Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2749)

Unified Diff: base/synchronization/lock_impl_posix.cc

Issue 2028303005: Add PTHREAD_PRIO_INHERIT to POSIX Locks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR Feedback Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/synchronization/lock_impl_posix.cc
diff --git a/base/synchronization/lock_impl_posix.cc b/base/synchronization/lock_impl_posix.cc
index 5619adaf5d829df72f93fd57b0687d551fb9390d..2cbb8b16cc8ef825d5b850dd1983c8f0140cac26 100644
--- a/base/synchronization/lock_impl_posix.cc
+++ b/base/synchronization/lock_impl_posix.cc
@@ -8,26 +8,36 @@
#include <string.h>
#include "base/logging.h"
+#include "base/synchronization/lock.h"
+#include "base/version.h"
+
+#if defined(OS_LINUX)
+#include <tuple>
+#include <gnu/libc-version.h>
+#endif
namespace base {
namespace internal {
LockImpl::LockImpl() {
-#ifndef NDEBUG
- // In debug, setup attributes for lock error checking.
pthread_mutexattr_t mta;
int rv = pthread_mutexattr_init(&mta);
DCHECK_EQ(rv, 0) << ". " << strerror(rv);
+#if PRIORITY_INHERITANCE_LOCKS_POSSIBLE()
+ if (PriorityInheritanceAvailable()) {
+ rv = pthread_mutexattr_setprotocol(&mta, PTHREAD_PRIO_INHERIT);
+ }
+ DCHECK_EQ(rv, 0) << ". " << strerror(rv);
+#endif
+#ifndef NDEBUG
+ // In debug, setup attributes for lock error checking.
rv = pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK);
DCHECK_EQ(rv, 0) << ". " << strerror(rv);
+#endif
rv = pthread_mutex_init(&native_handle_, &mta);
DCHECK_EQ(rv, 0) << ". " << strerror(rv);
rv = pthread_mutexattr_destroy(&mta);
DCHECK_EQ(rv, 0) << ". " << strerror(rv);
-#else
- // In release, go with the default lock attributes.
- pthread_mutex_init(&native_handle_, NULL);
-#endif
}
LockImpl::~LockImpl() {
@@ -51,5 +61,23 @@ void LockImpl::Unlock() {
DCHECK_EQ(rv, 0) << ". " << strerror(rv);
}
+// static
+bool LockImpl::PriorityInheritanceAvailable() {
+#if defined(OS_LINUX)
+ // Due to glibc Bug 14652, priority inheritance mutexes may deadlock with
gab 2016/06/07 12:28:19 Link to bug? (googling "glibc Bug 14652" doesn't y
robliao 2016/06/07 14:11:04 Done.
+ // condition variables during recacquisition of the mutex after the condition
+ // variable is signalled. This bug was fixed in glibc 2.17.
+ Version version(gnu_get_libc_version());
+ if (!version.IsValid() || version.components().size() != 2)
+ return false;
+
+ return std::tie(version.components()[0], version.components()[1]) >=
+ std::make_tuple(2, 17);
+
+#else
+ return true;
+#endif
+}
+
} // namespace internal
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698