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
|
@ -9,7 +9,7 @@ use std::collections::HashMap;
|
|||
|
||||
use base::id::PipelineId;
|
||||
|
||||
use crate::script_runtime::ScriptChan;
|
||||
use crate::messaging::ScriptEventLoopSender;
|
||||
use crate::task::TaskCanceller;
|
||||
use crate::task_source::{TaskSource, TaskSourceName};
|
||||
|
||||
|
@ -75,8 +75,7 @@ macro_rules! task_source_functions {
|
|||
|
||||
#[derive(JSTraceable, MallocSizeOf)]
|
||||
pub(crate) struct TaskManager {
|
||||
#[ignore_malloc_size_of = "We need to push the measurement of this down into the ScriptChan trait"]
|
||||
sender: RefCell<Option<Box<dyn ScriptChan + Send>>>,
|
||||
sender: RefCell<Option<ScriptEventLoopSender>>,
|
||||
#[no_trace]
|
||||
pipeline_id: PipelineId,
|
||||
cancellers: TaskCancellers,
|
||||
|
@ -84,7 +83,7 @@ pub(crate) struct TaskManager {
|
|||
|
||||
impl TaskManager {
|
||||
pub(crate) fn new(
|
||||
sender: Option<Box<dyn ScriptChan + Send>>,
|
||||
sender: Option<ScriptEventLoopSender>,
|
||||
pipeline_id: PipelineId,
|
||||
shared_canceller: Option<TaskCanceller>,
|
||||
) -> Self {
|
||||
|
@ -105,7 +104,7 @@ impl TaskManager {
|
|||
self.pipeline_id
|
||||
}
|
||||
|
||||
pub(crate) fn sender(&self) -> Ref<Option<Box<dyn ScriptChan + Send + 'static>>> {
|
||||
pub(crate) fn sender(&self) -> Ref<Option<ScriptEventLoopSender>> {
|
||||
self.sender.borrow()
|
||||
}
|
||||
|
||||
|
@ -116,7 +115,7 @@ impl TaskManager {
|
|||
/// Update the sender for this [`TaskSource`]. This is used by dedicated workers, which only have a
|
||||
/// sender while handling messages (as their sender prevents the main thread Worker object from being
|
||||
/// garbage collected).
|
||||
pub(crate) fn set_sender(&self, sender: Option<Box<dyn ScriptChan + Send>>) {
|
||||
pub(crate) fn set_sender(&self, sender: Option<ScriptEventLoopSender>) {
|
||||
*self.sender.borrow_mut() = sender;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue