From: Mukund Sivaraman Date: Sun, 21 Oct 2012 23:34:54 +0000 (+0530) Subject: [2198] Check for EDEADLK too when using Mutex::tryLock() X-Git-Tag: trac2402_base~10^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59d1e7799c13b01d24276dbd6377934d50ca0749;p=thirdparty%2Fkea.git [2198] Check for EDEADLK too when using Mutex::tryLock() --- diff --git a/src/lib/util/threads/sync.cc b/src/lib/util/threads/sync.cc index bcb391a79e..f812556005 100644 --- a/src/lib/util/threads/sync.cc +++ b/src/lib/util/threads/sync.cc @@ -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));