mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Introduce GlobalScope::scheduler_chan
This commit is contained in:
parent
f789e73fd2
commit
c6ff767625
4 changed files with 23 additions and 32 deletions
|
@ -16,7 +16,6 @@ use dom::bindings::reflector::{Reflectable, Reflector};
|
||||||
use dom::globalscope::GlobalScope;
|
use dom::globalscope::GlobalScope;
|
||||||
use dom::window;
|
use dom::window;
|
||||||
use dom::workerglobalscope::WorkerGlobalScope;
|
use dom::workerglobalscope::WorkerGlobalScope;
|
||||||
use ipc_channel::ipc::IpcSender;
|
|
||||||
use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL};
|
use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL};
|
||||||
use js::glue::{IsWrapper, UnwrapObject};
|
use js::glue::{IsWrapper, UnwrapObject};
|
||||||
use js::jsapi::{CurrentGlobalOrNull, Evaluate2, GetGlobalForObjectCrossCompartment};
|
use js::jsapi::{CurrentGlobalOrNull, Evaluate2, GetGlobalForObjectCrossCompartment};
|
||||||
|
@ -30,7 +29,7 @@ use profile_traits::time;
|
||||||
use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan};
|
use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan};
|
||||||
use script_runtime::{ScriptPort, maybe_take_panic_result};
|
use script_runtime::{ScriptPort, maybe_take_panic_result};
|
||||||
use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread};
|
use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread};
|
||||||
use script_traits::{MsDuration, TimerEventRequest};
|
use script_traits::MsDuration;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::panic;
|
use std::panic;
|
||||||
use task_source::file_reading::FileReadingTaskSource;
|
use task_source::file_reading::FileReadingTaskSource;
|
||||||
|
@ -89,14 +88,6 @@ impl<'a> GlobalRef<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the scheduler channel to request timer events.
|
|
||||||
pub fn scheduler_chan(&self) -> &IpcSender<TimerEventRequest> {
|
|
||||||
match *self {
|
|
||||||
GlobalRef::Window(window) => window.scheduler_chan(),
|
|
||||||
GlobalRef::Worker(worker) => worker.scheduler_chan(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the `ResourceThreads` for this global scope.
|
/// Get the `ResourceThreads` for this global scope.
|
||||||
pub fn resource_threads(&self) -> ResourceThreads {
|
pub fn resource_threads(&self) -> ResourceThreads {
|
||||||
match *self {
|
match *self {
|
||||||
|
|
|
@ -12,7 +12,7 @@ use dom::eventtarget::EventTarget;
|
||||||
use ipc_channel::ipc::IpcSender;
|
use ipc_channel::ipc::IpcSender;
|
||||||
use js::jsapi::{JS_GetContext, JS_GetObjectRuntime, JSContext};
|
use js::jsapi::{JS_GetContext, JS_GetObjectRuntime, JSContext};
|
||||||
use profile_traits::{mem, time};
|
use profile_traits::{mem, time};
|
||||||
use script_traits::ScriptMsg as ConstellationMsg;
|
use script_traits::{ScriptMsg as ConstellationMsg, TimerEventRequest};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
|
@ -46,6 +46,9 @@ pub struct GlobalScope {
|
||||||
/// A handle for communicating messages to the constellation thread.
|
/// A handle for communicating messages to the constellation thread.
|
||||||
#[ignore_heap_size_of = "channels are hard"]
|
#[ignore_heap_size_of = "channels are hard"]
|
||||||
constellation_chan: IpcSender<ConstellationMsg>,
|
constellation_chan: IpcSender<ConstellationMsg>,
|
||||||
|
|
||||||
|
#[ignore_heap_size_of = "channels are hard"]
|
||||||
|
scheduler_chan: IpcSender<TimerEventRequest>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlobalScope {
|
impl GlobalScope {
|
||||||
|
@ -53,7 +56,8 @@ impl GlobalScope {
|
||||||
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
||||||
mem_profiler_chan: mem::ProfilerChan,
|
mem_profiler_chan: mem::ProfilerChan,
|
||||||
time_profiler_chan: time::ProfilerChan,
|
time_profiler_chan: time::ProfilerChan,
|
||||||
constellation_chan: IpcSender<ConstellationMsg>)
|
constellation_chan: IpcSender<ConstellationMsg>,
|
||||||
|
scheduler_chan: IpcSender<TimerEventRequest>)
|
||||||
-> Self {
|
-> Self {
|
||||||
GlobalScope {
|
GlobalScope {
|
||||||
eventtarget: EventTarget::new_inherited(),
|
eventtarget: EventTarget::new_inherited(),
|
||||||
|
@ -65,6 +69,7 @@ impl GlobalScope {
|
||||||
mem_profiler_chan: mem_profiler_chan,
|
mem_profiler_chan: mem_profiler_chan,
|
||||||
time_profiler_chan: time_profiler_chan,
|
time_profiler_chan: time_profiler_chan,
|
||||||
constellation_chan: constellation_chan,
|
constellation_chan: constellation_chan,
|
||||||
|
scheduler_chan: scheduler_chan,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,6 +145,10 @@ impl GlobalScope {
|
||||||
pub fn constellation_chan(&self) -> &IpcSender<ConstellationMsg> {
|
pub fn constellation_chan(&self) -> &IpcSender<ConstellationMsg> {
|
||||||
&self.constellation_chan
|
&self.constellation_chan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn scheduler_chan(&self) -> &IpcSender<TimerEventRequest> {
|
||||||
|
&self.scheduler_chan
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn timestamp_in_ms(time: Timespec) -> u64 {
|
fn timestamp_in_ms(time: Timespec) -> u64 {
|
||||||
|
|
|
@ -170,8 +170,6 @@ pub struct Window {
|
||||||
session_storage: MutNullableHeap<JS<Storage>>,
|
session_storage: MutNullableHeap<JS<Storage>>,
|
||||||
local_storage: MutNullableHeap<JS<Storage>>,
|
local_storage: MutNullableHeap<JS<Storage>>,
|
||||||
status: DOMRefCell<DOMString>,
|
status: DOMRefCell<DOMString>,
|
||||||
#[ignore_heap_size_of = "channels are hard"]
|
|
||||||
scheduler_chan: IpcSender<TimerEventRequest>,
|
|
||||||
timers: OneshotTimers,
|
timers: OneshotTimers,
|
||||||
|
|
||||||
/// For sending timeline markers. Will be ignored if
|
/// For sending timeline markers. Will be ignored if
|
||||||
|
@ -1387,10 +1385,6 @@ impl Window {
|
||||||
&self.layout_chan
|
&self.layout_chan
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scheduler_chan(&self) -> &IpcSender<TimerEventRequest> {
|
|
||||||
&self.scheduler_chan
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn schedule_callback(&self, callback: OneshotTimerCallback, duration: MsDuration) -> OneshotTimerHandle {
|
pub fn schedule_callback(&self, callback: OneshotTimerCallback, duration: MsDuration) -> OneshotTimerHandle {
|
||||||
self.timers.schedule_callback(callback,
|
self.timers.schedule_callback(callback,
|
||||||
duration,
|
duration,
|
||||||
|
@ -1594,7 +1588,11 @@ impl Window {
|
||||||
let win = box Window {
|
let win = box Window {
|
||||||
globalscope:
|
globalscope:
|
||||||
GlobalScope::new_inherited(
|
GlobalScope::new_inherited(
|
||||||
devtools_chan, mem_profiler_chan, time_profiler_chan, constellation_chan),
|
devtools_chan,
|
||||||
|
mem_profiler_chan,
|
||||||
|
time_profiler_chan,
|
||||||
|
constellation_chan,
|
||||||
|
scheduler_chan.clone()),
|
||||||
script_chan: script_chan,
|
script_chan: script_chan,
|
||||||
dom_manipulation_task_source: dom_task_source,
|
dom_manipulation_task_source: dom_task_source,
|
||||||
user_interaction_task_source: user_task_source,
|
user_interaction_task_source: user_task_source,
|
||||||
|
@ -1613,7 +1611,6 @@ impl Window {
|
||||||
session_storage: Default::default(),
|
session_storage: Default::default(),
|
||||||
local_storage: Default::default(),
|
local_storage: Default::default(),
|
||||||
status: DOMRefCell::new(DOMString::new()),
|
status: DOMRefCell::new(DOMString::new()),
|
||||||
scheduler_chan: scheduler_chan.clone(),
|
|
||||||
timers: OneshotTimers::new(timer_event_chan, scheduler_chan),
|
timers: OneshotTimers::new(timer_event_chan, scheduler_chan),
|
||||||
id: id,
|
id: id,
|
||||||
parent_info: parent_info,
|
parent_info: parent_info,
|
||||||
|
|
|
@ -38,7 +38,7 @@ use net_traits::{LoadContext, ResourceThreads, load_whole_resource};
|
||||||
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, maybe_take_panic_result};
|
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, maybe_take_panic_result};
|
||||||
use script_runtime::{ScriptThreadEventCategory, PromiseJobQueue, EnqueuedPromiseCallback};
|
use script_runtime::{ScriptThreadEventCategory, PromiseJobQueue, EnqueuedPromiseCallback};
|
||||||
use script_thread::{Runnable, RunnableWrapper};
|
use script_thread::{Runnable, RunnableWrapper};
|
||||||
use script_traits::{MsDuration, TimerEvent, TimerEventId, TimerEventRequest, TimerSource};
|
use script_traits::{MsDuration, TimerEvent, TimerEventId, TimerSource};
|
||||||
use script_traits::WorkerGlobalScopeInit;
|
use script_traits::WorkerGlobalScopeInit;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
@ -59,6 +59,7 @@ pub fn prepare_workerscope_init(global: GlobalRef,
|
||||||
let mem_profiler_chan = global_scope.mem_profiler_chan().clone();
|
let mem_profiler_chan = global_scope.mem_profiler_chan().clone();
|
||||||
let time_profiler_chan = global_scope.time_profiler_chan().clone();
|
let time_profiler_chan = global_scope.time_profiler_chan().clone();
|
||||||
let constellation_chan = global_scope.constellation_chan().clone();
|
let constellation_chan = global_scope.constellation_chan().clone();
|
||||||
|
let scheduler_chan = global_scope.scheduler_chan().clone();
|
||||||
let init = WorkerGlobalScopeInit {
|
let init = WorkerGlobalScopeInit {
|
||||||
resource_threads: global.resource_threads(),
|
resource_threads: global.resource_threads(),
|
||||||
mem_profiler_chan: mem_profiler_chan,
|
mem_profiler_chan: mem_profiler_chan,
|
||||||
|
@ -66,7 +67,7 @@ pub fn prepare_workerscope_init(global: GlobalRef,
|
||||||
time_profiler_chan: time_profiler_chan,
|
time_profiler_chan: time_profiler_chan,
|
||||||
from_devtools_sender: devtools_sender,
|
from_devtools_sender: devtools_sender,
|
||||||
constellation_chan: constellation_chan,
|
constellation_chan: constellation_chan,
|
||||||
scheduler_chan: global.scheduler_chan().clone(),
|
scheduler_chan: scheduler_chan,
|
||||||
worker_id: worker_id,
|
worker_id: worker_id,
|
||||||
pipeline_id: global.pipeline_id(),
|
pipeline_id: global.pipeline_id(),
|
||||||
};
|
};
|
||||||
|
@ -102,9 +103,6 @@ pub struct WorkerGlobalScope {
|
||||||
/// `IpcSender` doesn't exist
|
/// `IpcSender` doesn't exist
|
||||||
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
||||||
|
|
||||||
#[ignore_heap_size_of = "Defined in std"]
|
|
||||||
scheduler_chan: IpcSender<TimerEventRequest>,
|
|
||||||
|
|
||||||
promise_job_queue: PromiseJobQueue,
|
promise_job_queue: PromiseJobQueue,
|
||||||
|
|
||||||
/// https://html.spec.whatwg.org/multipage/#in-error-reporting-mode
|
/// https://html.spec.whatwg.org/multipage/#in-error-reporting-mode
|
||||||
|
@ -125,7 +123,8 @@ impl WorkerGlobalScope {
|
||||||
init.to_devtools_sender,
|
init.to_devtools_sender,
|
||||||
init.mem_profiler_chan,
|
init.mem_profiler_chan,
|
||||||
init.time_profiler_chan,
|
init.time_profiler_chan,
|
||||||
init.constellation_chan),
|
init.constellation_chan,
|
||||||
|
init.scheduler_chan.clone()),
|
||||||
worker_id: init.worker_id,
|
worker_id: init.worker_id,
|
||||||
pipeline_id: init.pipeline_id,
|
pipeline_id: init.pipeline_id,
|
||||||
worker_url: worker_url,
|
worker_url: worker_url,
|
||||||
|
@ -134,10 +133,9 @@ impl WorkerGlobalScope {
|
||||||
resource_threads: init.resource_threads,
|
resource_threads: init.resource_threads,
|
||||||
location: Default::default(),
|
location: Default::default(),
|
||||||
navigator: Default::default(),
|
navigator: Default::default(),
|
||||||
timers: OneshotTimers::new(timer_event_chan, init.scheduler_chan.clone()),
|
timers: OneshotTimers::new(timer_event_chan, init.scheduler_chan),
|
||||||
from_devtools_sender: init.from_devtools_sender,
|
from_devtools_sender: init.from_devtools_sender,
|
||||||
from_devtools_receiver: from_devtools_receiver,
|
from_devtools_receiver: from_devtools_receiver,
|
||||||
scheduler_chan: init.scheduler_chan,
|
|
||||||
promise_job_queue: PromiseJobQueue::new(),
|
promise_job_queue: PromiseJobQueue::new(),
|
||||||
in_error_reporting_mode: Default::default(),
|
in_error_reporting_mode: Default::default(),
|
||||||
}
|
}
|
||||||
|
@ -151,10 +149,6 @@ impl WorkerGlobalScope {
|
||||||
&self.from_devtools_receiver
|
&self.from_devtools_receiver
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scheduler_chan(&self) -> &IpcSender<TimerEventRequest> {
|
|
||||||
&self.scheduler_chan
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn schedule_callback(&self, callback: OneshotTimerCallback, duration: MsDuration) -> OneshotTimerHandle {
|
pub fn schedule_callback(&self, callback: OneshotTimerCallback, duration: MsDuration) -> OneshotTimerHandle {
|
||||||
self.timers.schedule_callback(callback,
|
self.timers.schedule_callback(callback,
|
||||||
duration,
|
duration,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue