Author: dreiss
Date: Mon Mar 22 02:34:57 2010
New Revision: 925940

URL: http://svn.apache.org/viewvc?rev=925940&view=rev
Log:
THRIFT-736. cpp: Check for availability of pthread_mutex_timedlock

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.

Modified:
    incubator/thrift/trunk/lib/cpp/src/concurrency/Mutex.cpp

Modified: incubator/thrift/trunk/lib/cpp/src/concurrency/Mutex.cpp
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/concurrency/Mutex.cpp?rev=925940&r1=925939&r2=925940&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/concurrency/Mutex.cpp (original)
+++ incubator/thrift/trunk/lib/cpp/src/concurrency/Mutex.cpp Mon Mar 22 
02:34:57 2010
@@ -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;
@@ -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 {


Reply via email to