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

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, 6 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
« no previous file with comments | « base/synchronization/lock_impl.h ('k') | sandbox/linux/seccomp-bpf-helpers/baseline_policy_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1de030187157ed90421cd92a7c1c3b4dee739b65 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,28 @@ void LockImpl::Unlock() {
DCHECK_EQ(rv, 0) << ". " << strerror(rv);
}
+// static
+bool LockImpl::PriorityInheritanceAvailable() {
+#if PRIORITY_INHERITANCE_LOCKS_POSSIBLE()
+#if defined(OS_LINUX)
+ // glibc Bug 14652: https://sourceware.org/bugzilla/show_bug.cgi?id=14652
+ // Fixed in glibc 2.17.
+ // Priority inheritance mutexes may deadlock with condition variables during
+ // recacquisition of the mutex after the condition variable is signalled.
+ 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 // defined(OS_LINUX)
+ return true;
+#endif // defined(OS_LINUX)
+#else // PRIORITY_INHERITANCE_LOCKS_POSSIBLE()
+ return false;
+#endif // PRIORITY_INHERITANCE_LOCKS_POSSIBLE()
+}
+
} // namespace internal
} // namespace base
« no previous file with comments | « base/synchronization/lock_impl.h ('k') | sandbox/linux/seccomp-bpf-helpers/baseline_policy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698