Bug 1059572 - Part 2: Make absolutely sure a timer is removed before reinitting it. r=nfroyd
authorByron Campen [:bwc] <docfaraday@gmail.com>
Tue, 28 Jul 2015 10:10:54 -0500
changeset 286986 80677b385ce0866067fa7bb5c1b3765ac8c67181
parent 286985 7793255f366e01dd38aac596d094c853bc6d94df
child 286987 d45d53f73998a0326a3a8a6ad564e4b75a257428
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnfroyd
bugs1059572
milestone42.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 1059572 - Part 2: Make absolutely sure a timer is removed before reinitting it. r=nfroyd
xpcom/threads/nsTimerImpl.cpp
--- a/xpcom/threads/nsTimerImpl.cpp
+++ b/xpcom/threads/nsTimerImpl.cpp
@@ -200,33 +200,17 @@ nsTimerImpl::InitCommon(uint32_t aType, 
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   rv = gThread->Init();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  /**
-   * In case of re-Init, both with and without a preceding Cancel, clear the
-   * mCanceled flag and assign a new mGeneration.  But first, remove any armed
-   * timer from the timer thread's list.
-   *
-   * If we are racing with the timer thread to remove this timer and we lose,
-   * the RemoveTimer call made here will fail to find this timer in the timer
-   * thread's list, and will return false harmlessly.  We test mArmed here to
-   * avoid the small overhead in RemoveTimer of locking the timer thread and
-   * checking its list for this timer.  It's safe to test mArmed even though
-   * it might be cleared on another thread in the next cycle (or even already
-   * be cleared by another CPU whose store hasn't reached our CPU's cache),
-   * because RemoveTimer is idempotent.
-   */
-  if (mArmed) {
-    gThread->RemoveTimer(this);
-  }
+  gThread->RemoveTimer(this);
   mCanceled = false;
   mTimeout = TimeStamp();
   mGeneration = gGenerator++;
 
   mType = (uint8_t)aType;
   SetDelayInternal(aDelay);
 
   return gThread->AddTimer(this);