Bug 1398393 - Set Servo thread state on cooperative threads. r=billm draft
authorBlake Kaplan <mrbkap@gmail.com>
Fri, 08 Sep 2017 16:50:34 -0700
changeset 667345 cc1c9254de23444e77ecdf9dc2be881bf87f28d6
parent 667303 a0eb21bf55e1c1ae0ba311e6f2273da05c712799
child 732352 24a000d4d90b0fc964584fb86af120d6550e9de2
push id80676
push userbmo:mrbkap@mozilla.com
push dateTue, 19 Sep 2017 23:44:51 +0000
reviewersbillm
bugs1398393
milestone57.0a1
Bug 1398393 - Set Servo thread state on cooperative threads. r=billm By doing this we avoid triggering assertions in the Servo code that ensure we have registered the thread with Servo and set the proper state on it. MozReview-Commit-ID: K6qHrYoQDLm
layout/style/ServoBindingList.h
xpcom/threads/CooperativeThreadPool.cpp
xpcom/threads/Scheduler.cpp
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -535,16 +535,18 @@ SERVO_BINDING_FUNC(Servo_ComputedValues_
 // to RawServoStyleRule.
 SERVO_BINDING_FUNC(Servo_ComputedValues_GetStyleRuleList, void,
                    ServoStyleContextBorrowed values,
                    RawGeckoServoStyleRuleListBorrowedMut rules)
 
 // Initialize Servo components. Should be called exactly once at startup.
 SERVO_BINDING_FUNC(Servo_Initialize, void,
                    RawGeckoURLExtraData* dummy_url_data)
+// Initialize Servo on a cooperative Quantum DOM thread.
+SERVO_BINDING_FUNC(Servo_InitializeCooperativeThread, void);
 // Shut down Servo components. Should be called exactly once at shutdown.
 SERVO_BINDING_FUNC(Servo_Shutdown, void)
 
 // Restyle and change hints.
 SERVO_BINDING_FUNC(Servo_NoteExplicitHints, void, RawGeckoElementBorrowed element,
                    nsRestyleHint restyle_hint, nsChangeHint change_hint)
 // We'd like to return `nsChangeHint` here, but bindgen bitfield enums don't
 // work as return values with the Linux 32-bit ABI at the moment because
--- a/xpcom/threads/CooperativeThreadPool.cpp
+++ b/xpcom/threads/CooperativeThreadPool.cpp
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "CooperativeThreadPool.h"
 
 #include "base/message_loop.h"
 #include "mozilla/IOInterposer.h"
+#include "mozilla/ServoBindings.h"
 #include "nsError.h"
 #include "nsThreadUtils.h"
 
 using namespace mozilla;
 
 static bool gCooperativeSchedulingEnabled;
 MOZ_THREAD_LOCAL(CooperativeThreadPool::CooperativeThread*) CooperativeThreadPool::sTlsCurrentThread;
 
--- a/xpcom/threads/Scheduler.cpp
+++ b/xpcom/threads/Scheduler.cpp
@@ -648,16 +648,17 @@ SchedulerImpl::ThreadController::OnStart
   xpc::CreateCooperativeContext();
 
   JSContext* cx = dom::danger::GetJSContext();
   mScheduler->SetJSContext(aIndex, cx);
   if (sPrefPreemption) {
     JS_AddInterruptCallback(cx, SchedulerImpl::InterruptCallback);
   }
   js::SetCooperativeYieldCallback(cx, SchedulerImpl::YieldCallback);
+  Servo_InitializeCooperativeThread();
 }
 
 void
 SchedulerImpl::ThreadController::OnStopThread(size_t aIndex)
 {
   xpc::DestroyCooperativeContext();
 
   NS_UnsetMainThread();