equal
deleted
inserted
replaced
542 /***********************************************************************/ |
542 /***********************************************************************/ |
543 /***********************************************************************/ |
543 /***********************************************************************/ |
544 /***********************************************************************/ |
544 /***********************************************************************/ |
545 /***********************************************************************/ |
545 /***********************************************************************/ |
546 |
546 |
547 #define MILLISECOND 1 |
547 #define MILLISECOND 1000000 |
548 #define SECOND 1000 * MILLISECOND |
548 #define SECOND 1000 * MILLISECOND |
549 |
549 |
550 #define ULL_MAX std::numeric_limits<unsigned long long>::max() |
550 #define ULL_MAX std::numeric_limits<unsigned long long>::max() |
551 |
551 |
552 /* unsigned long long -> multiply and add : time_var += interval * multiplier */ |
552 /* unsigned long long -> multiply and add : time_var += interval * multiplier */ |
624 |
624 |
625 /* Test overflow on ADD by pre-condition: If (ULL_MAX - a) < b => overflow! */ |
625 /* Test overflow on ADD by pre-condition: If (ULL_MAX - a) < b => overflow! */ |
626 ovflow |= ((ULL_MAX - time_ull) < (unsigned long long)time_ld); |
626 ovflow |= ((ULL_MAX - time_ull) < (unsigned long long)time_ld); |
627 time_ull += time_ld; |
627 time_ull += time_ld; |
628 |
628 |
629 if (ovflow) |
629 if (ovflow) { |
630 STAGE4_ERROR(symbol, symbol, "Internal overflow calculating task interval (must be <= 49 days)."); |
630 /* time is being stored in ns resolution (MILLISECOND #define is set to 1000000) */ |
|
631 /* time is being stored in unsigned long long (ISO C99 guarantees at least 64 bits) */ |
|
632 /* 2⁶64ns works out to around 584.5 years, assuming 365.25 days per year */ |
|
633 STAGE4_ERROR(symbol, symbol, "Internal overflow calculating task interval (must be < 584 years)."); |
|
634 } |
631 |
635 |
632 return time_ull; |
636 return time_ull; |
633 }; |
637 }; |
634 ERROR; // should never reach this point! |
638 ERROR; // should never reach this point! |
635 return 0; // humour the compiler! |
639 return 0; // humour the compiler! |