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>
This commit is contained in:
Martin Robinson 2025-01-04 09:41:50 +01:00 committed by GitHub
parent 75a22cfe2e
commit b2eda71952
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
54 changed files with 1060 additions and 1516 deletions

View file

@ -59,7 +59,6 @@ impl WebGLSync {
) -> Option<u32> {
match self.client_wait_status.get() {
Some(constants::TIMEOUT_EXPIRED) | Some(constants::WAIT_FAILED) | None => {
let global = self.global();
let this = Trusted::new(self);
let context = Trusted::new(context);
let task = task!(request_client_wait_status: move || {
@ -74,11 +73,10 @@ impl WebGLSync {
));
this.client_wait_status.set(Some(receiver.recv().unwrap()));
});
global
.as_window()
self.global()
.task_manager()
.dom_manipulation_task_source()
.queue(task, global.upcast())
.queue(task)
.unwrap();
},
_ => {},
@ -101,7 +99,6 @@ impl WebGLSync {
pub fn get_sync_status(&self, pname: u32, context: &WebGLRenderingContext) -> Option<u32> {
match self.sync_status.get() {
Some(constants::UNSIGNALED) | None => {
let global = self.global();
let this = Trusted::new(self);
let context = Trusted::new(context);
let task = task!(request_sync_status: move || {
@ -111,11 +108,10 @@ impl WebGLSync {
context.send_command(WebGLCommand::GetSyncParameter(this.sync_id, pname, sender));
this.sync_status.set(Some(receiver.recv().unwrap()));
});
global
.as_window()
self.global()
.task_manager()
.dom_manipulation_task_source()
.queue(task, global.upcast())
.queue(task)
.unwrap();
},
_ => {},