]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2198] Check for EDEADLK too when using Mutex::tryLock()
authorMukund Sivaraman <muks@isc.org>
Sun, 21 Oct 2012 23:34:54 +0000 (05:04 +0530)
committerMukund Sivaraman <muks@isc.org>
Sun, 21 Oct 2012 23:44:38 +0000 (05:14 +0530)
src/lib/util/threads/sync.cc

index bcb391a79e2b1129955396d51ac7de43374fee0a..f812556005eb48fb6e0f0b36fe7b0c72231fc552 100644 (file)
@@ -132,7 +132,13 @@ bool
 Mutex::tryLock() {
     assert(impl_ != NULL);
     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);
     } else if (result != 0) {
         isc_throw(isc::InvalidOperation, std::strerror(result));