mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #21583 - AgustinCB:add-task-source-name, r=jdm
Add task source name Refactor `CommonScriptMsg::Task` to include `TaskSourceName`. Sorry for the delay, between doing this after work and the time I spent trying to ramp up on the project, it took me a bit longer than I expected. Test still don't pass in local, but they fail the same way on master, so I guess it's ok. I may have forgotten something, I refactored mostly the stuff that the compiler complained about. Please let me know if I missed anything. I tried to dump my thought process on the commit messages, so feel free to go commit by commit to understand context. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #21527 - [ ] There are tests for these changes OR - [x] These changes do not require tests because it's mostly refactor, no new behavior added. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21583) <!-- Reviewable:end -->
This commit is contained in:
commit
162826d6a9
18 changed files with 134 additions and 71 deletions
|
@ -33,7 +33,7 @@ use js::rust::HandleValue;
|
||||||
use msg::constellation_msg::TopLevelBrowsingContextId;
|
use msg::constellation_msg::TopLevelBrowsingContextId;
|
||||||
use net_traits::{IpcSend, load_whole_resource};
|
use net_traits::{IpcSend, load_whole_resource};
|
||||||
use net_traits::request::{CredentialsMode, Destination, RequestInit};
|
use net_traits::request::{CredentialsMode, Destination, RequestInit};
|
||||||
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, ScriptThreadEventCategory, new_rt_and_cx, Runtime};
|
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, new_rt_and_cx, Runtime};
|
||||||
use script_runtime::ScriptThreadEventCategory::WorkerEvent;
|
use script_runtime::ScriptThreadEventCategory::WorkerEvent;
|
||||||
use script_traits::{TimerEvent, TimerSource, WorkerGlobalScopeInit, WorkerScriptLoadOrigin};
|
use script_traits::{TimerEvent, TimerSource, WorkerGlobalScopeInit, WorkerScriptLoadOrigin};
|
||||||
use servo_rand::random;
|
use servo_rand::random;
|
||||||
|
@ -45,6 +45,7 @@ use std::sync::mpsc::{Receiver, Sender, channel};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use style::thread_state::{self, ThreadState};
|
use style::thread_state::{self, ThreadState};
|
||||||
use task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue};
|
use task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue};
|
||||||
|
use task_source::TaskSourceName;
|
||||||
|
|
||||||
/// Set the `worker` field of a related DedicatedWorkerGlobalScope object to a particular
|
/// Set the `worker` field of a related DedicatedWorkerGlobalScope object to a particular
|
||||||
/// value for the duration of this object's lifetime. This ensures that the related Worker
|
/// value for the duration of this object's lifetime. This ensures that the related Worker
|
||||||
|
@ -86,7 +87,7 @@ pub enum MixedMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl QueuedTaskConversion for DedicatedWorkerScriptMsg {
|
impl QueuedTaskConversion for DedicatedWorkerScriptMsg {
|
||||||
fn task_category(&self) -> Option<&ScriptThreadEventCategory> {
|
fn task_source_name(&self) -> Option<&TaskSourceName> {
|
||||||
let common_worker_msg = match self {
|
let common_worker_msg = match self {
|
||||||
DedicatedWorkerScriptMsg::CommonWorker(_, common_worker_msg) => common_worker_msg,
|
DedicatedWorkerScriptMsg::CommonWorker(_, common_worker_msg) => common_worker_msg,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
|
@ -95,11 +96,10 @@ impl QueuedTaskConversion for DedicatedWorkerScriptMsg {
|
||||||
WorkerScriptMsg::Common(ref script_msg) => script_msg,
|
WorkerScriptMsg::Common(ref script_msg) => script_msg,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
let category = match script_msg {
|
match script_msg {
|
||||||
CommonScriptMsg::Task(category, _boxed, _pipeline_id) => category,
|
CommonScriptMsg::Task(_category, _boxed, _pipeline_id, source_name) => Some(&source_name),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
}
|
||||||
Some(category)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_queued_task(self) -> Option<QueuedTask> {
|
fn into_queued_task(self) -> Option<QueuedTask> {
|
||||||
|
@ -111,17 +111,22 @@ impl QueuedTaskConversion for DedicatedWorkerScriptMsg {
|
||||||
WorkerScriptMsg::Common(script_msg) => script_msg,
|
WorkerScriptMsg::Common(script_msg) => script_msg,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
let (category, boxed, pipeline_id) = match script_msg {
|
let (category, boxed, pipeline_id, task_source) = match script_msg {
|
||||||
CommonScriptMsg::Task(category, boxed, pipeline_id) =>
|
CommonScriptMsg::Task(category, boxed, pipeline_id, task_source) =>
|
||||||
(category, boxed, pipeline_id),
|
(category, boxed, pipeline_id, task_source),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
Some((Some(worker), category, boxed, pipeline_id))
|
Some((Some(worker), category, boxed, pipeline_id, task_source))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_queued_task(queued_task: QueuedTask) -> Self {
|
fn from_queued_task(queued_task: QueuedTask) -> Self {
|
||||||
let (worker, category, boxed, pipeline_id) = queued_task;
|
let (worker, category, boxed, pipeline_id, task_source) = queued_task;
|
||||||
let script_msg = CommonScriptMsg::Task(category, boxed, pipeline_id);
|
let script_msg = CommonScriptMsg::Task(
|
||||||
|
category,
|
||||||
|
boxed,
|
||||||
|
pipeline_id,
|
||||||
|
task_source
|
||||||
|
);
|
||||||
DedicatedWorkerScriptMsg::CommonWorker(worker.unwrap(), WorkerScriptMsg::Common(script_msg))
|
DedicatedWorkerScriptMsg::CommonWorker(worker.unwrap(), WorkerScriptMsg::Common(script_msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,7 +300,8 @@ impl DedicatedWorkerGlobalScope {
|
||||||
parent_sender.send(CommonScriptMsg::Task(
|
parent_sender.send(CommonScriptMsg::Task(
|
||||||
WorkerEvent,
|
WorkerEvent,
|
||||||
Box::new(SimpleWorkerErrorHandler::new(worker)),
|
Box::new(SimpleWorkerErrorHandler::new(worker)),
|
||||||
pipeline_id
|
pipeline_id,
|
||||||
|
TaskSourceName::DOMManipulation,
|
||||||
)).unwrap();
|
)).unwrap();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -446,8 +452,12 @@ impl DedicatedWorkerGlobalScope {
|
||||||
global.report_an_error(error_info, HandleValue::null());
|
global.report_an_error(error_info, HandleValue::null());
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
// TODO: Should use the DOM manipulation task source.
|
self.parent_sender.send(CommonScriptMsg::Task(
|
||||||
self.parent_sender.send(CommonScriptMsg::Task(WorkerEvent, task, Some(pipeline_id))).unwrap();
|
WorkerEvent,
|
||||||
|
task,
|
||||||
|
Some(pipeline_id),
|
||||||
|
TaskSourceName::DOMManipulation,
|
||||||
|
)).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,7 +482,13 @@ impl DedicatedWorkerGlobalScopeMethods for DedicatedWorkerGlobalScope {
|
||||||
let task = Box::new(task!(post_worker_message: move || {
|
let task = Box::new(task!(post_worker_message: move || {
|
||||||
Worker::handle_message(worker, data);
|
Worker::handle_message(worker, data);
|
||||||
}));
|
}));
|
||||||
self.parent_sender.send(CommonScriptMsg::Task(WorkerEvent, task, Some(pipeline_id))).unwrap();
|
// TODO: Change this task source to a new `unshipped-port-message-queue` task source
|
||||||
|
self.parent_sender.send(CommonScriptMsg::Task(
|
||||||
|
WorkerEvent,
|
||||||
|
task,
|
||||||
|
Some(pipeline_id),
|
||||||
|
TaskSourceName::DOMManipulation,
|
||||||
|
)).unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2837,7 +2837,14 @@ impl Document {
|
||||||
let trusted_pending = Trusted::new(pending);
|
let trusted_pending = Trusted::new(pending);
|
||||||
let trusted_promise = TrustedPromise::new(promise.clone());
|
let trusted_promise = TrustedPromise::new(promise.clone());
|
||||||
let handler = ElementPerformFullscreenEnter::new(trusted_pending, trusted_promise, error);
|
let handler = ElementPerformFullscreenEnter::new(trusted_pending, trusted_promise, error);
|
||||||
let script_msg = CommonScriptMsg::Task(ScriptThreadEventCategory::EnterFullscreen, handler, pipeline_id);
|
// NOTE: This steps should be running in parallel
|
||||||
|
// https://fullscreen.spec.whatwg.org/#dom-element-requestfullscreen
|
||||||
|
let script_msg = CommonScriptMsg::Task(
|
||||||
|
ScriptThreadEventCategory::EnterFullscreen,
|
||||||
|
handler,
|
||||||
|
pipeline_id,
|
||||||
|
TaskSourceName::DOMManipulation,
|
||||||
|
);
|
||||||
let msg = MainThreadScriptMsg::Common(script_msg);
|
let msg = MainThreadScriptMsg::Common(script_msg);
|
||||||
window.main_thread_script_chan().send(msg).unwrap();
|
window.main_thread_script_chan().send(msg).unwrap();
|
||||||
|
|
||||||
|
@ -2870,7 +2877,14 @@ impl Document {
|
||||||
let trusted_promise = TrustedPromise::new(promise.clone());
|
let trusted_promise = TrustedPromise::new(promise.clone());
|
||||||
let handler = ElementPerformFullscreenExit::new(trusted_element, trusted_promise);
|
let handler = ElementPerformFullscreenExit::new(trusted_element, trusted_promise);
|
||||||
let pipeline_id = Some(global.pipeline_id());
|
let pipeline_id = Some(global.pipeline_id());
|
||||||
let script_msg = CommonScriptMsg::Task(ScriptThreadEventCategory::ExitFullscreen, handler, pipeline_id);
|
// NOTE: This steps should be running in parallel
|
||||||
|
// https://fullscreen.spec.whatwg.org/#exit-fullscreen
|
||||||
|
let script_msg = CommonScriptMsg::Task(
|
||||||
|
ScriptThreadEventCategory::ExitFullscreen,
|
||||||
|
handler,
|
||||||
|
pipeline_id,
|
||||||
|
TaskSourceName::DOMManipulation,
|
||||||
|
);
|
||||||
let msg = MainThreadScriptMsg::Common(script_msg);
|
let msg = MainThreadScriptMsg::Common(script_msg);
|
||||||
window.main_thread_script_chan().send(msg).unwrap();
|
window.main_thread_script_chan().send(msg).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ use js::jsapi::{JSAutoCompartment, JSContext, JS_AddInterruptCallback};
|
||||||
use js::jsval::UndefinedValue;
|
use js::jsval::UndefinedValue;
|
||||||
use net_traits::{load_whole_resource, IpcSend, CustomResponseMediator};
|
use net_traits::{load_whole_resource, IpcSend, CustomResponseMediator};
|
||||||
use net_traits::request::{CredentialsMode, Destination, RequestInit};
|
use net_traits::request::{CredentialsMode, Destination, RequestInit};
|
||||||
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory, new_rt_and_cx, Runtime};
|
use script_runtime::{CommonScriptMsg, ScriptChan, new_rt_and_cx, Runtime};
|
||||||
use script_traits::{TimerEvent, WorkerGlobalScopeInit, ScopeThings, ServiceWorkerMsg, WorkerScriptLoadOrigin};
|
use script_traits::{TimerEvent, WorkerGlobalScopeInit, ScopeThings, ServiceWorkerMsg, WorkerScriptLoadOrigin};
|
||||||
use servo_config::prefs::PREFS;
|
use servo_config::prefs::PREFS;
|
||||||
use servo_rand::random;
|
use servo_rand::random;
|
||||||
|
@ -37,6 +37,7 @@ use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use style::thread_state::{self, ThreadState};
|
use style::thread_state::{self, ThreadState};
|
||||||
use task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue};
|
use task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue};
|
||||||
|
use task_source::TaskSourceName;
|
||||||
|
|
||||||
/// Messages used to control service worker event loop
|
/// Messages used to control service worker event loop
|
||||||
pub enum ServiceWorkerScriptMsg {
|
pub enum ServiceWorkerScriptMsg {
|
||||||
|
@ -49,16 +50,15 @@ pub enum ServiceWorkerScriptMsg {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl QueuedTaskConversion for ServiceWorkerScriptMsg {
|
impl QueuedTaskConversion for ServiceWorkerScriptMsg {
|
||||||
fn task_category(&self) -> Option<&ScriptThreadEventCategory> {
|
fn task_source_name(&self) -> Option<&TaskSourceName> {
|
||||||
let script_msg = match self {
|
let script_msg = match self {
|
||||||
ServiceWorkerScriptMsg::CommonWorker(WorkerScriptMsg::Common(script_msg)) => script_msg,
|
ServiceWorkerScriptMsg::CommonWorker(WorkerScriptMsg::Common(script_msg)) => script_msg,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
let category = match script_msg {
|
match script_msg {
|
||||||
CommonScriptMsg::Task(category, _boxed, _pipeline_id) => category,
|
CommonScriptMsg::Task(_category, _boxed, _pipeline_id, task_source) => Some(&task_source),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
}
|
||||||
Some(&category)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_queued_task(self) -> Option<QueuedTask> {
|
fn into_queued_task(self) -> Option<QueuedTask> {
|
||||||
|
@ -66,17 +66,17 @@ impl QueuedTaskConversion for ServiceWorkerScriptMsg {
|
||||||
ServiceWorkerScriptMsg::CommonWorker(WorkerScriptMsg::Common(script_msg)) => script_msg,
|
ServiceWorkerScriptMsg::CommonWorker(WorkerScriptMsg::Common(script_msg)) => script_msg,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
let (category, boxed, pipeline_id) = match script_msg {
|
let (category, boxed, pipeline_id, task_source) = match script_msg {
|
||||||
CommonScriptMsg::Task(category, boxed, pipeline_id) =>
|
CommonScriptMsg::Task(category, boxed, pipeline_id, task_source) =>
|
||||||
(category, boxed, pipeline_id),
|
(category, boxed, pipeline_id, task_source),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
Some((None, category, boxed, pipeline_id))
|
Some((None, category, boxed, pipeline_id, task_source))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_queued_task(queued_task: QueuedTask) -> Self {
|
fn from_queued_task(queued_task: QueuedTask) -> Self {
|
||||||
let (_worker, category, boxed, pipeline_id) = queued_task;
|
let (_worker, category, boxed, pipeline_id, task_source) = queued_task;
|
||||||
let script_msg = CommonScriptMsg::Task(category, boxed, pipeline_id);
|
let script_msg = CommonScriptMsg::Task(category, boxed, pipeline_id, task_source);
|
||||||
ServiceWorkerScriptMsg::CommonWorker(WorkerScriptMsg::Common(script_msg))
|
ServiceWorkerScriptMsg::CommonWorker(WorkerScriptMsg::Common(script_msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ use std::ops::Deref;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
use task_source::TaskSourceName;
|
||||||
use webvr_traits::{WebVRDisplayData, WebVRDisplayEvent, WebVRFrameData, WebVRLayer, WebVRMsg};
|
use webvr_traits::{WebVRDisplayData, WebVRDisplayEvent, WebVRFrameData, WebVRLayer, WebVRMsg};
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
|
@ -517,7 +518,14 @@ impl VRDisplay {
|
||||||
let task = Box::new(task!(handle_vrdisplay_raf: move || {
|
let task = Box::new(task!(handle_vrdisplay_raf: move || {
|
||||||
this.root().handle_raf(&sender);
|
this.root().handle_raf(&sender);
|
||||||
}));
|
}));
|
||||||
js_sender.send(CommonScriptMsg::Task(WebVREvent, task, Some(pipeline_id))).unwrap();
|
// NOTE: WebVR spec doesn't specify what task source we should use. Is
|
||||||
|
// dom-manipulation a good choice long term?
|
||||||
|
js_sender.send(CommonScriptMsg::Task(
|
||||||
|
WebVREvent,
|
||||||
|
task,
|
||||||
|
Some(pipeline_id),
|
||||||
|
TaskSourceName::DOMManipulation,
|
||||||
|
)).unwrap();
|
||||||
|
|
||||||
// Run Sync Poses in parallell on Render thread
|
// Run Sync Poses in parallell on Render thread
|
||||||
let msg = WebVRCommand::SyncPoses(display_id, near, far, sync_sender.clone());
|
let msg = WebVRCommand::SyncPoses(display_id, near, far, sync_sender.clone());
|
||||||
|
|
|
@ -268,7 +268,13 @@ impl WebSocket {
|
||||||
let pipeline_id = self.global().pipeline_id();
|
let pipeline_id = self.global().pipeline_id();
|
||||||
self.global()
|
self.global()
|
||||||
.script_chan()
|
.script_chan()
|
||||||
.send(CommonScriptMsg::Task(WebSocketEvent, task, Some(pipeline_id)))
|
// TODO: Use a dedicated `websocket-task-source` task source instead.
|
||||||
|
.send(CommonScriptMsg::Task(
|
||||||
|
WebSocketEvent,
|
||||||
|
task,
|
||||||
|
Some(pipeline_id),
|
||||||
|
TaskSourceName::Networking,
|
||||||
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1667,7 +1667,8 @@ impl Window {
|
||||||
let _ = self.script_chan.send(CommonScriptMsg::Task(
|
let _ = self.script_chan.send(CommonScriptMsg::Task(
|
||||||
ScriptThreadEventCategory::DomEvent,
|
ScriptThreadEventCategory::DomEvent,
|
||||||
Box::new(self.task_canceller(TaskSourceName::DOMManipulation).wrap_task(task)),
|
Box::new(self.task_canceller(TaskSourceName::DOMManipulation).wrap_task(task)),
|
||||||
self.pipeline_id()
|
self.pipeline_id(),
|
||||||
|
TaskSourceName::DOMManipulation,
|
||||||
));
|
));
|
||||||
doc.set_url(url.clone());
|
doc.set_url(url.clone());
|
||||||
return
|
return
|
||||||
|
@ -2124,7 +2125,8 @@ impl Window {
|
||||||
let _ = self.script_chan.send(CommonScriptMsg::Task(
|
let _ = self.script_chan.send(CommonScriptMsg::Task(
|
||||||
ScriptThreadEventCategory::DomEvent,
|
ScriptThreadEventCategory::DomEvent,
|
||||||
Box::new(self.task_canceller(TaskSourceName::DOMManipulation).wrap_task(task)),
|
Box::new(self.task_canceller(TaskSourceName::DOMManipulation).wrap_task(task)),
|
||||||
self.pipeline_id()
|
self.pipeline_id(),
|
||||||
|
TaskSourceName::DOMManipulation,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -397,7 +397,7 @@ impl WorkerGlobalScope {
|
||||||
|
|
||||||
pub fn process_event(&self, msg: CommonScriptMsg) {
|
pub fn process_event(&self, msg: CommonScriptMsg) {
|
||||||
match msg {
|
match msg {
|
||||||
CommonScriptMsg::Task(_, task, _) => {
|
CommonScriptMsg::Task(_, task, _, _) => {
|
||||||
task.run_box()
|
task.run_box()
|
||||||
},
|
},
|
||||||
CommonScriptMsg::CollectReports(reports_chan) => {
|
CommonScriptMsg::CollectReports(reports_chan) => {
|
||||||
|
|
|
@ -66,6 +66,7 @@ use style::thread_state::{self, ThreadState};
|
||||||
use swapper::Swapper;
|
use swapper::Swapper;
|
||||||
use swapper::swapper;
|
use swapper::swapper;
|
||||||
use task::TaskBox;
|
use task::TaskBox;
|
||||||
|
use task_source::TaskSourceName;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
// Magic numbers
|
// Magic numbers
|
||||||
|
@ -644,7 +645,14 @@ impl WorkletThread {
|
||||||
where
|
where
|
||||||
T: TaskBox + 'static,
|
T: TaskBox + 'static,
|
||||||
{
|
{
|
||||||
let msg = CommonScriptMsg::Task(ScriptThreadEventCategory::WorkletEvent, Box::new(task), None);
|
// NOTE: It's unclear which task source should be used here:
|
||||||
|
// https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule
|
||||||
|
let msg = CommonScriptMsg::Task(
|
||||||
|
ScriptThreadEventCategory::WorkletEvent,
|
||||||
|
Box::new(task),
|
||||||
|
None,
|
||||||
|
TaskSourceName::DOMManipulation,
|
||||||
|
);
|
||||||
let msg = MainThreadScriptMsg::Common(msg);
|
let msg = MainThreadScriptMsg::Common(msg);
|
||||||
self.global_init.to_script_thread_sender.send(msg).expect("Worklet thread outlived script thread.");
|
self.global_init.to_script_thread_sender.send(msg).expect("Worklet thread outlived script thread.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ use std::panic::AssertUnwindSafe;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use style::thread_state::{self, ThreadState};
|
use style::thread_state::{self, ThreadState};
|
||||||
use task::TaskBox;
|
use task::TaskBox;
|
||||||
|
use task_source::TaskSourceName;
|
||||||
use time::{Tm, now};
|
use time::{Tm, now};
|
||||||
|
|
||||||
/// Common messages used to control the event loops in both the script and the worker
|
/// Common messages used to control the event loops in both the script and the worker
|
||||||
|
@ -51,14 +52,14 @@ pub enum CommonScriptMsg {
|
||||||
/// supplied channel.
|
/// supplied channel.
|
||||||
CollectReports(ReportsChan),
|
CollectReports(ReportsChan),
|
||||||
/// Generic message that encapsulates event handling.
|
/// Generic message that encapsulates event handling.
|
||||||
Task(ScriptThreadEventCategory, Box<TaskBox>, Option<PipelineId>),
|
Task(ScriptThreadEventCategory, Box<TaskBox>, Option<PipelineId>, TaskSourceName),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for CommonScriptMsg {
|
impl fmt::Debug for CommonScriptMsg {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
CommonScriptMsg::CollectReports(_) => write!(f, "CollectReports(...)"),
|
CommonScriptMsg::CollectReports(_) => write!(f, "CollectReports(...)"),
|
||||||
CommonScriptMsg::Task(ref category, ref task, _) => {
|
CommonScriptMsg::Task(ref category, ref task, _, _) => {
|
||||||
f.debug_tuple("Task").field(category).field(task).finish()
|
f.debug_tuple("Task").field(category).field(task).finish()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,6 +117,7 @@ use std::sync::mpsc::{Receiver, Select, Sender, channel};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use style::thread_state::{self, ThreadState};
|
use style::thread_state::{self, ThreadState};
|
||||||
use task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue};
|
use task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue};
|
||||||
|
use task_source::TaskSourceName;
|
||||||
use task_source::dom_manipulation::DOMManipulationTaskSource;
|
use task_source::dom_manipulation::DOMManipulationTaskSource;
|
||||||
use task_source::file_reading::FileReadingTaskSource;
|
use task_source::file_reading::FileReadingTaskSource;
|
||||||
use task_source::history_traversal::HistoryTraversalTaskSource;
|
use task_source::history_traversal::HistoryTraversalTaskSource;
|
||||||
|
@ -248,16 +249,15 @@ pub enum MainThreadScriptMsg {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl QueuedTaskConversion for MainThreadScriptMsg {
|
impl QueuedTaskConversion for MainThreadScriptMsg {
|
||||||
fn task_category(&self) -> Option<&ScriptThreadEventCategory> {
|
fn task_source_name(&self) -> Option<&TaskSourceName> {
|
||||||
let script_msg = match self {
|
let script_msg = match self {
|
||||||
MainThreadScriptMsg::Common(script_msg) => script_msg,
|
MainThreadScriptMsg::Common(script_msg) => script_msg,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
let category = match script_msg {
|
match script_msg {
|
||||||
CommonScriptMsg::Task(category, _boxed, _pipeline_id) => category,
|
CommonScriptMsg::Task(_category, _boxed, _pipeline_id, task_source) => Some(&task_source),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
}
|
||||||
Some(&category)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_queued_task(self) -> Option<QueuedTask> {
|
fn into_queued_task(self) -> Option<QueuedTask> {
|
||||||
|
@ -265,17 +265,17 @@ impl QueuedTaskConversion for MainThreadScriptMsg {
|
||||||
MainThreadScriptMsg::Common(script_msg) => script_msg,
|
MainThreadScriptMsg::Common(script_msg) => script_msg,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
let (category, boxed, pipeline_id) = match script_msg {
|
let (category, boxed, pipeline_id, task_source) = match script_msg {
|
||||||
CommonScriptMsg::Task(category, boxed, pipeline_id) =>
|
CommonScriptMsg::Task(category, boxed, pipeline_id, task_source) =>
|
||||||
(category, boxed, pipeline_id),
|
(category, boxed, pipeline_id, task_source),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
Some((None, category, boxed, pipeline_id))
|
Some((None, category, boxed, pipeline_id, task_source))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_queued_task(queued_task: QueuedTask) -> Self {
|
fn from_queued_task(queued_task: QueuedTask) -> Self {
|
||||||
let (_worker, category, boxed, pipeline_id) = queued_task;
|
let (_worker, category, boxed, pipeline_id, task_source) = queued_task;
|
||||||
let script_msg = CommonScriptMsg::Task(category, boxed, pipeline_id);
|
let script_msg = CommonScriptMsg::Task(category, boxed, pipeline_id, task_source);
|
||||||
MainThreadScriptMsg::Common(script_msg)
|
MainThreadScriptMsg::Common(script_msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1279,7 +1279,7 @@ impl ScriptThread {
|
||||||
MixedMessage::FromDevtools(_) => None,
|
MixedMessage::FromDevtools(_) => None,
|
||||||
MixedMessage::FromScript(ref inner_msg) => {
|
MixedMessage::FromScript(ref inner_msg) => {
|
||||||
match *inner_msg {
|
match *inner_msg {
|
||||||
MainThreadScriptMsg::Common(CommonScriptMsg::Task(_, _, pipeline_id)) =>
|
MainThreadScriptMsg::Common(CommonScriptMsg::Task(_, _, pipeline_id, _)) =>
|
||||||
pipeline_id,
|
pipeline_id,
|
||||||
MainThreadScriptMsg::Common(CommonScriptMsg::CollectReports(_)) => None,
|
MainThreadScriptMsg::Common(CommonScriptMsg::CollectReports(_)) => None,
|
||||||
MainThreadScriptMsg::Navigate(pipeline_id, ..) => Some(pipeline_id),
|
MainThreadScriptMsg::Navigate(pipeline_id, ..) => Some(pipeline_id),
|
||||||
|
@ -1433,7 +1433,7 @@ impl ScriptThread {
|
||||||
MainThreadScriptMsg::Navigate(parent_pipeline_id, load_data, replace) => {
|
MainThreadScriptMsg::Navigate(parent_pipeline_id, load_data, replace) => {
|
||||||
self.handle_navigate(parent_pipeline_id, None, load_data, replace)
|
self.handle_navigate(parent_pipeline_id, None, load_data, replace)
|
||||||
},
|
},
|
||||||
MainThreadScriptMsg::Common(CommonScriptMsg::Task(_, task, _)) => {
|
MainThreadScriptMsg::Common(CommonScriptMsg::Task(_, task, _, _)) => {
|
||||||
task.run_box()
|
task.run_box()
|
||||||
}
|
}
|
||||||
MainThreadScriptMsg::Common(CommonScriptMsg::CollectReports(chan)) => {
|
MainThreadScriptMsg::Common(CommonScriptMsg::CollectReports(chan)) => {
|
||||||
|
|
|
@ -16,11 +16,17 @@ use task::TaskBox;
|
||||||
use task_source::TaskSourceName;
|
use task_source::TaskSourceName;
|
||||||
|
|
||||||
|
|
||||||
pub type QueuedTask = (Option<TrustedWorkerAddress>, ScriptThreadEventCategory, Box<TaskBox>, Option<PipelineId>);
|
pub type QueuedTask = (
|
||||||
|
Option<TrustedWorkerAddress>,
|
||||||
|
ScriptThreadEventCategory,
|
||||||
|
Box<TaskBox>,
|
||||||
|
Option<PipelineId>,
|
||||||
|
TaskSourceName
|
||||||
|
);
|
||||||
|
|
||||||
/// Defining the operations used to convert from a msg T to a QueuedTask.
|
/// Defining the operations used to convert from a msg T to a QueuedTask.
|
||||||
pub trait QueuedTaskConversion {
|
pub trait QueuedTaskConversion {
|
||||||
fn task_category(&self) -> Option<&ScriptThreadEventCategory>;
|
fn task_source_name(&self) -> Option<&TaskSourceName>;
|
||||||
fn into_queued_task(self) -> Option<QueuedTask>;
|
fn into_queued_task(self) -> Option<QueuedTask>;
|
||||||
fn from_queued_task(queued_task: QueuedTask) -> Self;
|
fn from_queued_task(queued_task: QueuedTask) -> Self;
|
||||||
fn wake_up_msg() -> Self;
|
fn wake_up_msg() -> Self;
|
||||||
|
@ -60,12 +66,12 @@ impl<T: QueuedTaskConversion> TaskQueue<T> {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let to_be_throttled: Vec<T> = non_throttled.drain_filter(|msg|{
|
let to_be_throttled: Vec<T> = non_throttled.drain_filter(|msg|{
|
||||||
let category = match msg.task_category() {
|
let task_source = match msg.task_source_name() {
|
||||||
Some(category) => category,
|
Some(task_source) => task_source,
|
||||||
None => return false,
|
None => return false,
|
||||||
};
|
};
|
||||||
match category {
|
match task_source {
|
||||||
ScriptThreadEventCategory::PerformanceTimelineTask => return true,
|
TaskSourceName::PerformanceTimeline => return true,
|
||||||
_ => {
|
_ => {
|
||||||
// A task that will not be throttled, start counting "business"
|
// A task that will not be throttled, start counting "business"
|
||||||
self.taken_task_counter.set(self.taken_task_counter.get() + 1);
|
self.taken_task_counter.set(self.taken_task_counter.get() + 1);
|
||||||
|
@ -81,20 +87,15 @@ impl<T: QueuedTaskConversion> TaskQueue<T> {
|
||||||
|
|
||||||
for msg in to_be_throttled {
|
for msg in to_be_throttled {
|
||||||
// Categorize tasks per task queue.
|
// Categorize tasks per task queue.
|
||||||
let (worker, category, boxed, pipeline_id) = match msg.into_queued_task() {
|
let (worker, category, boxed, pipeline_id, task_source) = match msg.into_queued_task() {
|
||||||
Some((worker, category, boxed, pipeline_id)) => (worker, category, boxed, pipeline_id),
|
Some(queued_task) => queued_task,
|
||||||
None => unreachable!("A message to be throttled should always be convertible into a queued task"),
|
None => unreachable!("A message to be throttled should always be convertible into a queued task"),
|
||||||
};
|
};
|
||||||
// FIXME: Add the task-source name directly to CommonScriptMsg::Task.
|
|
||||||
let task_source = match category {
|
|
||||||
ScriptThreadEventCategory::PerformanceTimelineTask => TaskSourceName::PerformanceTimeline,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
let mut throttled_tasks = self.throttled.borrow_mut();
|
let mut throttled_tasks = self.throttled.borrow_mut();
|
||||||
throttled_tasks
|
throttled_tasks
|
||||||
.entry(task_source)
|
.entry(task_source.clone())
|
||||||
.or_insert(VecDeque::new())
|
.or_insert(VecDeque::new())
|
||||||
.push_back((worker, category, boxed, pipeline_id));
|
.push_back((worker, category, boxed, pipeline_id, task_source));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ impl fmt::Debug for DOMManipulationTaskSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TaskSource for DOMManipulationTaskSource {
|
impl TaskSource for DOMManipulationTaskSource {
|
||||||
const NAME: TaskSourceName = TaskSourceName::DOMManipulation;
|
const NAME: TaskSourceName = TaskSourceName::DOMManipulation;
|
||||||
|
|
||||||
fn queue_with_canceller<T>(
|
fn queue_with_canceller<T>(
|
||||||
&self,
|
&self,
|
||||||
|
@ -40,7 +40,8 @@ impl TaskSource for DOMManipulationTaskSource {
|
||||||
let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task(
|
let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task(
|
||||||
ScriptThreadEventCategory::ScriptEvent,
|
ScriptThreadEventCategory::ScriptEvent,
|
||||||
Box::new(canceller.wrap_task(task)),
|
Box::new(canceller.wrap_task(task)),
|
||||||
Some(self.1)
|
Some(self.1),
|
||||||
|
DOMManipulationTaskSource::NAME,
|
||||||
));
|
));
|
||||||
self.0.send(msg).map_err(|_| ())
|
self.0.send(msg).map_err(|_| ())
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ impl TaskSource for FileReadingTaskSource {
|
||||||
ScriptThreadEventCategory::FileRead,
|
ScriptThreadEventCategory::FileRead,
|
||||||
Box::new(canceller.wrap_task(task)),
|
Box::new(canceller.wrap_task(task)),
|
||||||
Some(self.1),
|
Some(self.1),
|
||||||
|
FileReadingTaskSource::NAME,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ use task::{TaskCanceller, TaskOnce};
|
||||||
// Note: When adding a task source, update this enum.
|
// Note: When adding a task source, update this enum.
|
||||||
// Note: The HistoryTraversalTaskSource is not part of this,
|
// Note: The HistoryTraversalTaskSource is not part of this,
|
||||||
// because it doesn't implement TaskSource.
|
// because it doesn't implement TaskSource.
|
||||||
#[derive(Eq, Hash, IntoEnumIterator, JSTraceable, PartialEq)]
|
#[derive(Clone, Eq, Hash, IntoEnumIterator, JSTraceable, PartialEq)]
|
||||||
pub enum TaskSourceName {
|
pub enum TaskSourceName {
|
||||||
DOMManipulation,
|
DOMManipulation,
|
||||||
FileReading,
|
FileReading,
|
||||||
|
|
|
@ -31,6 +31,7 @@ impl TaskSource for NetworkingTaskSource {
|
||||||
ScriptThreadEventCategory::NetworkEvent,
|
ScriptThreadEventCategory::NetworkEvent,
|
||||||
Box::new(canceller.wrap_task(task)),
|
Box::new(canceller.wrap_task(task)),
|
||||||
Some(self.1),
|
Some(self.1),
|
||||||
|
NetworkingTaskSource::NAME,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +47,7 @@ impl NetworkingTaskSource {
|
||||||
ScriptThreadEventCategory::NetworkEvent,
|
ScriptThreadEventCategory::NetworkEvent,
|
||||||
Box::new(task),
|
Box::new(task),
|
||||||
Some(self.1),
|
Some(self.1),
|
||||||
|
NetworkingTaskSource::NAME,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,8 @@ impl TaskSource for PerformanceTimelineTaskSource {
|
||||||
let msg = CommonScriptMsg::Task(
|
let msg = CommonScriptMsg::Task(
|
||||||
ScriptThreadEventCategory::PerformanceTimelineTask,
|
ScriptThreadEventCategory::PerformanceTimelineTask,
|
||||||
Box::new(canceller.wrap_task(task)),
|
Box::new(canceller.wrap_task(task)),
|
||||||
Some(self.1)
|
Some(self.1),
|
||||||
|
PerformanceTimelineTaskSource::NAME,
|
||||||
);
|
);
|
||||||
self.0.send(msg).map_err(|_| ())
|
self.0.send(msg).map_err(|_| ())
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ impl TaskSource for RemoteEventTaskSource {
|
||||||
ScriptThreadEventCategory::NetworkEvent,
|
ScriptThreadEventCategory::NetworkEvent,
|
||||||
Box::new(canceller.wrap_task(task)),
|
Box::new(canceller.wrap_task(task)),
|
||||||
Some(self.1),
|
Some(self.1),
|
||||||
|
RemoteEventTaskSource::NAME,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,8 @@ impl TaskSource for UserInteractionTaskSource {
|
||||||
let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task(
|
let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task(
|
||||||
ScriptThreadEventCategory::InputEvent,
|
ScriptThreadEventCategory::InputEvent,
|
||||||
Box::new(canceller.wrap_task(task)),
|
Box::new(canceller.wrap_task(task)),
|
||||||
Some(self.1)
|
Some(self.1),
|
||||||
|
UserInteractionTaskSource::NAME,
|
||||||
));
|
));
|
||||||
self.0.send(msg).map_err(|_| ())
|
self.0.send(msg).map_err(|_| ())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue