mirror of
https://github.com/servo/servo.git
synced 2025-07-20 13:53:42 +01:00
Auto merge of #11734 - DarinM223:master, r=Ms2ger
Replace RefCell in SCRIPT_THREAD_ROOT with Cell <!-- Please describe your changes on the following line: --> Replaced RefCell usage in SCRIPT_THREAD_ROOT with Cell. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [X] These changes fix #11732 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because it is refactoring existing code <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11734) <!-- Reviewable:end -->
This commit is contained in:
commit
df4693489d
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