Bug 994081 - [1/3] Make VolatileBufferPtrs more flexible, r=glandium
authorMichael Wu <mwu@mozilla.com>
Fri, 18 Apr 2014 12:26:49 -0400
changeset 194595 4c16ab7d8eefba4d096788363ae9fdd8f62b7d99
parent 194594 4511d9ac1000a8f8a974bfd1427de745f446e834
child 194596 013456bbf74d5517f53ca1f04206d758ddeae0be
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-esr52@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs994081
milestone32.0a1
Bug 994081 - [1/3] Make VolatileBufferPtrs more flexible, r=glandium
memory/mozalloc/VolatileBuffer.h
--- a/memory/mozalloc/VolatileBuffer.h
+++ b/memory/mozalloc/VolatileBuffer.h
@@ -74,48 +74,69 @@ private:
   bool mHeap;
   bool mFirstLock;
 #endif
 };
 
 class VolatileBufferPtr_base {
 public:
   explicit VolatileBufferPtr_base(VolatileBuffer* vbuf) : mVBuf(vbuf) {
-    if (vbuf) {
-      mPurged = !vbuf->Lock(&mMapping);
-    } else {
-      mMapping = nullptr;
-      mPurged = false;
-    }
+    Lock();
   }
 
   ~VolatileBufferPtr_base() {
-    if (mVBuf) {
-      mVBuf->Unlock();
-    }
+    Unlock();
   }
 
   bool WasBufferPurged() const {
     return mPurged;
   }
 
 protected:
   void* mMapping;
 
+  void Set(VolatileBuffer* vbuf) {
+    Unlock();
+    mVBuf = vbuf;
+    Lock();
+  }
+
 private:
   RefPtr<VolatileBuffer> mVBuf;
   bool mPurged;
+
+  void Lock() {
+    if (mVBuf) {
+      mPurged = !mVBuf->Lock(&mMapping);
+    } else {
+      mMapping = nullptr;
+      mPurged = false;
+    }
+  }
+
+  void Unlock() {
+    if (mVBuf) {
+      mVBuf->Unlock();
+    }
+  }
 };
 
 template <class T>
 class VolatileBufferPtr : public VolatileBufferPtr_base
 {
 public:
   explicit VolatileBufferPtr(VolatileBuffer* vbuf) : VolatileBufferPtr_base(vbuf) {}
+  VolatileBufferPtr() : VolatileBufferPtr_base(nullptr) {}
 
   operator T*() const {
     return (T*) mMapping;
   }
+
+  void operator =(VolatileBuffer* vbuf) {
+    Set(vbuf);
+  }
+private:
+  VolatileBufferPtr(VolatileBufferPtr const& vbufptr) MOZ_DELETE;
 };
 
 }; /* namespace mozilla */
 
 #endif /* mozalloc_VolatileBuffer_h */