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

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: 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
« 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..90c3fa8cc3cfea55386f4698f2d9ac768a61d7da 100644
--- a/base/synchronization/lock_impl_posix.cc
+++ b/base/synchronization/lock_impl_posix.cc
@@ -8,26 +8,35 @@
#include <string.h>
#include "base/logging.h"
+#include "base/synchronization/lock.h"
+#include "base/version.h"
+
+#if defined(OS_LINUX)
+#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 +60,27 @@ 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
+ // 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;
+
+ uint32_t glibc_major_version = version.components()[0];
+ uint32_t glibc_minor_version = version.components()[1];
+
+ if (glibc_major_version < 2)
+ return false;
+
+ return glibc_major_version != 2 || glibc_minor_version >= 17;
danakj 2016/06/02 21:59:21 You can use std::tie to combine these into one a <
robliao 2016/06/02 22:17:48 Neat! Done.
+#else
+ return true;
+#endif
+}
+
} // 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