diff options
author | Andy Hung <hunga@google.com> | 2016-08-24 22:50:00 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-08-24 22:50:00 +0000 |
commit | 8ec6753d61fe2e9c2a0857c7cf49266ba43232e3 (patch) | |
tree | 1184473ce30d06b6740d89f56ad3e2ac43903fdf /include/utils | |
parent | 789d4c65b496ab2bf281f9d0d44780da024182ee (diff) | |
parent | 47e5ca61e2704ca60bae1fe68b36d7b0105dd64a (diff) | |
download | system_core-8ec6753d61fe2e9c2a0857c7cf49266ba43232e3.tar.gz system_core-8ec6753d61fe2e9c2a0857c7cf49266ba43232e3.tar.bz2 system_core-8ec6753d61fe2e9c2a0857c7cf49266ba43232e3.zip |
Fix Mutex::timedLock to properly handle relative time am: 604ba48220 am: 708b9d118a
am: 47e5ca61e2
Change-Id: I5c351fbdc485acbcb33426b99ea6b900519ee0e3
Diffstat (limited to 'include/utils')
-rw-r--r-- | include/utils/Mutex.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/include/utils/Mutex.h b/include/utils/Mutex.h index 8c4683c02..d106185f0 100644 --- a/include/utils/Mutex.h +++ b/include/utils/Mutex.h @@ -64,13 +64,18 @@ public: status_t tryLock(); #if defined(__ANDROID__) - // lock the mutex, but don't wait longer than timeoutMilliseconds. + // Lock the mutex, but don't wait longer than timeoutNs (relative time). // Returns 0 on success, TIMED_OUT for failure due to timeout expiration. // // OSX doesn't have pthread_mutex_timedlock() or equivalent. To keep // capabilities consistent across host OSes, this method is only available // when building Android binaries. - status_t timedLock(nsecs_t timeoutMilliseconds); + // + // FIXME?: pthread_mutex_timedlock is based on CLOCK_REALTIME, + // which is subject to NTP adjustments, and includes time during suspend, + // so a timeout may occur even though no processes could run. + // Not holding a partial wakelock may lead to a system suspend. + status_t timedLock(nsecs_t timeoutNs); #endif // Manages the mutex automatically. It'll be locked when Autolock is @@ -134,6 +139,7 @@ inline status_t Mutex::tryLock() { } #if defined(__ANDROID__) inline status_t Mutex::timedLock(nsecs_t timeoutNs) { + timeoutNs += systemTime(SYSTEM_TIME_REALTIME); const struct timespec ts = { /* .tv_sec = */ static_cast<time_t>(timeoutNs / 1000000000), /* .tv_nsec = */ static_cast<long>(timeoutNs % 1000000000), |