diff options
author | Martin Robinson <mrobinson@igalia.com> | 2025-01-04 09:41:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-04 08:41:50 +0000 |
commit | b2eda71952f32c0e486c72ed881f472e59ad37c0 (patch) | |
tree | 281ac2c157d39859ebf9122d178d9c349f492a87 /components/script/dom/gamepadhapticactuator.rs | |
parent | 75a22cfe2eb6c4822d5cda98e84cc88c1e4ce941 (diff) | |
download | servo-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/dom/gamepadhapticactuator.rs')
-rw-r--r-- | components/script/dom/gamepadhapticactuator.rs | 42 |
1 files changed, 12 insertions, 30 deletions
diff --git a/components/script/dom/gamepadhapticactuator.rs b/components/script/dom/gamepadhapticactuator.rs index 6892092a9a5..909d60a83f9 100644 --- a/components/script/dom/gamepadhapticactuator.rs +++ b/components/script/dom/gamepadhapticactuator.rs @@ -27,11 +27,9 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::promise::Promise; use crate::realms::InRealm; use crate::script_runtime::{CanGc, JSContext}; -use crate::task::TaskCanceller; -use crate::task_source::{TaskSource, TaskSourceName}; +use crate::task_source::TaskSource; struct HapticEffectListener { - canceller: TaskCanceller, task_source: TaskSource, context: Trusted<GamepadHapticActuator>, } @@ -39,24 +37,22 @@ struct HapticEffectListener { impl HapticEffectListener { fn handle_stopped(&self, stopped_successfully: bool) { let context = self.context.clone(); - let _ = self.task_source.queue_with_canceller( - task!(handle_haptic_effect_stopped: move || { + let _ = self + .task_source + .queue(task!(handle_haptic_effect_stopped: move || { let actuator = context.root(); actuator.handle_haptic_effect_stopped(stopped_successfully); - }), - &self.canceller, - ); + })); } fn handle_completed(&self, completed_successfully: bool) { let context = self.context.clone(); - let _ = self.task_source.queue_with_canceller( - task!(handle_haptic_effect_completed: move || { + let _ = self + .task_source + .queue(task!(handle_haptic_effect_completed: move || { let actuator = context.root(); actuator.handle_haptic_effect_completed(completed_successfully); - }), - &self.canceller, - ); + })); } } @@ -204,7 +200,6 @@ impl GamepadHapticActuatorMethods<crate::DomTypeHolder> for GamepadHapticActuato let message = DOMString::from("preempted"); promise.resolve_native(&message); }), - &self.global(), ); } @@ -219,13 +214,8 @@ impl GamepadHapticActuatorMethods<crate::DomTypeHolder> for GamepadHapticActuato let context = Trusted::new(self); let (effect_complete_sender, effect_complete_receiver) = ipc::channel().expect("ipc channel failure"); - let (task_source, canceller) = ( - self.global().task_manager().gamepad_task_source(), - self.global().task_canceller(TaskSourceName::Gamepad), - ); let listener = HapticEffectListener { - canceller, - task_source, + task_source: self.global().task_manager().gamepad_task_source(), context, }; @@ -277,7 +267,6 @@ impl GamepadHapticActuatorMethods<crate::DomTypeHolder> for GamepadHapticActuato let message = DOMString::from("preempted"); promise.resolve_native(&message); }), - &self.global(), ); } @@ -288,13 +277,8 @@ impl GamepadHapticActuatorMethods<crate::DomTypeHolder> for GamepadHapticActuato let context = Trusted::new(self); let (effect_stop_sender, effect_stop_receiver) = ipc::channel().expect("ipc channel failure"); - let (task_source, canceller) = ( - self.global().task_manager().gamepad_task_source(), - self.global().task_canceller(TaskSourceName::Gamepad), - ); let listener = HapticEffectListener { - canceller, - task_source, + task_source: self.global().task_manager().gamepad_task_source(), context, }; @@ -350,8 +334,7 @@ impl GamepadHapticActuator { let promise = trusted_promise.root(); let message = DOMString::from("complete"); promise.resolve_native(&message); - }), - &self.global(), + }) ); } } @@ -372,7 +355,6 @@ impl GamepadHapticActuator { let message = DOMString::from("preempted"); promise.resolve_native(&message); }), - &self.global(), ); let (send, _rcv) = ipc::channel().expect("ipc channel failure"); |