Bug 1324894 - use standard Monitor APIs rather than PR_Interrupt in BackgroundHangMonitor; r=darchons
authorNathan Froyd <froydnj@mozilla.com>
Fri, 20 Jan 2017 16:38:12 -0500
changeset 375490 5f42a80cee038ae943ba4d3f6278208e0350fc3c
parent 375489 c20b49c1ff854f0c38546bafbbd74b622cd8dec5
child 375491 17f78bed73c29ee9d9a0792c1643f37932c60027
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdarchons
bugs1324894
milestone53.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 1324894 - use standard Monitor APIs rather than PR_Interrupt in BackgroundHangMonitor; r=darchons Using PR_Interrupt here makes life difficult for other things, such as moving away from NSPR synchronization primitives.
xpcom/threads/BackgroundHangMonitor.cpp
--- a/xpcom/threads/BackgroundHangMonitor.cpp
+++ b/xpcom/threads/BackgroundHangMonitor.cpp
@@ -90,23 +90,21 @@ public:
 
   void Shutdown()
   {
     MonitorAutoLock autoLock(mLock);
     mShutdown = true;
     autoLock.Notify();
   }
 
+  // Attempt to wakeup the hang monitor thread.
   void Wakeup()
   {
-    // PR_CreateThread could have failed earlier
-    if (mHangMonitorThread) {
-      // Use PR_Interrupt to avoid potentially taking a lock
-      PR_Interrupt(mHangMonitorThread);
-    }
+    mLock.AssertCurrentThreadOwns();
+    mLock.NotifyAll();
   }
 
   BackgroundHangManager();
 private:
   virtual ~BackgroundHangManager();
 };
 
 NS_IMPL_ISUPPORTS(BackgroundHangManager, nsIObserver)
@@ -270,35 +268,33 @@ BackgroundHangManager::RunMonitorThread(
      used to track PR_IntervalNow() and determine our latency. */
 
   PRIntervalTime systemTime = PR_IntervalNow();
   // Default values for the first iteration of thread loop
   PRIntervalTime waitTime = PR_INTERVAL_NO_WAIT;
   PRIntervalTime recheckTimeout = PR_INTERVAL_NO_WAIT;
 
   while (!mShutdown) {
-
-    PR_ClearInterrupt();
     nsresult rv = autoLock.Wait(waitTime);
 
     PRIntervalTime newTime = PR_IntervalNow();
     PRIntervalTime systemInterval = newTime - systemTime;
     systemTime = newTime;
 
     /* waitTime is a quarter of the shortest timeout value; If our timing
        latency is low enough (less than half the shortest timeout value),
        we can update mIntervalNow. */
     if (MOZ_LIKELY(waitTime != PR_INTERVAL_NO_TIMEOUT &&
                    systemInterval < 2 * waitTime)) {
       mIntervalNow += systemInterval;
     }
 
-    /* If it's before the next recheck timeout, and our wait did not
-       get interrupted (either through Notify or PR_Interrupt), we can
-       keep the current waitTime and skip iterating through hang monitors. */
+    /* If it's before the next recheck timeout, and our wait did not get
+       interrupted, we can keep the current waitTime and skip iterating
+       through hang monitors. */
     if (MOZ_LIKELY(systemInterval < recheckTimeout &&
                    systemInterval >= waitTime &&
                    rv == NS_OK)) {
       recheckTimeout -= systemInterval;
       continue;
     }
 
     /* We are in one of the following scenarios,