mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
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>
This commit is contained in:
parent
82ac8d41d0
commit
77bc7f415d
18 changed files with 217 additions and 325 deletions
|
@ -11,7 +11,8 @@ use servo_atoms::Atom;
|
|||
use crate::dom::bindings::refcounted::Trusted;
|
||||
use crate::dom::event::{EventBubbles, EventCancelable, EventTask, SimpleEventTask};
|
||||
use crate::dom::eventtarget::EventTarget;
|
||||
use crate::script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory};
|
||||
use crate::messaging::{CommonScriptMsg, ScriptEventLoopSender};
|
||||
use crate::script_runtime::ScriptThreadEventCategory;
|
||||
use crate::task::{TaskCanceller, TaskOnce};
|
||||
use crate::task_manager::TaskManager;
|
||||
|
||||
|
@ -141,7 +142,7 @@ impl TaskSource<'_> {
|
|||
let sender = sender
|
||||
.as_ref()
|
||||
.expect("Tried to enqueue task for DedicatedWorker while not handling a message.")
|
||||
.as_boxed();
|
||||
.clone();
|
||||
SendableTaskSource {
|
||||
sender,
|
||||
pipeline_id: self.task_manager.pipeline_id(),
|
||||
|
@ -159,8 +160,7 @@ impl<'task_manager> From<TaskSource<'task_manager>> for SendableTaskSource {
|
|||
|
||||
#[derive(JSTraceable, MallocSizeOf)]
|
||||
pub(crate) struct SendableTaskSource {
|
||||
#[ignore_malloc_size_of = "Need to push MallocSizeOf down into the ScriptChan trait implementations"]
|
||||
pub sender: Box<dyn ScriptChan + Send + 'static>,
|
||||
pub sender: ScriptEventLoopSender,
|
||||
#[no_trace]
|
||||
pub pipeline_id: PipelineId,
|
||||
pub name: TaskSourceName,
|
||||
|
@ -197,7 +197,7 @@ impl SendableTaskSource {
|
|||
impl Clone for SendableTaskSource {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
sender: self.sender.as_boxed(),
|
||||
sender: self.sender.clone(),
|
||||
pipeline_id: self.pipeline_id,
|
||||
name: self.name,
|
||||
canceller: self.canceller.clone(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue