Bug 1258847 - Set PTHREAD_MUTEX_ERRORCHECK for js::Mutex in debug builds. r=sfink
authorNick Fitzgerald <fitzgen@gmail.com>
Tue, 22 Mar 2016 15:51:00 -0400
changeset 289977 038c00218cf4afd880152ecbb2f9924aaf678e3b
parent 289976 9daacc9d25600491dacef965c3927d306deef931
child 289978 b2bc470bfbc3409702c24838d1a0029aa961fb96
push id18337
push usercbook@mozilla.com
push dateWed, 23 Mar 2016 15:30:25 +0000
treeherderfx-team@67ac681f7e53 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1258847
milestone48.0a1
Bug 1258847 - Set PTHREAD_MUTEX_ERRORCHECK for js::Mutex in debug builds. r=sfink
js/src/threading/posix/Mutex.cpp
--- a/js/src/threading/posix/Mutex.cpp
+++ b/js/src/threading/posix/Mutex.cpp
@@ -13,18 +13,31 @@
 
 js::Mutex::Mutex()
 {
   AutoEnterOOMUnsafeRegion oom;
   platformData_ = js_new<PlatformData>();
   if (!platformData_)
     oom.crash("js::Mutex::Mutex");
 
-  int r = pthread_mutex_init(&platformData()->ptMutex, NULL);
+  pthread_mutexattr_t* attrp = nullptr;
+
+#ifdef DEBUG
+  pthread_mutexattr_t attr;
+  MOZ_ALWAYS_TRUE(pthread_mutexattr_init(&attr) == 0);
+  MOZ_ALWAYS_TRUE(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK) == 0);
+  attrp = &attr;
+#endif
+
+  int r = pthread_mutex_init(&platformData()->ptMutex, attrp);
   MOZ_RELEASE_ASSERT(r == 0);
+
+#ifdef DEBUG
+  MOZ_ALWAYS_TRUE(pthread_mutexattr_destroy(&attr) == 0);
+#endif
 }
 
 js::Mutex::~Mutex()
 {
   if (!platformData_)
     return;
 
   int r = pthread_mutex_destroy(&platformData()->ptMutex);