From 51b71028661092e8860cca4f8ca79848e03cdc2c Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Tue, 4 Mar 2014 11:57:09 +0000 Subject: Remove use of pthread_cond_timedwait_monotonic. Use posix compliant pthread_condattr_setclock instead. Also, remove usage of HAVE_TIMEDWAIT_MONOTONIC and replace it with a specific reference to the only supported platform that doesn't have it. Change-Id: I933f05c5b4965bab88ccd8e3e26c91549ed4184d --- runtime/base/mutex.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'runtime/base') diff --git a/runtime/base/mutex.cc b/runtime/base/mutex.cc index fdf5763..532e6c4 100644 --- a/runtime/base/mutex.cc +++ b/runtime/base/mutex.cc @@ -650,7 +650,13 @@ ConditionVariable::ConditionVariable(const char* name, Mutex& guard) sequence_ = 0; num_waiters_ = 0; #else - CHECK_MUTEX_CALL(pthread_cond_init, (&cond_, NULL)); + pthread_condattr_t cond_attrs; + CHECK_MUTEX_CALL(pthread_condattr_init(&cond_attrs)); +#if !defined(__APPLE__) + // Apple doesn't have CLOCK_MONOTONIC or pthread_condattr_setclock. + CHECK_MUTEX_CALL(pthread_condattr_setclock(&cond_attrs, CLOCK_MONOTONIC)); +#endif + CHECK_MUTEX_CALL(pthread_cond_init, (&cond_, &cond_attrs)); #endif } @@ -788,17 +794,15 @@ void ConditionVariable::TimedWait(Thread* self, int64_t ms, int32_t ns) { CHECK_GE(guard_.num_contenders_, 0); guard_.num_contenders_--; #else -#ifdef HAVE_TIMEDWAIT_MONOTONIC -#define TIMEDWAIT pthread_cond_timedwait_monotonic +#if !defined(__APPLE__) int clock = CLOCK_MONOTONIC; #else -#define TIMEDWAIT pthread_cond_timedwait int clock = CLOCK_REALTIME; #endif guard_.recursion_count_ = 0; timespec ts; InitTimeSpec(true, clock, ms, ns, &ts); - int rc = TEMP_FAILURE_RETRY(TIMEDWAIT(&cond_, &guard_.mutex_, &ts)); + int rc = TEMP_FAILURE_RETRY(pthread_cond_timedwait(&cond_, &guard_.mutex_, &ts)); if (rc != 0 && rc != ETIMEDOUT) { errno = rc; PLOG(FATAL) << "TimedWait failed for " << name_; -- cgit v1.1