Bug 1253478 - Use Atomic<uint64_t> in AsyncTransactionTracker r=nical
authorSotaro Ikeda <sotaro.ikeda.g@gmail.com>
Mon, 07 Mar 2016 18:59:00 -0800
changeset 338033 361af7c658e8bffb88c43b46190cd945f22671fc
parent 338032 722fb8b4213bca2b78d8f50e0e397f7115022c2a
child 338034 5a83c59fbc36a36dab077e5c8dafa79742b0759e
push id12405
push usercku@mozilla.com
push dateTue, 08 Mar 2016 03:35:29 +0000
reviewersnical
bugs1253478
milestone47.0a1
Bug 1253478 - Use Atomic<uint64_t> in AsyncTransactionTracker r=nical
gfx/layers/ipc/AsyncTransactionTracker.cpp
gfx/layers/ipc/AsyncTransactionTracker.h
--- a/gfx/layers/ipc/AsyncTransactionTracker.cpp
+++ b/gfx/layers/ipc/AsyncTransactionTracker.cpp
@@ -31,18 +31,17 @@ AsyncTransactionWaiter::WaitComplete()
     count++;
   }
 
   if (mWaitCount > 0) {
     printf_stderr("Timeout of waiting transaction complete.");
   }
 }
 
-uint64_t AsyncTransactionTracker::sSerialCounter(0);
-Mutex* AsyncTransactionTracker::sLock = nullptr;
+Atomic<uint64_t> AsyncTransactionTracker::sSerialCounter(0);
 
 AsyncTransactionTracker::AsyncTransactionTracker(AsyncTransactionWaiter* aWaiter)
     : mSerial(GetNextSerial())
     , mWaiter(aWaiter)
 #ifdef DEBUG
     , mCompleted(false)
 #endif
 {
@@ -76,17 +75,17 @@ AsyncTransactionTracker::NotifyCancel()
   mCompleted = true;
 #endif
   Cancel();
   if (mWaiter) {
     mWaiter->DecrementWaitCount();
   }
 }
 
-uint64_t AsyncTransactionTrackersHolder::sSerialCounter(0);
+Atomic<uint64_t> AsyncTransactionTrackersHolder::sSerialCounter(0);
 Mutex* AsyncTransactionTrackersHolder::sHolderLock = nullptr;
 
 std::map<uint64_t, AsyncTransactionTrackersHolder*> AsyncTransactionTrackersHolder::sTrackersHolders;
 
 AsyncTransactionTrackersHolder::AsyncTransactionTrackersHolder()
   : mSerial(GetNextSerial())
   , mIsTrackersHolderDestroyed(false)
 {
--- a/gfx/layers/ipc/AsyncTransactionTracker.h
+++ b/gfx/layers/ipc/AsyncTransactionTracker.h
@@ -103,49 +103,38 @@ public:
 
   virtual void SetReleaseFenceHandle(FenceHandle& aReleaseFenceHandle) {}
 
 protected:
   virtual ~AsyncTransactionTracker();
 
   static void Initialize()
   {
-    if (!sLock) {
-      sLock = new Mutex("AsyncTransactionTracker::sLock");
-    }
   }
 
   static void Finalize()
   {
-    if (sLock) {
-      delete sLock;
-      sLock = nullptr;
-    }
   }
 
   static uint64_t GetNextSerial()
   {
-    MOZ_ASSERT(sLock);
-    MutexAutoLock lock(*sLock);
-    ++sSerialCounter;
-    return sSerialCounter;
+    return ++sSerialCounter;
   }
 
   uint64_t mSerial;
   RefPtr<AsyncTransactionWaiter> mWaiter;
 #ifdef DEBUG
   bool mCompleted;
 #endif
 
   /**
    * gecko does not provide atomic operation for uint64_t.
    * Ensure atomicity by using Mutex.
    */
-  static uint64_t sSerialCounter;
-  static Mutex* sLock;
+  static Atomic<uint64_t> sSerialCounter;
 };
 
 class AsyncTransactionTrackersHolder
 {
 public:
   AsyncTransactionTrackersHolder();
   virtual ~AsyncTransactionTrackersHolder();
 
@@ -180,20 +169,17 @@ public:
   {
     return mSerial;
   }
 
 protected:
 
   static uint64_t GetNextSerial()
   {
-    MOZ_ASSERT(sHolderLock);
-    MutexAutoLock lock(*sHolderLock);
-    ++sSerialCounter;
-    return sSerialCounter;
+    return ++sSerialCounter;
   }
 
   void TransactionCompletetedInternal(uint64_t aTransactionId);
 
   void SetReleaseFenceHandle(FenceHandle& aReleaseFenceHandle, uint64_t aTransactionId);
 
   void ClearAllAsyncTransactionTrackers();
 
@@ -203,17 +189,17 @@ protected:
 
   bool mIsTrackersHolderDestroyed;
   std::map<uint64_t, RefPtr<AsyncTransactionTracker> > mAsyncTransactionTrackers;
 
   /**
    * gecko does not provide atomic operation for uint64_t.
    * Ensure atomicity by using Mutex.
    */
-  static uint64_t sSerialCounter;
+  static Atomic<uint64_t> sSerialCounter;
   static Mutex* sHolderLock;
 
   /**
    * Map of all living AsyncTransactionTrackersHolder instances
    */
   static std::map<uint64_t, AsyncTransactionTrackersHolder*> sTrackersHolders;
 };