From b2eda71952f32c0e486c72ed881f472e59ad37c0 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Sat, 4 Jan 2025 09:41:50 +0100 Subject: 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 --- components/script/dom/webgpu/gpu.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'components/script/dom/webgpu/gpu.rs') diff --git a/components/script/dom/webgpu/gpu.rs b/components/script/dom/webgpu/gpu.rs index ba4ce6be221..8b1a2dd46a8 100644 --- a/components/script/dom/webgpu/gpu.rs +++ b/components/script/dom/webgpu/gpu.rs @@ -25,7 +25,6 @@ use crate::dom::promise::Promise; use crate::dom::webgpu::gpuadapter::GPUAdapter; use crate::realms::InRealm; use crate::script_runtime::CanGc; -use crate::task_source::TaskSourceName; #[dom_struct] #[allow(clippy::upper_case_acronyms)] @@ -73,9 +72,6 @@ pub fn response_async( .global() .task_manager() .dom_manipulation_task_source(); - let canceller = receiver - .global() - .task_canceller(TaskSourceName::DOMManipulation); let mut trusted: Option = Some(TrustedPromise::new(promise.clone())); let trusted_receiver = Trusted::new(receiver); ROUTER.add_typed_route( @@ -92,12 +88,9 @@ pub fn response_async( trusted, receiver: trusted_receiver.clone(), }; - let result = task_source.queue_with_canceller( - task!(process_webgpu_task: move|| { - context.response(message.unwrap(), CanGc::note()); - }), - &canceller, - ); + let result = task_source.queue(task!(process_webgpu_task: move|| { + context.response(message.unwrap(), CanGc::note()); + })); if let Err(err) = result { error!("Failed to queue GPU listener-task: {:?}", err); } -- cgit v1.2.3