diff options
| author | 2011-03-17 20:16:42 -0700 | |
|---|---|---|
| committer | 2011-03-17 20:16:42 -0700 | |
| commit | f98f1364f802d7637b0304722f38efdfed758e6e (patch) | |
| tree | b92aea7cc73c8e898d9dbec71a85547ec4d24687 /libs/utils/Timers.cpp | |
| parent | e5e02aac299bd0f864677ab62ebd804d79f69d44 (diff) | |
| parent | c0a5e8df03d949cb307a0eb98f0222086c0434c1 (diff) | |
Merge "Refactor how timeouts are calculated."
Diffstat (limited to 'libs/utils/Timers.cpp')
| -rw-r--r-- | libs/utils/Timers.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libs/utils/Timers.cpp b/libs/utils/Timers.cpp index 784f035dc0..64a29f5877 100644 --- a/libs/utils/Timers.cpp +++ b/libs/utils/Timers.cpp @@ -26,6 +26,7 @@ #include <sys/time.h> #include <time.h> #include <errno.h> +#include <limits.h> #ifdef HAVE_WIN32_THREADS #include <windows.h> @@ -53,6 +54,23 @@ nsecs_t systemTime(int clock) #endif } +int toMillisecondTimeoutDelay(nsecs_t referenceTime, nsecs_t timeoutTime) +{ + int timeoutDelayMillis; + if (timeoutTime > referenceTime) { + uint64_t timeoutDelay = uint64_t(timeoutTime - referenceTime); + if (timeoutDelay > uint64_t((INT_MAX - 1) * 1000000LL)) { + timeoutDelayMillis = -1; + } else { + timeoutDelayMillis = (timeoutDelay + 999999LL) / 1000000LL; + } + } else { + timeoutDelayMillis = 0; + } + return timeoutDelayMillis; +} + + /* * =========================================================================== * DurationTimer |