Bug 1301796 - Remove racy code in nsCycleCollector::RegisterJSRuntime. r=smaug draft
authorAndrew McCreight <continuation@gmail.com>
Fri, 09 Sep 2016 15:14:15 -0700
changeset 413101 4611ccb5c6f7fb65ab900d980f6d0d90bac413e3
parent 413099 490a21383718796ec5adbcc796c1c5875bebf289
child 531137 903255ad8440501438c7c26e1deaf6564b2b3696
push id29336
push userbmo:continuation@gmail.com
push dateTue, 13 Sep 2016 15:45:27 +0000
reviewerssmaug
bugs1301796
milestone51.0a1
Bug 1301796 - Remove racy code in nsCycleCollector::RegisterJSRuntime. r=smaug MozReview-Commit-ID: 18MW4EYbaC8
xpcom/base/nsCycleCollector.cpp
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -3430,24 +3430,24 @@ nsCycleCollector::~nsCycleCollector()
 }
 
 void
 nsCycleCollector::RegisterJSRuntime(CycleCollectedJSRuntime* aJSRuntime)
 {
   MOZ_RELEASE_ASSERT(!mJSRuntime, "Multiple registrations of JS runtime in cycle collector");
   mJSRuntime = aJSRuntime;
 
+  if (!NS_IsMainThread()) {
+    return;
+  }
+
   // We can't register as a reporter in nsCycleCollector() because that runs
   // before the memory reporter manager is initialized.  So we do it here
   // instead.
-  static bool registered = false;
-  if (!registered) {
-    RegisterWeakMemoryReporter(this);
-    registered = true;
-  }
+  RegisterWeakMemoryReporter(this);
 }
 
 void
 nsCycleCollector::ForgetJSRuntime()
 {
   MOZ_RELEASE_ASSERT(mJSRuntime, "Forgetting JS runtime in cycle collector before a JS runtime was registered");
   mJSRuntime = nullptr;
 }