Bug 1339588 - Part 1: Simplify nsTimerEvent::Cancel, since there's no need to release the nsTimerImpl itself. r=froydnj, a=dveditz
authorByron Campen [:bwc] <docfaraday@gmail.com>
Tue, 14 Feb 2017 15:29:01 -0600
changeset 395730 48bcbeacbf019b819ef773533333422327a01c92
parent 395729 4c6327208ad2aa689b0291853571c1ccc1f16392
child 395731 36e47083c3ba20c5d5e5e6b1f0ca33790069ef12
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, dveditz
bugs1339588
milestone54.0a2
Bug 1339588 - Part 1: Simplify nsTimerEvent::Cancel, since there's no need to release the nsTimerImpl itself. r=froydnj, a=dveditz MozReview-Commit-ID: 6br6DaDqxR0
xpcom/threads/TimerThread.cpp
--- a/xpcom/threads/TimerThread.cpp
+++ b/xpcom/threads/TimerThread.cpp
@@ -136,21 +136,17 @@ public:
 // instead of Run().
 class nsTimerEvent final : public CancelableRunnable
 {
 public:
   NS_IMETHOD Run() override;
 
   nsresult Cancel() override
   {
-    // Since nsTimerImpl is not thread-safe, we should release |mTimer|
-    // here in the target thread to avoid race condition. Otherwise,
-    // ~nsTimerEvent() which calls nsTimerImpl::Release() could run in the
-    // timer thread and result in race condition.
-    mTimer = nullptr;
+    mTimer->Cancel();
     return NS_OK;
   }
 
   NS_IMETHOD GetName(nsACString& aName) override;
 
   nsTimerEvent()
     : mTimer()
     , mGeneration(0)
@@ -277,33 +273,26 @@ nsTimerEvent::GetName(nsACString& aName)
 
   mTimer->GetName(aName);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTimerEvent::Run()
 {
-  if (!mTimer) {
-    MOZ_ASSERT(false);
-    return NS_OK;
-  }
-
   if (MOZ_LOG_TEST(GetTimerLog(), LogLevel::Debug)) {
     TimeStamp now = TimeStamp::Now();
     MOZ_LOG(GetTimerLog(), LogLevel::Debug,
            ("[this=%p] time between PostTimerEvent() and Fire(): %fms\n",
             this, (now - mInitTime).ToMilliseconds()));
   }
 
   mTimer->Fire(mGeneration);
 
-  // We call Cancel() to correctly release mTimer.
-  // Read more in the Cancel() implementation.
-  return Cancel();
+  return NS_OK;
 }
 
 nsresult
 TimerThread::Init()
 {
   MOZ_LOG(GetTimerLog(), LogLevel::Debug,
          ("TimerThread::Init [%d]\n", mInitialized));