Bug 1402595 - Don't wait on cooperative thread cvar after marking the current thread as having finished, r=jandem.
authorBrian Hackett <bhackett1024@gmail.com>
Wed, 01 Nov 2017 09:56:59 -0600
changeset 389668 9cff4b8eb3965ec0aa67be915f36e087bfb32538
parent 389667 33134954c638c1516caa20d6d13b0dce378af389
child 389669 cc4275f8755c2543e4fb05e58ee2b848bcef4950
push id32789
push userarchaeopteryx@coole-files.de
push dateWed, 01 Nov 2017 21:55:42 +0000
treeherdermozilla-central@e81094853e1d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1402595
milestone58.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 1402595 - Don't wait on cooperative thread cvar after marking the current thread as having finished, r=jandem.
js/src/shell/js.cpp
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -3378,26 +3378,26 @@ CooperativeEndWait(JSContext* cx)
 
     JS_ResumeCooperativeContext(cx);
     cooperationState->idle = false;
     cooperationState->yieldCount++;
     cooperationState->cvar.notify_all();
 }
 
 static void
-CooperativeYield()
+CooperativeYield(bool terminating = false)
 {
     LockGuard<Mutex> lock(cooperationState->lock);
     MOZ_ASSERT(!cooperationState->idle);
     cooperationState->idle = true;
     cooperationState->cvar.notify_all();
 
     // Wait until another thread takes over control before returning, if there
     // is another thread to do so.
-    if (cooperationState->numThreads) {
+    if (!terminating && cooperationState->numThreads) {
         uint64_t count = cooperationState->yieldCount;
         cooperationState->cvar.wait(lock, [&] { return cooperationState->yieldCount != count; });
     }
 }
 
 static bool
 CooperativeThreadMayYield(JSContext* cx)
 {
@@ -3547,17 +3547,17 @@ WorkerMain(void* arg)
     if (!sc)
         return;
 
     auto guard = mozilla::MakeScopeExit([&] {
         JS_DestroyContext(cx);
         js_delete(sc);
         if (input->siblingContext) {
             cooperationState->numThreads--;
-            CooperativeYield();
+            CooperativeYield(/* terminating = */ true);
         }
         js_delete(input);
     });
 
     if (input->parentRuntime)
         sc->isWorker = true;
     JS_SetContextPrivate(cx, sc);
     SetWorkerContextOptions(cx);