mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Move script_runtime::StackRootTLS to root::ThreadLocalStackRoots
This commit is contained in:
parent
a6d01c92d9
commit
8d566fbc3c
6 changed files with 31 additions and 32 deletions
|
@ -41,6 +41,7 @@ use std::default::Default;
|
|||
use std::hash::{Hash, Hasher};
|
||||
#[cfg(debug_assertions)]
|
||||
use std::intrinsics::type_name;
|
||||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
use std::ptr;
|
||||
|
@ -165,6 +166,23 @@ impl Clone for RootCollectionPtr {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct ThreadLocalStackRoots<'a>(PhantomData<&'a u32>);
|
||||
|
||||
impl<'a> ThreadLocalStackRoots<'a> {
|
||||
pub fn new(roots: &'a RootCollection) -> Self {
|
||||
STACK_ROOTS.with(|ref r| {
|
||||
r.set(Some(RootCollectionPtr(roots as *const _)))
|
||||
});
|
||||
ThreadLocalStackRoots(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Drop for ThreadLocalStackRoots<'a> {
|
||||
fn drop(&mut self) {
|
||||
STACK_ROOTS.with(|ref r| r.set(None));
|
||||
}
|
||||
}
|
||||
|
||||
impl RootCollection {
|
||||
/// Create an empty collection of roots
|
||||
pub fn new() -> RootCollection {
|
||||
|
|
|
@ -12,7 +12,7 @@ use dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding::Dedicat
|
|||
use dom::bindings::error::{ErrorInfo, ErrorResult};
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::reflector::DomObject;
|
||||
use dom::bindings::root::{DomRoot, RootCollection};
|
||||
use dom::bindings::root::{DomRoot, RootCollection, ThreadLocalStackRoots};
|
||||
use dom::bindings::str::DOMString;
|
||||
use dom::bindings::structuredclone::StructuredCloneData;
|
||||
use dom::errorevent::ErrorEvent;
|
||||
|
@ -32,7 +32,7 @@ use js::rust::Runtime;
|
|||
use msg::constellation_msg::TopLevelBrowsingContextId;
|
||||
use net_traits::{IpcSend, load_whole_resource};
|
||||
use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as RequestType};
|
||||
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, StackRootTLS, new_rt_and_cx};
|
||||
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, new_rt_and_cx};
|
||||
use script_runtime::ScriptThreadEventCategory::WorkerEvent;
|
||||
use script_traits::{TimerEvent, TimerSource, WorkerGlobalScopeInit, WorkerScriptLoadOrigin};
|
||||
use servo_rand::random;
|
||||
|
@ -172,7 +172,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
}
|
||||
|
||||
let roots = RootCollection::new();
|
||||
let _stack_roots_tls = StackRootTLS::new(&roots);
|
||||
let _stack_roots = ThreadLocalStackRoots::new(&roots);
|
||||
|
||||
let WorkerScriptLoadOrigin { referrer_url, referrer_policy, pipeline_id } = worker_load_origin;
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ use dom::bindings::codegen::Bindings::ServiceWorkerGlobalScopeBinding;
|
|||
use dom::bindings::codegen::Bindings::ServiceWorkerGlobalScopeBinding::ServiceWorkerGlobalScopeMethods;
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::reflector::DomObject;
|
||||
use dom::bindings::root::{DomRoot, RootCollection};
|
||||
use dom::bindings::root::{DomRoot, RootCollection, ThreadLocalStackRoots};
|
||||
use dom::bindings::str::DOMString;
|
||||
use dom::event::Event;
|
||||
use dom::eventtarget::EventTarget;
|
||||
|
@ -25,7 +25,7 @@ use js::jsval::UndefinedValue;
|
|||
use js::rust::Runtime;
|
||||
use net_traits::{load_whole_resource, IpcSend, CustomResponseMediator};
|
||||
use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as RequestType};
|
||||
use script_runtime::{CommonScriptMsg, ScriptChan, StackRootTLS, new_rt_and_cx};
|
||||
use script_runtime::{CommonScriptMsg, ScriptChan, new_rt_and_cx};
|
||||
use script_traits::{TimerEvent, WorkerGlobalScopeInit, ScopeThings, ServiceWorkerMsg, WorkerScriptLoadOrigin};
|
||||
use servo_config::prefs::PREFS;
|
||||
use servo_rand::random;
|
||||
|
@ -154,7 +154,7 @@ impl ServiceWorkerGlobalScope {
|
|||
thread::Builder::new().name(format!("ServiceWorker for {}", serialized_worker_url)).spawn(move || {
|
||||
thread_state::initialize(SCRIPT | IN_WORKER);
|
||||
let roots = RootCollection::new();
|
||||
let _stack_roots_tls = StackRootTLS::new(&roots);
|
||||
let _stack_roots = ThreadLocalStackRoots::new(&roots);
|
||||
|
||||
let WorkerScriptLoadOrigin { referrer_url, referrer_policy, pipeline_id } = worker_load_origin;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ use dom::bindings::inheritance::Castable;
|
|||
use dom::bindings::refcounted::TrustedPromise;
|
||||
use dom::bindings::reflector::Reflector;
|
||||
use dom::bindings::reflector::reflect_dom_object;
|
||||
use dom::bindings::root::{Dom, DomRoot, RootCollection};
|
||||
use dom::bindings::root::{Dom, DomRoot, RootCollection, ThreadLocalStackRoots};
|
||||
use dom::bindings::str::USVString;
|
||||
use dom::bindings::trace::JSTraceable;
|
||||
use dom::bindings::trace::RootedTraceableBox;
|
||||
|
@ -47,7 +47,6 @@ use net_traits::request::RequestMode;
|
|||
use net_traits::request::Type as RequestType;
|
||||
use script_runtime::CommonScriptMsg;
|
||||
use script_runtime::ScriptThreadEventCategory;
|
||||
use script_runtime::StackRootTLS;
|
||||
use script_runtime::new_rt_and_cx;
|
||||
use script_thread::{MainThreadScriptMsg, ScriptThread};
|
||||
use servo_rand;
|
||||
|
@ -429,7 +428,7 @@ impl WorkletThread {
|
|||
debug!("Initializing worklet thread.");
|
||||
thread_state::initialize(thread_state::SCRIPT | thread_state::IN_WORKER);
|
||||
let roots = RootCollection::new();
|
||||
let _stack_roots_tls = StackRootTLS::new(&roots);
|
||||
let _stack_roots = ThreadLocalStackRoots::new(&roots);
|
||||
let mut thread = RootedTraceableBox::new(WorkletThread {
|
||||
role: role,
|
||||
control_receiver: control_receiver,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue