 Chromium Code Reviews
 Chromium Code Reviews Issue 2178503003:
  Add PTHREAD_PRIO_INHERIT Locks for Mac  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 2178503003:
  Add PTHREAD_PRIO_INHERIT Locks for Mac  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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..ed65aa69146c28baf53e2212830cc237a00f7e06 100644 | 
| --- a/base/synchronization/lock_impl_posix.cc | 
| +++ b/base/synchronization/lock_impl_posix.cc | 
| @@ -8,26 +8,30 @@ | 
| #include <string.h> | 
| #include "base/logging.h" | 
| +#include "base/synchronization/lock.h" | 
| 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 +55,14 @@ void LockImpl::Unlock() { | 
| DCHECK_EQ(rv, 0) << ". " << strerror(rv); | 
| } | 
| +// static | 
| +bool LockImpl::PriorityInheritanceAvailable() { | 
| 
gab
2016/07/22 20:07:31
There's no longer anything run-time about this met
 
robliao
2016/07/25 20:53:19
This future-proofs lock against the known runtime
 
gab
2016/07/26 17:31:27
Ok, can you add a TODO here then to indicate the i
 
gab
2016/07/26 17:32:11
Nvm, see you addressed this already with other com
 | 
| +#if PRIORITY_INHERITANCE_LOCKS_POSSIBLE() && defined(OS_MACOSX) | 
| 
gab
2016/07/22 20:07:31
Please add a comment explaining why it doesn't wor
 
robliao
2016/07/25 20:53:19
Done.
 | 
| + return true; | 
| +#else | 
| + return false; | 
| +#endif | 
| +} | 
| + | 
| } // namespace internal | 
| } // namespace base |