Bug 1033121 - Release |mTimer| in nsTimerEvent::Run() instead of ~nsTimerEvent() to avoid race. r=bz
authorJW Wang <jwwang@mozilla.com>
Thu, 10 Jul 2014 11:23:02 -0400
changeset 193391 2f00e114a4894d78cecd54b8e064fd5c057396e3
parent 193390 ab6ad70d1a3effbf6faaa4e88e31dcdf05117973
child 193392 df6ba75a47bdc5f1e460d9e9079f92374e776e52
push id27117
push userryanvm@gmail.com
push dateThu, 10 Jul 2014 22:23:14 +0000
treeherdermozilla-central@e1a037c085d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1033121
milestone33.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 1033121 - Release |mTimer| in nsTimerEvent::Run() instead of ~nsTimerEvent() to avoid race. r=bz
xpcom/threads/nsTimerImpl.cpp
--- a/xpcom/threads/nsTimerImpl.cpp
+++ b/xpcom/threads/nsTimerImpl.cpp
@@ -704,16 +704,21 @@ nsTimerEvent::Run()
     TimeStamp now = TimeStamp::Now();
     PR_LOG(GetTimerLog(), PR_LOG_DEBUG,
            ("[this=%p] time between PostTimerEvent() and Fire(): %fms\n",
             this, (now - mInitTime).ToMilliseconds()));
   }
 #endif
 
   mTimer->Fire();
+  // 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;
 
   return NS_OK;
 }
 
 already_AddRefed<nsTimerImpl>
 nsTimerImpl::PostTimerEvent(already_AddRefed<nsTimerImpl> aTimerRef)
 {
   nsRefPtr<nsTimerImpl> timer(aTimerRef);