Bug 1208957 - No need for a condvar for thread shutdown. draft
authorBlake Kaplan <mrbkap@gmail.com>
Tue, 14 Mar 2017 23:36:02 -0700
changeset 499345 e326ba0a5bb75e08e01dd229523508fa720b6854
parent 499344 225e2aa99df408ccb27e3089d8bd85d30f1aa833
child 549313 cd5b553467f251dd8a308391db9ac2bcdc64cf83
push id49370
push userbmo:mrbkap@mozilla.com
push dateWed, 15 Mar 2017 16:36:02 +0000
bugs1208957
milestone55.0a1
Bug 1208957 - No need for a condvar for thread shutdown. Now that we join on the thread exiting, we no longer need to have the thread explicitly tell us it's shutting down. MozReview-Commit-ID: LycPjUvyeX
js/xpconnect/src/XPCJSContext.cpp
--- a/js/xpconnect/src/XPCJSContext.cpp
+++ b/js/xpconnect/src/XPCJSContext.cpp
@@ -995,22 +995,23 @@ class Watchdog
         {   // Scoped lock.
             AutoLockWatchdog lock(this);
 
             // Signal to the watchdog thread that it's time to shut down.
             mShuttingDown = true;
 
             // Wake up the watchdog, and wait for it to call us back.
             PR_NotifyCondVar(mWakeup);
-            PR_WaitCondVar(mWakeup, PR_INTERVAL_NO_TIMEOUT);
-            MOZ_ASSERT(!mShuttingDown);
         }
 
         PR_JoinThread(mThread);
 
+        // The thread sets mShuttingDown to false as it exits.
+        MOZ_ASSERT(!mShuttingDown);
+
         // Destroy state.
         mThread = nullptr;
         PR_DestroyCondVar(mWakeup);
         mWakeup = nullptr;
         PR_DestroyLock(mLock);
         mLock = nullptr;
 
         // All done.
@@ -1039,17 +1040,16 @@ class Watchdog
     {
         MOZ_ASSERT(!NS_IsMainThread());
         MOZ_ALWAYS_TRUE(PR_WaitCondVar(mWakeup, timeout) == PR_SUCCESS);
     }
     void Finished()
     {
         MOZ_ASSERT(!NS_IsMainThread());
         mShuttingDown = false;
-        PR_NotifyCondVar(mWakeup);
     }
 
     int32_t MinScriptRunTimeSeconds()
     {
         return mMinScriptRunTimeSeconds;
     }
 
   private: