Browse Source

[2198] Check for EDEADLK too when using Mutex::tryLock()

Mukund Sivaraman 12 years ago
parent
commit
59d1e7799c
1 changed files with 7 additions and 1 deletions
  1. 7 1
      src/lib/util/threads/sync.cc

+ 7 - 1
src/lib/util/threads/sync.cc

@@ -132,7 +132,13 @@ bool
 Mutex::tryLock() {
 Mutex::tryLock() {
     assert(impl_ != NULL);
     assert(impl_ != NULL);
     const int result = pthread_mutex_trylock(&impl_->mutex);
     const int result = pthread_mutex_trylock(&impl_->mutex);
-    if (result == EBUSY) {
+
+    // In the case of pthread_mutex_trylock(), if it is called on a
+    // locked mutex from the same thread, some platforms (such as fedora
+    // and debian) return EBUSY whereas others (such as centos 5) return
+    // EDEADLK. We return false and don't pass the lock attempt in both
+    // cases.
+    if (result == EBUSY || result == EDEADLK) {
         return (false);
         return (false);
     } else if (result != 0) {
     } else if (result != 0) {
         isc_throw(isc::InvalidOperation, std::strerror(result));
         isc_throw(isc::InvalidOperation, std::strerror(result));