Bug 1038855, part 3 - Use an nsRefPtr for CrossProcessMutex::mSharedBuffer. r=bjacob
authorAndrew McCreight <continuation@gmail.com>
Wed, 16 Jul 2014 12:39:03 -0700
changeset 194426 74034d6b6ae6d550c6b482bd79a595f8c527d87d
parent 194425 2bf6c098623d9f8e95e9d86e1a8a1721fb6583d7
child 194427 1b12aa2451a2318f16750bc17415e4003107915d
push id46350
push useramccreight@mozilla.com
push dateWed, 16 Jul 2014 19:39:21 +0000
treeherdermozilla-inbound@74034d6b6ae6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbjacob
bugs1038855
milestone33.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 1038855, part 3 - Use an nsRefPtr for CrossProcessMutex::mSharedBuffer. r=bjacob
ipc/glue/CrossProcessMutex.h
ipc/glue/CrossProcessMutex_posix.cpp
--- a/ipc/glue/CrossProcessMutex.h
+++ b/ipc/glue/CrossProcessMutex.h
@@ -8,16 +8,17 @@
 
 #include "base/process.h"
 #include "mozilla/Mutex.h"
 
 #if defined(OS_LINUX)
 #include <pthread.h>
 #include "SharedMemoryBasic.h"
 #include "mozilla/Atomics.h"
+#include "nsAutoPtr.h"
 #endif
 
 namespace IPC {
 template<typename T>
 struct ParamTraits;
 }
 
 //
@@ -95,17 +96,17 @@ private:
 
   CrossProcessMutex();
   CrossProcessMutex(const CrossProcessMutex&);
   CrossProcessMutex &operator=(const CrossProcessMutex&);
 
 #ifdef XP_WIN
   HANDLE mMutex;
 #elif defined(OS_LINUX)
-  mozilla::ipc::SharedMemoryBasic* mSharedBuffer;
+  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
@@ -33,18 +33,17 @@ InitMutex(pthread_mutex_t* mMutex)
   }
 
   if (pthread_mutex_init(mMutex, &mutexAttributes)) {
     MOZ_CRASH();
   }
 }
 
 CrossProcessMutex::CrossProcessMutex(const char*)
-    : mSharedBuffer(nullptr)
-    , mMutex(nullptr)
+    : mMutex(nullptr)
     , mCount(nullptr)
 {
   mSharedBuffer = new ipc::SharedMemoryBasic;
   if (!mSharedBuffer->Create(sizeof(MutexData))) {
     MOZ_CRASH();
   }
 
   if (!mSharedBuffer->Map(sizeof(MutexData))) {
@@ -62,18 +61,17 @@ CrossProcessMutex::CrossProcessMutex(con
 
   *mCount = 1;
   InitMutex(mMutex);
 
   MOZ_COUNT_CTOR(CrossProcessMutex);
 }
 
 CrossProcessMutex::CrossProcessMutex(CrossProcessMutexHandle aHandle)
-    : mSharedBuffer(nullptr)
-    , mMutex(nullptr)
+    : mMutex(nullptr)
     , mCount(nullptr)
 {
   if (!ipc::SharedMemoryBasic::IsHandleValid(aHandle)) {
     MOZ_CRASH();
   }
 
   mSharedBuffer = new ipc::SharedMemoryBasic(aHandle);
 
@@ -104,17 +102,16 @@ CrossProcessMutex::~CrossProcessMutex()
 {
   int32_t count = --(*mCount);
 
   if (count == 0) {
     // Nothing can be done if the destroy fails so ignore return code.
     unused << pthread_mutex_destroy(mMutex);
   }
 
-  delete mSharedBuffer;
   MOZ_COUNT_DTOR(CrossProcessMutex);
 }
 
 void
 CrossProcessMutex::Lock()
 {
   MOZ_ASSERT(*mCount > 0, "Attempting to lock mutex with zero ref count");
   pthread_mutex_lock(mMutex);