Skip to content

Commit

Permalink
THRIFT-736. cpp: Check for availability of pthread_mutex_timedlock
Browse files Browse the repository at this point in the history
r920679 introduced a call to pthread_mutex_timedlock, which is not
available on all UNIX variants.  In particular, it is missing on Mac OS.
Add a preprocessor check for the relevant feature macro.  If it fails,
just use a trylock.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@925940 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
dreiss committed Mar 22, 2010
1 parent c298acf commit 494c07b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/cpp/src/concurrency/Mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class Mutex::impl {
bool trylock() const { return (0 == pthread_mutex_trylock(&pthread_mutex_)); }

bool timedlock(int64_t milliseconds) const {
#if defined(_POSIX_TIMEOUTS) && _POSIX_TIMEOUTS >= 200112L
PROFILE_MUTEX_START_LOCK();

struct timespec ts;
Expand All @@ -147,6 +148,11 @@ class Mutex::impl {

PROFILE_MUTEX_NOT_LOCKED();
return false;
#else
// If pthread_mutex_timedlock isn't supported, the safest thing to do
// is just do a nonblocking trylock.
return trylock();
#endif
}

void unlock() const {
Expand Down

0 comments on commit 494c07b

Please sign in to comment.