mirror of
https://github.com/servo/servo.git
synced 2025-07-26 00:30:22 +01:00
Replace RefCell in SCRIPT_THREAD_ROOT with Cell
This commit is contained in:
parent
b5115fc895
commit
a158e478b8
1 changed files with 10 additions and 10 deletions
|
@ -87,7 +87,7 @@ use script_traits::{NewLayoutInfo, ScriptMsg as ConstellationMsg};
|
||||||
use script_traits::{ScriptThreadFactory, TimerEvent, TimerEventRequest, TimerSource};
|
use script_traits::{ScriptThreadFactory, TimerEvent, TimerEventRequest, TimerSource};
|
||||||
use script_traits::{TouchEventType, TouchId, UntrustedNodeAddress};
|
use script_traits::{TouchEventType, TouchId, UntrustedNodeAddress};
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::Cell;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::option::Option;
|
use std::option::Option;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
@ -111,11 +111,11 @@ use util::thread_state;
|
||||||
use webdriver_handlers;
|
use webdriver_handlers;
|
||||||
|
|
||||||
thread_local!(pub static STACK_ROOTS: Cell<Option<RootCollectionPtr>> = Cell::new(None));
|
thread_local!(pub static STACK_ROOTS: Cell<Option<RootCollectionPtr>> = Cell::new(None));
|
||||||
thread_local!(static SCRIPT_THREAD_ROOT: RefCell<Option<*const ScriptThread>> = RefCell::new(None));
|
thread_local!(static SCRIPT_THREAD_ROOT: Cell<Option<*const ScriptThread>> = Cell::new(None));
|
||||||
|
|
||||||
pub unsafe fn trace_thread(tr: *mut JSTracer) {
|
pub unsafe fn trace_thread(tr: *mut JSTracer) {
|
||||||
SCRIPT_THREAD_ROOT.with(|root| {
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
if let Some(script_thread) = *root.borrow() {
|
if let Some(script_thread) = root.get() {
|
||||||
debug!("tracing fields of ScriptThread");
|
debug!("tracing fields of ScriptThread");
|
||||||
(*script_thread).trace(tr);
|
(*script_thread).trace(tr);
|
||||||
}
|
}
|
||||||
|
@ -461,7 +461,7 @@ impl ScriptThreadFactory for ScriptThread {
|
||||||
script_chan.clone());
|
script_chan.clone());
|
||||||
|
|
||||||
SCRIPT_THREAD_ROOT.with(|root| {
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
*root.borrow_mut() = Some(&script_thread as *const _);
|
root.set(Some(&script_thread as *const _));
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut failsafe = ScriptMemoryFailsafe::new(&script_thread);
|
let mut failsafe = ScriptMemoryFailsafe::new(&script_thread);
|
||||||
|
@ -494,7 +494,7 @@ impl ScriptThread {
|
||||||
pub fn page_headers_available(id: &PipelineId, subpage: Option<&SubpageId>, metadata: Option<Metadata>)
|
pub fn page_headers_available(id: &PipelineId, subpage: Option<&SubpageId>, metadata: Option<Metadata>)
|
||||||
-> Option<ParserRoot> {
|
-> Option<ParserRoot> {
|
||||||
SCRIPT_THREAD_ROOT.with(|root| {
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
let script_thread = unsafe { &*root.borrow().unwrap() };
|
let script_thread = unsafe { &*root.get().unwrap() };
|
||||||
script_thread.handle_page_headers_available(id, subpage, metadata)
|
script_thread.handle_page_headers_available(id, subpage, metadata)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -502,21 +502,21 @@ impl ScriptThread {
|
||||||
// stores a service worker registration
|
// stores a service worker registration
|
||||||
pub fn set_registration(scope_url: Url, registration:&ServiceWorkerRegistration) {
|
pub fn set_registration(scope_url: Url, registration:&ServiceWorkerRegistration) {
|
||||||
SCRIPT_THREAD_ROOT.with(|root| {
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
let script_thread = unsafe { &*root.borrow().unwrap() };
|
let script_thread = unsafe { &*root.get().unwrap() };
|
||||||
script_thread.handle_serviceworker_registration(scope_url, registration);
|
script_thread.handle_serviceworker_registration(scope_url, registration);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parsing_complete(id: PipelineId) {
|
pub fn parsing_complete(id: PipelineId) {
|
||||||
SCRIPT_THREAD_ROOT.with(|root| {
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
let script_thread = unsafe { &*root.borrow().unwrap() };
|
let script_thread = unsafe { &*root.get().unwrap() };
|
||||||
script_thread.handle_parsing_complete(id);
|
script_thread.handle_parsing_complete(id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_event(msg: CommonScriptMsg) {
|
pub fn process_event(msg: CommonScriptMsg) {
|
||||||
SCRIPT_THREAD_ROOT.with(|root| {
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
if let Some(script_thread) = *root.borrow() {
|
if let Some(script_thread) = root.get() {
|
||||||
let script_thread = unsafe { &*script_thread };
|
let script_thread = unsafe { &*script_thread };
|
||||||
script_thread.handle_msg_from_script(MainThreadScriptMsg::Common(msg));
|
script_thread.handle_msg_from_script(MainThreadScriptMsg::Common(msg));
|
||||||
}
|
}
|
||||||
|
@ -527,7 +527,7 @@ impl ScriptThread {
|
||||||
pub fn await_stable_state<T: Runnable + Send + 'static>(task: T) {
|
pub fn await_stable_state<T: Runnable + Send + 'static>(task: T) {
|
||||||
//TODO use microtasks when they exist
|
//TODO use microtasks when they exist
|
||||||
SCRIPT_THREAD_ROOT.with(|root| {
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
if let Some(script_thread) = *root.borrow() {
|
if let Some(script_thread) = root.get() {
|
||||||
let script_thread = unsafe { &*script_thread };
|
let script_thread = unsafe { &*script_thread };
|
||||||
let _ = script_thread.chan.send(CommonScriptMsg::RunnableMsg(
|
let _ = script_thread.chan.send(CommonScriptMsg::RunnableMsg(
|
||||||
ScriptThreadEventCategory::DomEvent,
|
ScriptThreadEventCategory::DomEvent,
|
||||||
|
@ -2051,7 +2051,7 @@ impl ScriptThread {
|
||||||
impl Drop for ScriptThread {
|
impl Drop for ScriptThread {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
SCRIPT_THREAD_ROOT.with(|root| {
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
*root.borrow_mut() = None;
|
root.set(None);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue