mirror of
https://github.com/servo/servo.git
synced 2025-09-23 05:10:09 +01:00
Use GenericChannel for script_chan (#38645)
Motivation: Using our GenericChannel abstraction allows us to optimize IPC in single-process mode to just use cross-beam channel. To keep the diff low, and get early feedback, this PR only tackles a single channel, but the intention is to port all ipc channels to the generic channel, which allows us to skip serializing and deserializing messages in single process mode. Based on: - https://github.com/servo/servo/pull/38638 - https://github.com/servo/servo/pull/38636 Testing: Covered by existing tests --------- Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
parent
73e0f2f7e6
commit
8587536755
12 changed files with 36 additions and 22 deletions
|
@ -11,15 +11,15 @@ use std::marker::PhantomData;
|
|||
use std::rc::Rc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use base::generic_channel::GenericSender;
|
||||
use ipc_channel::Error;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use script_traits::ScriptThreadMessage;
|
||||
|
||||
static CURRENT_EVENT_LOOP_ID: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#event-loop>
|
||||
pub struct EventLoop {
|
||||
script_chan: IpcSender<ScriptThreadMessage>,
|
||||
script_chan: GenericSender<ScriptThreadMessage>,
|
||||
dont_send_or_sync: PhantomData<Rc<()>>,
|
||||
id: usize,
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ impl Drop for EventLoop {
|
|||
|
||||
impl EventLoop {
|
||||
/// Create a new event loop from the channel to its script thread.
|
||||
pub fn new(script_chan: IpcSender<ScriptThreadMessage>) -> Rc<EventLoop> {
|
||||
pub fn new(script_chan: GenericSender<ScriptThreadMessage>) -> Rc<EventLoop> {
|
||||
let id = CURRENT_EVENT_LOOP_ID.fetch_add(1, Ordering::Relaxed);
|
||||
Rc::new(EventLoop {
|
||||
script_chan,
|
||||
|
@ -57,6 +57,8 @@ impl EventLoop {
|
|||
|
||||
/// Send a message to the event loop.
|
||||
pub fn send(&self, msg: ScriptThreadMessage) -> Result<(), Error> {
|
||||
self.script_chan.send(msg)
|
||||
self.script_chan
|
||||
.send(msg)
|
||||
.map_err(|_err| Box::new(ipc_channel::ErrorKind::Custom("SendError".into())))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ use background_hang_monitor_api::{
|
|||
BackgroundHangMonitorControlMsg, BackgroundHangMonitorRegister, HangMonitorAlert,
|
||||
};
|
||||
use base::Epoch;
|
||||
use base::generic_channel::{GenericReceiver, GenericSender};
|
||||
use base::id::{
|
||||
BrowsingContextId, HistoryStateId, PipelineId, PipelineNamespace, PipelineNamespaceId,
|
||||
PipelineNamespaceRequest, WebViewId,
|
||||
|
@ -239,7 +240,8 @@ impl Pipeline {
|
|||
(script_chan, (None, None, None))
|
||||
},
|
||||
None => {
|
||||
let (script_chan, script_port) = ipc::channel().expect("Pipeline script chan");
|
||||
let (script_chan, script_port) =
|
||||
base::generic_channel::channel().expect("Pipeline script chan");
|
||||
|
||||
// Route messages coming from content to devtools as appropriate.
|
||||
let script_to_devtools_ipc_sender =
|
||||
|
@ -482,9 +484,9 @@ pub struct UnprivilegedPipelineContent {
|
|||
mem_profiler_chan: profile_mem::ProfilerChan,
|
||||
viewport_details: ViewportDetails,
|
||||
theme: Theme,
|
||||
script_chan: IpcSender<ScriptThreadMessage>,
|
||||
script_chan: GenericSender<ScriptThreadMessage>,
|
||||
load_data: LoadData,
|
||||
script_port: IpcReceiver<ScriptThreadMessage>,
|
||||
script_port: GenericReceiver<ScriptThreadMessage>,
|
||||
opts: Opts,
|
||||
prefs: Box<Preferences>,
|
||||
pipeline_namespace_id: PipelineNamespaceId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue