Bug 850054 - Do some more work on nsMainThreadPtrHandle. r=bsmedberg
authorBobby Holley <bobbyholley@gmail.com>
Fri, 15 Mar 2013 10:41:48 -0700
changeset 124947 9d4a41ffdcb7e3cd3d5238bacab15bee41ed3a84
parent 124946 83720eb64f44d19a2a80b8078d6dbcfa9f64f66b
child 124948 9ea11ddff33b37316fab484873f228f36ae3b41a
push id24695
push userbobbyholley@gmail.com
push dateFri, 15 Mar 2013 17:42:08 +0000
treeherdermozilla-inbound@9ea11ddff33b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs850054
milestone22.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 850054 - Do some more work on nsMainThreadPtrHandle. r=bsmedberg
xpcom/glue/nsProxyRelease.h
--- a/xpcom/glue/nsProxyRelease.h
+++ b/xpcom/glue/nsProxyRelease.h
@@ -131,16 +131,18 @@ public:
     // Nobody should be touching the raw pointer off-main-thread.
     if (MOZ_UNLIKELY(!NS_IsMainThread())) {
       NS_ERROR("Can't dereference nsMainThreadPtrHolder off main thread");
       MOZ_CRASH();
     }
     return mRawPtr;
   }
 
+  bool operator==(const nsMainThreadPtrHolder<T>& aOther) const { return mRawPtr == aOther.mRawPtr; }
+
   NS_IMETHOD_(nsrefcnt) Release();
   NS_IMETHOD_(nsrefcnt) AddRef();
 
 private:
   // This class is threadsafe and reference-counted.
   nsAutoRefCnt mRefCnt;
 
   // Our wrapped pointer.
@@ -158,16 +160,17 @@ template<class T>
 NS_IMPL_THREADSAFE_RELEASE(nsMainThreadPtrHolder<T>)
 
 template<class T>
 class nsMainThreadPtrHandle
 {
   nsRefPtr<nsMainThreadPtrHolder<T> > mPtr;
 
   public:
+  nsMainThreadPtrHandle() : mPtr(NULL) {}
   nsMainThreadPtrHandle(nsMainThreadPtrHolder<T> *aHolder) : mPtr(aHolder) {}
   nsMainThreadPtrHandle(const nsMainThreadPtrHandle& aOther) : mPtr(aOther.mPtr) {}
   nsMainThreadPtrHandle& operator=(const nsMainThreadPtrHandle& aOther) {
     mPtr = aOther.mPtr;
     return *this;
   }
 
   operator nsMainThreadPtrHolder<T>*() { return mPtr.get(); }
@@ -178,13 +181,30 @@ class nsMainThreadPtrHandle
   T* get()
   {
     MOZ_ASSERT(NS_IsMainThread());
     if (mPtr) {
       return mPtr.get()->get();
     }
     return nullptr;
   }
+  const T* get() const
+  {
+    MOZ_ASSERT(NS_IsMainThread());
+    if (mPtr) {
+      return mPtr.get()->get();
+    }
+    return nullptr;
+  }
+
   operator T*() { return get(); }
   T* operator->() { return get(); }
+
+  // These are safe to call on other threads with appropriate external locking.
+  bool operator==(const nsMainThreadPtrHandle<T>& aOther) const {
+    if (!mPtr || !aOther.mPtr)
+      return mPtr == aOther.mPtr;
+    return *mPtr == *aOther.mPtr;
+  }
+  bool operator!() { return !mPtr; }
 };
 
 #endif