diff options
author | 2011-03-17 01:34:19 -0700 | |
---|---|---|
committer | 2011-03-17 17:29:09 -0700 | |
commit | aa3855d5836d2a2d83baafdf6e40caf90d3dad1c (patch) | |
tree | 5f19b7bd1c42abf7e145637ed3459cf377fa94b9 /libs/utils/Timers.cpp | |
parent | 843e29d3751017267b96565c543df0301c31a9f7 (diff) |
Refactor how timeouts are calculated.
Added a timeout mechanism to EventHub and InputReader so that
InputMappers can request timeouts to perform delayed processing of
input when needed.
Change-Id: Iec2045baaf4e67690b15eef3c09a58d5cac76897
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 784f035dc03a..64a29f58776a 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 |