aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/script_thread.rs
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2025-01-08 22:33:29 +0100
committerGitHub <noreply@github.com>2025-01-08 21:33:29 +0000
commit77bc7f415d91b46a2a739cca4521957a274c2386 (patch)
treedcbeddcb84df4192eda52133b2a141e7fc4c5af8 /components/script/script_thread.rs
parent82ac8d41d0ad7e06a0076ef898a01ee6acac3e99 (diff)
downloadservo-77bc7f415d91b46a2a739cca4521957a274c2386.tar.gz
servo-77bc7f415d91b46a2a739cca4521957a274c2386.zip
script: Use `enum`s for event loop senders and receivers (#34896)
Previously, senders and receivers to different kinds of event loops (the main `ScriptThread`, different types of workers) used a rust `trait` mechanism to implement dynamic behavior. This led to having many unused implementations of this `trait`. This change moves to using an `enum` based approach for these senders and receivers and removes all of the dead code. In addition, to allowing for use of rust's dead code detection, it simplifies the code a great deal. All of these generic senders and receivers are moved to the `messaging.rs` file and given proper documentation. Finally, empty an `JSTraceable` implementation is made for all crossbeam `Sender<...>`s to avoid having to manually skip them everytime they are included in structs. The pre-existing empty `MallocSizeOf` implementation is used more thoroughly. Other unecessary wrappers around these senders and receivers are removed as well. 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 5b0c201764a..6587c604d8b 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -142,15 +142,14 @@ use crate::dom::worklet::WorkletThreadPool;
use crate::dom::workletglobalscope::WorkletGlobalScopeInit;
use crate::fetch::FetchCanceller;
use crate::messaging::{
- MainThreadScriptChan, MainThreadScriptMsg, MixedMessage, ScriptThreadReceivers,
- ScriptThreadSenders,
+ CommonScriptMsg, MainThreadScriptMsg, MixedMessage, ScriptEventLoopSender,
+ ScriptThreadReceivers, ScriptThreadSenders,
};
use crate::microtask::{Microtask, MicrotaskQueue};
use crate::realms::enter_realm;
use crate::script_module::ScriptFetchOptions;
use crate::script_runtime::{
- CanGc, CommonScriptMsg, JSContext, Runtime, ScriptChan, ScriptThreadEventCategory,
- ThreadSafeJSContext,
+ CanGc, JSContext, Runtime, ScriptThreadEventCategory, ThreadSafeJSContext,
};
use crate::task_queue::TaskQueue;
use crate::task_source::{SendableTaskSource, TaskSourceName};
@@ -531,7 +530,7 @@ impl ScriptThreadFactory for ScriptThread {
.send(());
},
reporter_name,
- script_thread.senders.self_sender.0.clone(),
+ ScriptEventLoopSender::MainThread(script_thread.senders.self_sender.clone()),
CommonScriptMsg::CollectReports,
);
@@ -795,7 +794,7 @@ impl ScriptThread {
.borrow_mut()
.get_or_insert_with(|| {
let init = WorkletGlobalScopeInit {
- to_script_thread_sender: script_thread.senders.self_sender.0.clone(),
+ to_script_thread_sender: script_thread.senders.self_sender.clone(),
resource_threads: script_thread.resource_threads.clone(),
mem_profiler_chan: script_thread.senders.memory_profiler_sender.clone(),
time_profiler_chan: script_thread.senders.time_profiler_sender.clone(),
@@ -900,9 +899,8 @@ impl ScriptThread {
opts.output_file.is_some() || opts.exit_after_load || opts.webdriver_port.is_some();
let (self_sender, self_receiver) = unbounded();
- let self_sender = MainThreadScriptChan(self_sender.clone());
let runtime = Runtime::new(Some(SendableTaskSource {
- sender: self_sender.as_boxed(),
+ sender: ScriptEventLoopSender::MainThread(self_sender.clone()),
pipeline_id: state.id,
name: TaskSourceName::Networking,
canceller: Default::default(),
@@ -927,7 +925,7 @@ impl ScriptThread {
.unwrap_or_else(crossbeam_channel::never);
let (image_cache_sender, image_cache_receiver) = unbounded();
- let task_queue = TaskQueue::new(self_receiver, self_sender.0.clone());
+ let task_queue = TaskQueue::new(self_receiver, self_sender.clone());
let closing = Arc::new(AtomicBool::new(false));
let background_hang_monitor_exit_signal = BHMExitSignal {