diff options
| author | Narayan Kamath <narayan@google.com> | 2014-03-07 20:15:50 +0000 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2014-03-07 20:15:50 +0000 |
| commit | 7d20a9486d52d3e0747e34fb717830fcdad21933 (patch) | |
| tree | 6b2bc856bb2a191a052b0a3311fd8e4f577ea038 /src | |
| parent | cb66e5e0fa527d958f97fe835c35dbbf82810fb9 (diff) | |
| parent | 5c057d44e5869b8acb779d48a4b821859040d9c8 (diff) | |
| download | android_frameworks_wilhelm-7d20a9486d52d3e0747e34fb717830fcdad21933.tar.gz android_frameworks_wilhelm-7d20a9486d52d3e0747e34fb717830fcdad21933.tar.bz2 android_frameworks_wilhelm-7d20a9486d52d3e0747e34fb717830fcdad21933.zip | |
am 5c057d44: Merge "Remove use of pthread_mutex_lock_timeout_np."
* commit '5c057d44e5869b8acb779d48a4b821859040d9c8':
Remove use of pthread_mutex_lock_timeout_np.
Diffstat (limited to 'src')
| -rw-r--r-- | src/locks.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/locks.c b/src/locks.c index d95c23a..776eef7 100644 --- a/src/locks.c +++ b/src/locks.c @@ -31,6 +31,17 @@ /** \brief Exclusively lock an object */ #ifdef USE_DEBUG + +void init_time_spec(timespec* ts, long delta) { + clock_gettime(CLOCK_REALTIME, ts); + ts->tv_nsec += delta; + + if (ts->tv_nsec >= 1000000000L) { + ts->tv_sec++; + ts->tv_nsec -= 1000000000L; + } +} + void object_lock_exclusive_(IObject *thiz, const char *file, int line) { int ok; @@ -39,11 +50,14 @@ void object_lock_exclusive_(IObject *thiz, const char *file, int line) // not android_atomic_acquire_load because we don't care about relative load/load ordering int32_t oldGeneration = thiz->mGeneration; // wait up to a total of 250 ms - static const unsigned backoffs[] = {10, 20, 30, 40, 50, 100}; + static const long nanoBackoffs[] = { + 10 * 1000000, 20 * 1000000, 30 * 1000000, 40 * 1000000, 50 * 1000000, 100 * 1000000}; unsigned i = 0; + timespec ts; + memset(&ts, 0, sizeof(timespec)); for (;;) { - // the Android version is in ms not timespec, and isn't named pthread_mutex_timedlock_np - ok = pthread_mutex_lock_timeout_np(&thiz->mMutex, backoffs[i]); + init_time_spec(&ts, nanoBackoffs[i]); + ok = pthread_mutex_timedlock(&thiz->mMutex, &ts); if (0 == ok) { break; } @@ -63,7 +77,7 @@ void object_lock_exclusive_(IObject *thiz, const char *file, int line) goto forward_progress; } // no, then continue trying to lock but with increasing timeouts - if (++i >= (sizeof(backoffs) / sizeof(backoffs[0]))) { + if (++i >= (sizeof(nanoBackoffs) / sizeof(nanoBackoffs[0]))) { // the extra block avoids a C++ compiler error about goto past initialization { pthread_t me = pthread_self(); |
