| 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
|
|
|