Bug 975335 - Allow calling CurrentThreadCanAccess{Runtime,Zone} from any thread, r=luke.
authorBrian Hackett <bhackett1024@gmail.com>
Fri, 21 Feb 2014 13:22:39 -0700
changeset 170317 6d1407d6ec52fa226d86f4d4eee7122b3db460ce
parent 170316 ce1a691650ef8200e136bf9b4a345cc06189ed00
child 170318 8fb083fffb02786b2648a52ed8fe7fa2c29c0b6f
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersluke
bugs975335
milestone30.0a1
Bug 975335 - Allow calling CurrentThreadCanAccess{Runtime,Zone} from any thread, r=luke.
js/src/vm/Runtime.cpp
--- a/js/src/vm/Runtime.cpp
+++ b/js/src/vm/Runtime.cpp
@@ -865,27 +865,34 @@ JSRuntime::clearUsedByExclusiveThread(Zo
     JS_ASSERT(zone->usedByExclusiveThread);
     zone->usedByExclusiveThread = false;
     numExclusiveThreads--;
 }
 
 bool
 js::CurrentThreadCanAccessRuntime(JSRuntime *rt)
 {
-    DebugOnly<PerThreadData *> pt = js::TlsPerThreadData.get();
-    JS_ASSERT(pt && pt->associatedWith(rt));
     return rt->ownerThread_ == PR_GetCurrentThread() || InExclusiveParallelSection();
 }
 
 bool
 js::CurrentThreadCanAccessZone(Zone *zone)
 {
-    DebugOnly<PerThreadData *> pt = js::TlsPerThreadData.get();
-    JS_ASSERT(pt && pt->associatedWith(zone->runtime_));
-    return !InParallelSection() || InExclusiveParallelSection();
+    if (CurrentThreadCanAccessRuntime(zone->runtime_))
+        return true;
+    if (InParallelSection()) {
+        DebugOnly<PerThreadData *> pt = js::TlsPerThreadData.get();
+        JS_ASSERT(pt && pt->associatedWith(zone->runtime_));
+        return true;
+    }
+
+    // Only zones in use by an exclusive thread can be used off the main thread
+    // or outside of PJS. We don't keep track of which thread owns such zones
+    // though, so this check is imperfect.
+    return zone->usedByExclusiveThread;
 }
 
 #else // JS_THREADSAFE
 
 bool
 js::CurrentThreadCanAccessRuntime(JSRuntime *rt)
 {
     return true;