Bug 1520955. Add ref qualifier to DataMutex for more safety. r=froydnj
authorJeff Muizelaar <jrmuizel@gmail.com>
Fri, 18 Jan 2019 16:48:22 +0000
changeset 511574 0f73ecaf9f406f11d0a64a3194690aa67bc4bf60
parent 511573 6c39cc812c87cf6ac71f6af96b60b3754a636eee
child 511575 2c853b32f011ac35b6639efd9862c4e351f38047
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1520955
milestone66.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 1520955. Add ref qualifier to DataMutex for more safety. r=froydnj We lose some sugar but gain some safety. This seems like the right trade. If people want sugar they should use Rust. Differential Revision: https://phabricator.services.mozilla.com/D16918
gfx/webrender_bindings/RenderThread.cpp
xpcom/threads/DataMutex.h
--- a/gfx/webrender_bindings/RenderThread.cpp
+++ b/gfx/webrender_bindings/RenderThread.cpp
@@ -175,17 +175,18 @@ void RenderThread::AddRenderer(wr::Windo
   MOZ_ASSERT(IsInRenderThread());
 
   if (mHasShutdown) {
     return;
   }
 
   mRenderers[aWindowId] = std::move(aRenderer);
 
-  mWindowInfos.Lock()->emplace(AsUint64(aWindowId), new WindowInfo());
+  auto windows = mWindowInfos.Lock();
+  windows->emplace(AsUint64(aWindowId), new WindowInfo());
 }
 
 void RenderThread::RemoveRenderer(wr::WindowId aWindowId) {
   MOZ_ASSERT(IsInRenderThread());
 
   if (mHasShutdown) {
     return;
   }
--- a/xpcom/threads/DataMutex.h
+++ b/xpcom/threads/DataMutex.h
@@ -34,31 +34,34 @@ namespace mozilla {
 //    x.AppendElement(1u);
 //    assert(x[0], 1u);
 //
 template <typename T>
 class DataMutex {
  private:
   class MOZ_STACK_CLASS AutoLock {
    public:
-    T* operator->() const { return &ref(); }
+    T* operator->() const& { return &ref(); }
+    T* operator->() const&& = delete;
 
-    T& operator*() const { return ref(); }
+    T& operator*() const& { return ref(); }
+    T& operator*() const&& = delete;
 
     // Like RefPtr, make this act like its underlying raw pointer type
     // whenever it is used in a context where a raw pointer is expected.
     operator T*() const& { return &ref(); }
 
     // Like RefPtr, don't allow implicit conversion of temporary to raw pointer.
     operator T*() const&& = delete;
 
-    T& ref() const {
+    T& ref() const& {
       MOZ_ASSERT(mOwner);
       return mOwner->mValue;
     }
+    T& ref() const&& = delete;
 
     AutoLock(AutoLock&& aOther) : mOwner(aOther.mOwner) {
       aOther.mOwner = nullptr;
     }
 
     ~AutoLock() {
       if (mOwner) {
         mOwner->mMutex.Unlock();