Bug 1122420 - Improve after-shutdown dispatch assertion on CacheIOThread. r=michal, a=sledru
authorHonza Bambas <honzab.moz@firemni.cz>
Mon, 13 Apr 2015 16:58:00 +0200
changeset 266167 082a23c146bd
parent 266166 abcd95bb7212
child 266168 d8904a3f0278
push id4771
push userryanvm@gmail.com
push date2015-06-02 20:21 +0000
treeherdermozilla-beta@082a23c146bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmichal, sledru
bugs1122420
milestone39.0
Bug 1122420 - Improve after-shutdown dispatch assertion on CacheIOThread. r=michal, a=sledru
netwerk/cache2/CacheIOThread.cpp
netwerk/cache2/CacheIOThread.h
--- a/netwerk/cache2/CacheIOThread.cpp
+++ b/netwerk/cache2/CacheIOThread.cpp
@@ -22,16 +22,17 @@ NS_IMPL_ISUPPORTS(CacheIOThread, nsIThre
 CacheIOThread::CacheIOThread()
 : mMonitor("CacheIOThread")
 , mThread(nullptr)
 , mLowestLevelWaiting(LAST_LEVEL)
 , mCurrentlyExecutingLevel(0)
 , mHasXPCOMEvents(false)
 , mRerunCurrentEvent(false)
 , mShutdown(false)
+, mInsideLoop(true)
 {
   sSelf = this;
 }
 
 CacheIOThread::~CacheIOThread()
 {
   sSelf = nullptr;
 #ifdef DEBUG
@@ -232,16 +233,19 @@ loopStart:
       lock.Wait(PR_INTERVAL_NO_TIMEOUT);
 
       if (EventsPending())
         continue;
 
     } while (true);
 
     MOZ_ASSERT(!EventsPending());
+
+    // This is for correct assertion on XPCOM events dispatch.
+    mInsideLoop = false;
   } // lock
 
   if (threadInternal)
     threadInternal->SetObserver(nullptr);
 }
 
 static const char* const sLevelTraceName[] = {
   "net::cache::io::level(0)",
@@ -308,17 +312,17 @@ bool CacheIOThread::EventsPending(uint32
 {
   return mLowestLevelWaiting < aLastLevel || mHasXPCOMEvents;
 }
 
 NS_IMETHODIMP CacheIOThread::OnDispatchedEvent(nsIThreadInternal *thread)
 {
   MonitorAutoLock lock(mMonitor);
   mHasXPCOMEvents = true;
-  MOZ_ASSERT(!mShutdown || (PR_GetCurrentThread() == mThread));
+  MOZ_ASSERT(mInsideLoop);
   lock.Notify();
   return NS_OK;
 }
 
 NS_IMETHODIMP CacheIOThread::OnProcessNextEvent(nsIThreadInternal *thread, bool mayWait, uint32_t recursionDepth)
 {
   return NS_OK;
 }
--- a/netwerk/cache2/CacheIOThread.h
+++ b/netwerk/cache2/CacheIOThread.h
@@ -6,16 +6,17 @@
 #define CacheIOThread__h__
 
 #include "nsIThreadInternal.h"
 #include "nsISupportsImpl.h"
 #include "prthread.h"
 #include "nsTArray.h"
 #include "nsAutoPtr.h"
 #include "mozilla/Monitor.h"
+#include "mozilla/DebugOnly.h"
 
 class nsIRunnable;
 
 namespace mozilla {
 namespace net {
 
 class CacheIOThread : public nsIThreadObserver
 {
@@ -89,14 +90,15 @@ private:
   nsCOMPtr<nsIThread> mXPCOMThread;
   uint32_t mLowestLevelWaiting;
   uint32_t mCurrentlyExecutingLevel;
   nsTArray<nsCOMPtr<nsIRunnable> > mEventQueue[LAST_LEVEL];
 
   bool mHasXPCOMEvents;
   bool mRerunCurrentEvent;
   bool mShutdown;
+  DebugOnly<bool> mInsideLoop;
 };
 
 } // net
 } // mozilla
 
 #endif