aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/script_thread.rs
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2025-01-04 09:41:50 +0100
committerGitHub <noreply@github.com>2025-01-04 08:41:50 +0000
commitb2eda71952f32c0e486c72ed881f472e59ad37c0 (patch)
tree281ac2c157d39859ebf9122d178d9c349f492a87 /components/script/script_thread.rs
parent75a22cfe2eb6c4822d5cda98e84cc88c1e4ce941 (diff)
downloadservo-b2eda71952f32c0e486c72ed881f472e59ad37c0.tar.gz
servo-b2eda71952f32c0e486c72ed881f472e59ad37c0.zip
script: Move `TaskManager` to `GlobalScope` (#34827)
This is a simplification of the internal `TaskQueue` API that moves the `TaskManager` to the `GlobalScope` itself. In addition, the handling of cancellers is moved to the `TaskManager` as well. This means that no arguments other than the `task` are necessary for queueing tasks, which makes the API a lot easier to use and cleaner. `TaskSource` now also keeps a copy of the canceller with it, so that they always know the proper way to cancel any tasks queued on them. There is one complication here. The event loop `sender` for dedicated workers is constantly changing as it is set to `None` when not handling messages. This is because this sender keeps a handle to the main thread's `Worker` object, preventing garbage collection while any messages are still in flight or being handled. This change allows setting the `sender` on the `TaskManager` to `None` to allow proper garbabge collection. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/script/script_thread.rs')
-rw-r--r--components/script/script_thread.rs16
1 files changed, 7 insertions, 9 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index f970d351d35..18f67c5d86c 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -152,7 +152,6 @@ use crate::script_runtime::{
CanGc, CommonScriptMsg, JSContext, Runtime, ScriptChan, ScriptThreadEventCategory,
ThreadSafeJSContext,
};
-use crate::task_manager::TaskManager;
use crate::task_queue::TaskQueue;
use crate::task_source::{TaskSource, TaskSourceName};
use crate::{devtools, webdriver_handlers};
@@ -693,7 +692,7 @@ impl ScriptThread {
global
.task_manager()
.dom_manipulation_task_source()
- .queue(task, global.upcast())
+ .queue(task)
.expect("Enqueing navigate js task on the DOM manipulation task source failed");
} else {
if let Some(ref sender) = script_thread.senders.devtools_server_sender {
@@ -907,6 +906,7 @@ impl ScriptThread {
sender: self_sender.as_boxed(),
pipeline_id: state.id,
name: TaskSourceName::Networking,
+ canceller: Default::default(),
}));
let cx = runtime.cx();
@@ -1033,8 +1033,10 @@ impl ScriptThread {
fn prepare_for_shutdown_inner(&self) {
let docs = self.documents.borrow();
for (_, document) in docs.iter() {
- let window = document.window();
- window.ignore_all_tasks();
+ document
+ .window()
+ .task_manager()
+ .cancel_all_tasks_and_ignore_future_tasks();
}
}
@@ -1407,6 +1409,7 @@ impl ScriptThread {
//
// This task is empty because any new IPC messages in the ScriptThread trigger a
// rendering update when animations are not running.
+ let _realm = enter_realm(&*document);
let rendering_task_source = document.window().task_manager().rendering_task_source();
let _ =
rendering_task_source.queue_unconditionally(task!(update_the_rendering: move || { }));
@@ -3129,10 +3132,6 @@ impl ScriptThread {
pipeline_id: incomplete.pipeline_id,
};
- let task_manager = TaskManager::new(
- Box::new(self.senders.self_sender.clone()),
- incomplete.pipeline_id,
- );
let paint_time_metrics = PaintTimeMetrics::new(
incomplete.pipeline_id,
self.senders.time_profiler_sender.clone(),
@@ -3161,7 +3160,6 @@ impl ScriptThread {
let window = Window::new(
self.js_runtime.clone(),
self.senders.self_sender.clone(),
- task_manager,
self.layout_factory.create(layout_config),
self.senders.image_cache_sender.clone(),
self.image_cache.clone(),