Bug 1312087 - part 0 - use PTHREAD_MUTEX_ADAPTIVE_NP mutexes on Linux/glibc; r=erahm
authorNathan Froyd <froydnj@mozilla.com>
Tue, 21 Mar 2017 11:20:36 -0400
changeset 348707 85458fefc1ae3e7d927bf12895ac23c61d952076
parent 348706 f86ef08fdae0a012c28e1264e83238cfb31ccc2e
child 348708 54440069e459c3fc6da22f2f4062163da231af9f
push id31533
push userkwierso@gmail.com
push dateTue, 21 Mar 2017 23:08:53 +0000
treeherdermozilla-central@8744e9f8eb99 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1312087
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1312087 - part 0 - use PTHREAD_MUTEX_ADAPTIVE_NP mutexes on Linux/glibc; r=erahm This matches NSPR's behavior for its PRLock type.
mozglue/misc/Mutex_posix.cpp
--- a/mozglue/misc/Mutex_posix.cpp
+++ b/mozglue/misc/Mutex_posix.cpp
@@ -22,32 +22,45 @@
       MOZ_CRASH(msg);                           \
     }                                           \
   }
 
 mozilla::detail::MutexImpl::MutexImpl()
 {
   pthread_mutexattr_t* attrp = nullptr;
 
-#ifdef DEBUG
+  // glibc's adaptive mutexes spin for a short number of tries before sleeping.
+  // NSPR's locks did this, too, and it seems like a reasonable thing to do.
+#if defined(__linux__) && defined(__GLIBC__)
+#define ADAPTIVE_MUTEX_SUPPORTED
+#endif
+
+#if defined(DEBUG)
+#define ATTR_REQUIRED
+#define MUTEX_KIND PTHREAD_MUTEX_ERRORCHECK
+#elif defined(ADAPTIVE_MUTEX_SUPPORTED)
+#define ATTR_REQUIRED
+#define MUTEX_KIND PTHREAD_MUTEX_ADAPTIVE_NP
+#endif
+
+#if defined(ATTR_REQUIRED)
   pthread_mutexattr_t attr;
 
   TRY_CALL_PTHREADS(pthread_mutexattr_init(&attr),
                     "mozilla::detail::MutexImpl::MutexImpl: pthread_mutexattr_init failed");
 
-  TRY_CALL_PTHREADS(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK),
+  TRY_CALL_PTHREADS(pthread_mutexattr_settype(&attr, MUTEX_KIND),
                     "mozilla::detail::MutexImpl::MutexImpl: pthread_mutexattr_settype failed");
-
   attrp = &attr;
 #endif
 
   TRY_CALL_PTHREADS(pthread_mutex_init(&platformData()->ptMutex, attrp),
                     "mozilla::detail::MutexImpl::MutexImpl: pthread_mutex_init failed");
 
-#ifdef DEBUG
+#if defined(ATTR_REQUIRED)
   TRY_CALL_PTHREADS(pthread_mutexattr_destroy(&attr),
                     "mozilla::detail::MutexImpl::MutexImpl: pthread_mutexattr_destroy failed");
 #endif
 }
 
 mozilla::detail::MutexImpl::~MutexImpl()
 {
   TRY_CALL_PTHREADS(pthread_mutex_destroy(&platformData()->ptMutex),