Bug 969165 - Convert Atomic<T> where T != bool but is used as a bool over to Atomic<bool>, now that it's supported, in xpcom/. r=froydnj
authorJeff Walden <jwalden@mit.edu>
Thu, 06 Feb 2014 22:05:24 -0800
changeset 167978 1b3ab13a219b2c332d569ef7d04685c7600651ad
parent 167977 b346f11002eb413e1c799126a5888e48c1bcbd23
child 167979 d9dc94e75a5c7e1ed4a2c681ed0a5ec8a4014f9e
push id26194
push userryanvm@gmail.com
push dateTue, 11 Feb 2014 13:39:41 +0000
treeherdermozilla-central@edd724161ab4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs969165
milestone30.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 969165 - Convert Atomic<T> where T != bool but is used as a bool over to Atomic<bool>, now that it's supported, in xpcom/. r=froydnj
xpcom/base/nsMemoryImpl.cpp
xpcom/base/nsMemoryImpl.h
xpcom/threads/TimerThread.cpp
xpcom/threads/TimerThread.h
--- a/xpcom/base/nsMemoryImpl.cpp
+++ b/xpcom/base/nsMemoryImpl.cpp
@@ -108,17 +108,17 @@ nsMemoryImpl::FlushMemory(const char16_t
         // got to be on the UI main thread for us to be able to do
         // that...are we?
         if (!NS_IsMainThread()) {
             NS_ERROR("can't synchronously flush memory: not on UI thread");
             return NS_ERROR_FAILURE;
         }
     }
 
-    int32_t lastVal = sIsFlushing.exchange(1);
+    bool lastVal = sIsFlushing.exchange(true);
     if (lastVal)
         return NS_OK;
 
     PRIntervalTime now = PR_IntervalNow();
 
     // Run the flushers immediately if we can; otherwise, proxy to the
     // UI thread an run 'em asynchronously.
     if (aImmediate) {
@@ -149,45 +149,45 @@ nsMemoryImpl::RunFlushers(const char16_t
 
         nsCOMPtr<nsISimpleEnumerator> e;
         os->EnumerateObservers("memory-pressure", getter_AddRefs(e));
 
         if ( e ) {
           nsCOMPtr<nsIObserver> observer;
           bool loop = true;
 
-          while (NS_SUCCEEDED(e->HasMoreElements(&loop)) && loop) 
+          while (NS_SUCCEEDED(e->HasMoreElements(&loop)) && loop)
           {
               e->GetNext(getter_AddRefs(observer));
 
               if (!observer)
                   continue;
 
               observer->Observe(observer, "memory-pressure", aReason);
           }
         }
     }
 
-    sIsFlushing = 0;
+    sIsFlushing = false;
     return NS_OK;
 }
 
 // XXX need NS_IMPL_STATIC_ADDREF/RELEASE
 NS_IMETHODIMP_(nsrefcnt) nsMemoryImpl::FlushEvent::AddRef() { return 2; }
 NS_IMETHODIMP_(nsrefcnt) nsMemoryImpl::FlushEvent::Release() { return 1; }
 NS_IMPL_QUERY_INTERFACE1(nsMemoryImpl::FlushEvent, nsIRunnable)
 
 NS_IMETHODIMP
 nsMemoryImpl::FlushEvent::Run()
 {
     sGlobalMemory.RunFlushers(mReason);
     return NS_OK;
 }
 
-mozilla::Atomic<int32_t>
+mozilla::Atomic<bool>
 nsMemoryImpl::sIsFlushing;
 
 PRIntervalTime
 nsMemoryImpl::sLastFlushTime = 0;
 
 nsMemoryImpl::FlushEvent
 nsMemoryImpl::sFlushEvent;
 
--- a/xpcom/base/nsMemoryImpl.h
+++ b/xpcom/base/nsMemoryImpl.h
@@ -33,14 +33,14 @@ public:
 
 protected:
     struct FlushEvent : public nsIRunnable {
         NS_DECL_ISUPPORTS_INHERITED
         NS_DECL_NSIRUNNABLE
         const char16_t* mReason;
     };
 
-    static mozilla::Atomic<int32_t> sIsFlushing;
+    static mozilla::Atomic<bool> sIsFlushing;
     static FlushEvent sFlushEvent;
     static PRIntervalTime sLastFlushTime;
 };
 
 #endif // nsMemoryImpl_h__
--- a/xpcom/threads/TimerThread.cpp
+++ b/xpcom/threads/TimerThread.cpp
@@ -15,17 +15,17 @@
 
 #include <math.h>
 
 using namespace mozilla;
 
 NS_IMPL_ISUPPORTS2(TimerThread, nsIRunnable, nsIObserver)
 
 TimerThread::TimerThread() :
-  mInitInProgress(0),
+  mInitInProgress(false),
   mInitialized(false),
   mMonitor("TimerThread.mMonitor"),
   mShutdown(false),
   mWaiting(false),
   mSleeping(false)
 {
 }
 
@@ -79,17 +79,17 @@ nsresult TimerThread::Init()
 
   if (mInitialized) {
     if (!mThread)
       return NS_ERROR_FAILURE;
 
     return NS_OK;
   }
 
-  if (mInitInProgress.exchange(1) == 0) {
+  if (mInitInProgress.exchange(true) == false) {
     // We hold on to mThread to keep the thread alive.
     nsresult rv = NS_NewThread(getter_AddRefs(mThread), this);
     if (NS_FAILED(rv)) {
       mThread = nullptr;
     }
     else {
       nsRefPtr<TimerObserverRunnable> r = new TimerObserverRunnable(this);
       if (NS_IsMainThread()) {
@@ -239,17 +239,17 @@ NS_IMETHODIMP TimerThread::Run()
 #endif
 
             // We are going to let the call to PostTimerEvent here handle the
             // release of the timer so that we don't end up releasing the timer
             // on the TimerThread instead of on the thread it targets.
             if (NS_FAILED(timer->PostTimerEvent())) {
               nsrefcnt rc;
               NS_RELEASE2(timer, rc);
-            
+
               // The nsITimer interface requires that its users keep a reference
               // to the timers they use while those timers are initialized but
               // have not yet fired.  If this ever happens, it is a bug in the
               // code that created and used the timer.
               //
               // Further, note that this should never happen even with a
               // misbehaving user, because nsTimerImpl::Release checks for a
               // refcount of 1 with an armed timer (a timer whose only reference
--- a/xpcom/threads/TimerThread.h
+++ b/xpcom/threads/TimerThread.h
@@ -32,17 +32,17 @@ public:
   typedef mozilla::TimeDuration TimeDuration;
 
   TimerThread();
   NS_HIDDEN_(nsresult) InitLocks();
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
   NS_DECL_NSIOBSERVER
-  
+
   NS_HIDDEN_(nsresult) Init();
   NS_HIDDEN_(nsresult) Shutdown();
 
   nsresult AddTimer(nsTimerImpl *aTimer);
   nsresult TimerDelayChanged(nsTimerImpl *aTimer);
   nsresult RemoveTimer(nsTimerImpl *aTimer);
 
   void DoBeforeSleep();
@@ -51,33 +51,33 @@ public:
   bool IsOnTimerThread() const
   {
     return mThread == NS_GetCurrentThread();
   }
 
 private:
   ~TimerThread();
 
-  mozilla::Atomic<int32_t> mInitInProgress;
+  mozilla::Atomic<bool> mInitInProgress;
   bool    mInitialized;
 
   // These two internal helper methods must be called while mLock is held.
   // AddTimerInternal returns the position where the timer was added in the
   // list, or -1 if it failed.
   int32_t AddTimerInternal(nsTimerImpl *aTimer);
   bool    RemoveTimerInternal(nsTimerImpl *aTimer);
   void    ReleaseTimerInternal(nsTimerImpl *aTimer);
 
   nsCOMPtr<nsIThread> mThread;
   Monitor mMonitor;
 
   bool mShutdown;
   bool mWaiting;
   bool mSleeping;
-  
+
   nsTArray<nsTimerImpl*> mTimers;
 };
 
 struct TimerAdditionComparator {
   TimerAdditionComparator(const mozilla::TimeStamp &aNow,
                           nsTimerImpl *aTimerToInsert) :
     now(aNow)
 #ifdef DEBUG