Bug 1072093 - Build the CrossProcessMutex_posix on OS X, but disable it prior to Lion. r=smichaud
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 07 Nov 2014 14:17:14 -0500
changeset 226054 33b7cccd5e2b45f91b237c0e8dca6c0d28e35932
parent 226053 fca687b2809299066fb774ca197d1c2b4c107885
child 226055 6c2fb5df16babe6173a9f11ba1894472c0c713b1
push id31
push userdburns@mozilla.com
push dateSat, 08 Nov 2014 00:12:59 +0000
reviewerssmichaud
bugs1072093
milestone36.0a1
Bug 1072093 - Build the CrossProcessMutex_posix on OS X, but disable it prior to Lion. r=smichaud
ipc/glue/CrossProcessMutex.h
ipc/glue/CrossProcessMutex_posix.cpp
ipc/glue/moz.build
--- a/ipc/glue/CrossProcessMutex.h
+++ b/ipc/glue/CrossProcessMutex.h
@@ -4,17 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_CrossProcessMutex_h
 #define mozilla_CrossProcessMutex_h
 
 #include "base/process.h"
 #include "mozilla/Mutex.h"
 
-#if defined(OS_LINUX)
+#if defined(OS_POSIX)
 #include <pthread.h>
 #include "SharedMemoryBasic.h"
 #include "mozilla/Atomics.h"
 #include "nsAutoPtr.h"
 #endif
 
 namespace IPC {
 template<typename T>
@@ -27,19 +27,19 @@ struct ParamTraits;
 //  - CrossProcessMutex, a non-recursive mutex that can be shared across processes
 //  - CrossProcessMutexAutoLock, an RAII class for ensuring that Mutexes are
 //    properly locked and unlocked
 //
 // Using CrossProcessMutexAutoLock/CrossProcessMutexAutoUnlock is MUCH
 // preferred to making bare calls to CrossProcessMutex.Lock and Unlock.
 //
 namespace mozilla {
-#ifdef XP_WIN
+#if defined(OS_WIN)
 typedef HANDLE CrossProcessMutexHandle;
-#elif defined(OS_LINUX)
+#elif defined(OS_POSIX)
 typedef mozilla::ipc::SharedMemoryBasic::Handle CrossProcessMutexHandle;
 #else
 // Stub for other platforms. We can't use uintptr_t here since different
 // processes could disagree on its size.
 typedef uintptr_t CrossProcessMutexHandle;
 #endif
 
 class CrossProcessMutex
@@ -93,19 +93,19 @@ public:
 
 private:
   friend struct IPC::ParamTraits<CrossProcessMutex>;
 
   CrossProcessMutex();
   CrossProcessMutex(const CrossProcessMutex&);
   CrossProcessMutex &operator=(const CrossProcessMutex&);
 
-#ifdef XP_WIN
+#if defined(OS_WIN)
   HANDLE mMutex;
-#elif defined(OS_LINUX)
+#elif defined(OS_POSIX)
   nsRefPtr<mozilla::ipc::SharedMemoryBasic> mSharedBuffer;
   pthread_mutex_t* mMutex;
   mozilla::Atomic<int32_t>* mCount;
 #endif
 };
 
 typedef BaseAutoLock<CrossProcessMutex> CrossProcessMutexAutoLock;
 typedef BaseAutoUnlock<CrossProcessMutex> CrossProcessMutexAutoUnlock;
--- a/ipc/glue/CrossProcessMutex_posix.cpp
+++ b/ipc/glue/CrossProcessMutex_posix.cpp
@@ -3,16 +3,20 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "CrossProcessMutex.h"
 #include "mozilla/unused.h"
 #include "nsDebug.h"
 #include "nsISupportsImpl.h"
 
+#ifdef OS_MACOSX
+#include "nsCocoaFeatures.h"
+#endif
+
 namespace {
 
 struct MutexData {
   pthread_mutex_t mMutex;
   mozilla::Atomic<int32_t> mCount;
 };
 
 }
@@ -36,16 +40,25 @@ InitMutex(pthread_mutex_t* mMutex)
     MOZ_CRASH();
   }
 }
 
 CrossProcessMutex::CrossProcessMutex(const char*)
     : mMutex(nullptr)
     , mCount(nullptr)
 {
+#ifdef OS_MACOSX
+  if (!nsCocoaFeatures::OnLionOrLater()) {
+    // Don't allow using the cross-process mutex before OS X 10.7 because it
+    // probably doesn't work very well. See discussion in bug 1072093 for more
+    // details.
+    MOZ_CRASH();
+  }
+#endif
+
   mSharedBuffer = new ipc::SharedMemoryBasic;
   if (!mSharedBuffer->Create(sizeof(MutexData))) {
     MOZ_CRASH();
   }
 
   if (!mSharedBuffer->Map(sizeof(MutexData))) {
     MOZ_CRASH();
   }
--- a/ipc/glue/moz.build
+++ b/ipc/glue/moz.build
@@ -54,17 +54,17 @@ else:
         'SharedMemory_posix.cpp',
         'Transport_posix.cpp',
     ]
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     SOURCES += [
         'CrossProcessMutex_windows.cpp',
     ]
-elif CONFIG['OS_ARCH'] == 'Linux':
+elif CONFIG['OS_ARCH'] in ('Linux', 'Darwin'):
     UNIFIED_SOURCES += [
         'CrossProcessMutex_posix.cpp',
     ]
 else:
     UNIFIED_SOURCES += [
         'CrossProcessMutex_unimplemented.cpp',
     ]