diff options
author | Bastien Orivel <eijebong@bananium.fr> | 2018-11-07 19:48:07 +0100 |
---|---|---|
committer | Bastien Orivel <eijebong@bananium.fr> | 2018-11-18 19:33:19 +0100 |
commit | 9a7eeb349a8aa657e063665ac92387ab8ef3ce28 (patch) | |
tree | 63c5aa1ba7cd7fdb1bf14bcc9cbb6e6c0e24431b /components | |
parent | 76195e0779469f29a5e27cd882e2bbe8b2c9d6dd (diff) | |
download | servo-9a7eeb349a8aa657e063665ac92387ab8ef3ce28.tar.gz servo-9a7eeb349a8aa657e063665ac92387ab8ef3ce28.zip |
Update crossbeam-channel to 0.3
Diffstat (limited to 'components')
71 files changed, 248 insertions, 455 deletions
diff --git a/components/channel/Cargo.toml b/components/channel/Cargo.toml deleted file mode 100644 index 5b30d622830..00000000000 --- a/components/channel/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "servo_channel" -version = "0.0.1" -authors = ["The Servo Project Developers"] -license = "MPL-2.0" -edition = "2018" -publish = false - -[lib] -name = "servo_channel" -path = "lib.rs" -test = false -doctest = false - -[dependencies] -crossbeam-channel = "0.2.5" -ipc-channel = "0.11" -serde = "1.0" - -[[test]] -name = "main" -path = "tests/disconnect.rs" diff --git a/components/channel/lib.rs b/components/channel/lib.rs deleted file mode 100644 index d8f637b99db..00000000000 --- a/components/channel/lib.rs +++ /dev/null @@ -1,164 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -pub mod base_channel { - pub use crossbeam_channel::*; -} -// Needed to re-export the select macro. -pub use crossbeam_channel::*; - -use ipc_channel::ipc::IpcReceiver; -use ipc_channel::router::ROUTER; -use serde::{Deserialize, Serialize}; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::Arc; - -pub fn route_ipc_receiver_to_new_servo_receiver<T>(ipc_receiver: IpcReceiver<T>) -> Receiver<T> -where - T: for<'de> Deserialize<'de> + Serialize + Send + 'static, -{ - let (servo_sender, servo_receiver) = channel(); - ROUTER.add_route( - ipc_receiver.to_opaque(), - Box::new(move |message| drop(servo_sender.send(message.to::<T>().unwrap()))), - ); - servo_receiver -} - -pub fn route_ipc_receiver_to_new_servo_sender<T>( - ipc_receiver: IpcReceiver<T>, - servo_sender: Sender<T>, -) where - T: for<'de> Deserialize<'de> + Serialize + Send + 'static, -{ - ROUTER.add_route( - ipc_receiver.to_opaque(), - Box::new(move |message| drop(servo_sender.send(message.to::<T>().unwrap()))), - ) -} - -pub fn channel<T>() -> (Sender<T>, Receiver<T>) { - let (base_sender, base_receiver) = crossbeam_channel::unbounded::<T>(); - let is_disconnected = Arc::new(AtomicBool::new(false)); - ( - Sender::new(base_sender, is_disconnected.clone()), - Receiver::new(base_receiver, is_disconnected), - ) -} - -#[derive(Debug, PartialEq)] -pub enum ChannelError { - ChannelClosedError, -} - -pub struct Receiver<T> { - receiver: crossbeam_channel::Receiver<T>, - is_disconnected: Arc<AtomicBool>, -} - -impl<T> Drop for Receiver<T> { - fn drop(&mut self) { - self.is_disconnected.store(true, Ordering::SeqCst); - } -} - -impl<T> Clone for Receiver<T> { - fn clone(&self) -> Self { - Receiver { - receiver: self.receiver.clone(), - is_disconnected: self.is_disconnected.clone(), - } - } -} - -impl<T> Receiver<T> { - pub fn new( - receiver: crossbeam_channel::Receiver<T>, - is_disconnected: Arc<AtomicBool>, - ) -> Receiver<T> { - Receiver { - receiver, - is_disconnected, - } - } - - pub fn recv(&self) -> Option<T> { - self.receiver.recv() - } - - pub fn try_recv(&self) -> Option<T> { - self.receiver.try_recv() - } - - pub fn len(&self) -> usize { - self.receiver.len() - } - - pub fn select(&self) -> &crossbeam_channel::Receiver<T> { - &self.receiver - } -} - -impl<T> Iterator for Receiver<T> { - type Item = T; - - fn next(&mut self) -> Option<Self::Item> { - self.receiver.recv() - } -} - -impl<'a, T> IntoIterator for &'a Receiver<T> { - type Item = T; - type IntoIter = crossbeam_channel::Receiver<T>; - - fn into_iter(self) -> Self::IntoIter { - self.receiver.clone() - } -} - -pub struct Sender<T> { - sender: crossbeam_channel::Sender<T>, - is_disconnected: Arc<AtomicBool>, -} - -impl<T> Clone for Sender<T> { - fn clone(&self) -> Self { - Sender { - sender: self.sender.clone(), - is_disconnected: self.is_disconnected.clone(), - } - } -} - -impl<T> Sender<T> { - pub fn new( - sender: crossbeam_channel::Sender<T>, - is_disconnected: Arc<AtomicBool>, - ) -> Sender<T> { - Sender { - sender, - is_disconnected, - } - } - - pub fn send(&self, msg: T) -> Result<(), ChannelError> { - if self.is_disconnected.load(Ordering::SeqCst) { - Err(ChannelError::ChannelClosedError) - } else { - Ok(self.sender.send(msg)) - } - } - - pub fn len(&self) -> usize { - self.sender.len() - } - - pub fn select(&self) -> Option<&crossbeam_channel::Sender<T>> { - if self.is_disconnected.load(Ordering::SeqCst) { - None - } else { - Some(&self.sender) - } - } -} diff --git a/components/channel/tests/disconnect.rs b/components/channel/tests/disconnect.rs deleted file mode 100644 index 1ba87287cfa..00000000000 --- a/components/channel/tests/disconnect.rs +++ /dev/null @@ -1,31 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#[macro_use] -extern crate servo_channel; - -use servo_channel::{channel, ChannelError}; - -#[test] -fn send_after_receiver_dropped() { - let (sender, receiver) = channel(); - drop(receiver); - assert_eq!(sender.send(1), Err(ChannelError::ChannelClosedError)); - let sent = select! { - send(sender.select(), 1) => true, - default => false - }; - assert_eq!(sent, false); -} - -#[test] -fn send_with_receiver_connected() { - let (sender, _receiver) = channel(); - assert_eq!(sender.send(1), Ok(())); - let sent = select! { - send(sender.select(), 1) => true, - default => false - }; - assert_eq!(sent, true); -} diff --git a/components/compositing/Cargo.toml b/components/compositing/Cargo.toml index 73b9413fcdf..d20ee89b354 100644 --- a/components/compositing/Cargo.toml +++ b/components/compositing/Cargo.toml @@ -15,6 +15,7 @@ path = "lib.rs" default = [] [dependencies] +crossbeam-channel = "0.3" embedder_traits = {path = "../embedder_traits"} euclid = "0.19" gfx_traits = {path = "../gfx_traits"} @@ -28,7 +29,6 @@ msg = {path = "../msg"} net_traits = {path = "../net_traits"} profile_traits = {path = "../profile_traits"} script_traits = {path = "../script_traits"} -servo_channel = {path = "../channel"} servo_config = {path = "../config"} servo_geometry = {path = "../geometry"} servo_url = {path = "../url"} diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index ee25a835d7e..a4f89c7c0ee 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -12,6 +12,7 @@ use crate::windowing::{ }; use crate::CompositionPipeline; use crate::SendableFrameTree; +use crossbeam_channel::Sender; use euclid::{TypedPoint2D, TypedScale, TypedVector2D}; use gfx_traits::Epoch; #[cfg(feature = "gleam")] @@ -27,7 +28,6 @@ use script_traits::CompositorEvent::{MouseButtonEvent, MouseMoveEvent, TouchEven use script_traits::{AnimationState, AnimationTickType, ConstellationMsg, LayoutControlMsg}; use script_traits::{MouseButton, MouseEventType, ScrollState, TouchEventType, TouchId}; use script_traits::{UntrustedNodeAddress, WindowSizeData, WindowSizeType}; -use servo_channel::Sender; use servo_config::opts; use servo_geometry::DeviceIndependentPixel; use std::collections::HashMap; diff --git a/components/compositing/compositor_thread.rs b/components/compositing/compositor_thread.rs index 76b14d3eb6e..d56a97b8a63 100644 --- a/components/compositing/compositor_thread.rs +++ b/components/compositing/compositor_thread.rs @@ -6,6 +6,7 @@ use crate::compositor::CompositingReason; use crate::SendableFrameTree; +use crossbeam_channel::{Receiver, Sender}; use embedder_traits::EventLoopWaker; use gfx_traits::Epoch; use ipc_channel::ipc::IpcSender; @@ -14,7 +15,6 @@ use net_traits::image::base::Image; use profile_traits::mem; use profile_traits::time; use script_traits::{AnimationState, ConstellationMsg, EventResult}; -use servo_channel::{Receiver, Sender}; use std::fmt::{Debug, Error, Formatter}; use style_traits::viewport::ViewportConstraints; use webrender_api::{self, DeviceIntPoint, DeviceUintSize}; @@ -50,7 +50,7 @@ pub struct CompositorReceiver { impl CompositorReceiver { pub fn try_recv_compositor_msg(&mut self) -> Option<Msg> { - self.receiver.try_recv() + self.receiver.try_recv().ok() } pub fn recv_compositor_msg(&mut self) -> Msg { self.receiver.recv().unwrap() diff --git a/components/constellation/Cargo.toml b/components/constellation/Cargo.toml index 9af85bd5939..5ef39c5bbae 100644 --- a/components/constellation/Cargo.toml +++ b/components/constellation/Cargo.toml @@ -17,6 +17,7 @@ canvas = {path = "../canvas"} clipboard = "0.5" canvas_traits = {path = "../canvas_traits"} compositing = {path = "../compositing"} +crossbeam-channel = "0.3" debugger = {path = "../debugger"} devtools_traits = {path = "../devtools_traits"} euclid = "0.19" @@ -35,7 +36,6 @@ net_traits = {path = "../net_traits"} profile_traits = {path = "../profile_traits"} script_traits = {path = "../script_traits"} serde = "1.0" -servo_channel = {path = "../channel"} style_traits = {path = "../style_traits"} servo_config = {path = "../config"} servo_rand = {path = "../rand"} diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 2c693273b0f..474684da18b 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -110,6 +110,7 @@ use crate::session_history::{ JointSessionHistory, NeedsToReload, SessionHistoryChange, SessionHistoryDiff, }; use crate::timer_scheduler::TimerScheduler; +use crossbeam_channel::{unbounded, Receiver, Sender}; use devtools_traits::{ChromeToDevtoolsControlMsg, DevtoolsControlMsg}; use embedder_traits::{EmbedderMsg, EmbedderProxy}; use euclid::{Size2D, TypedScale, TypedSize2D}; @@ -146,7 +147,6 @@ use script_traits::{LayoutMsg as FromLayoutMsg, ScriptMsg as FromScriptMsg, Scri use script_traits::{SWManagerMsg, ScopeThings, UpdatePipelineIdReason, WebDriverCommandMsg}; use script_traits::{WindowSizeData, WindowSizeType}; use serde::{Deserialize, Serialize}; -use servo_channel::{channel, Receiver, Sender}; use servo_config::opts; use servo_config::prefs::PREFS; use servo_rand::{random, Rng, SeedableRng, ServoRng}; @@ -555,7 +555,7 @@ fn route_ipc_receiver_to_new_mpsc_receiver_preserving_errors<T>( where T: for<'de> Deserialize<'de> + Serialize + Send + 'static, { - let (mpsc_sender, mpsc_receiver) = channel(); + let (mpsc_sender, mpsc_receiver) = unbounded(); ROUTER.add_route( ipc_receiver.to_opaque(), Box::new(move |message| drop(mpsc_sender.send(message.to::<T>()))), @@ -572,7 +572,7 @@ where pub fn start( state: InitialConstellationState, ) -> (Sender<FromCompositorMsg>, IpcSender<SWManagerMsg>) { - let (compositor_sender, compositor_receiver) = channel(); + let (compositor_sender, compositor_receiver) = unbounded(); // service worker manager to communicate with constellation let (swmanager_sender, swmanager_receiver) = ipc::channel().expect("ipc channel failure"); @@ -591,7 +591,7 @@ where let layout_receiver = route_ipc_receiver_to_new_mpsc_receiver_preserving_errors(ipc_layout_receiver); - let (network_listener_sender, network_listener_receiver) = channel(); + let (network_listener_sender, network_listener_receiver) = unbounded(); let swmanager_receiver = route_ipc_receiver_to_new_mpsc_receiver_preserving_errors(swmanager_receiver); @@ -906,21 +906,21 @@ where // being called. If this happens, there's not much we can do // other than panic. let request = select! { - recv(self.script_receiver.select(), msg) => { + recv(self.script_receiver) -> msg => { msg.expect("Unexpected script channel panic in constellation").map(Request::Script) } - recv(self.compositor_receiver.select(), msg) => { + recv(self.compositor_receiver) -> msg => { Ok(Request::Compositor(msg.expect("Unexpected compositor channel panic in constellation"))) } - recv(self.layout_receiver.select(), msg) => { + recv(self.layout_receiver) -> msg => { msg.expect("Unexpected layout channel panic in constellation").map(Request::Layout) } - recv(self.network_listener_receiver.select(), msg) => { + recv(self.network_listener_receiver) -> msg => { Ok(Request::NetworkListener( msg.expect("Unexpected network listener channel panic in constellation") )) } - recv(self.swmanager_receiver.select(), msg) => { + recv(self.swmanager_receiver) -> msg => { msg.expect("Unexpected panic channel panic in constellation").map(Request::FromSWManager) } }; diff --git a/components/constellation/lib.rs b/components/constellation/lib.rs index 1b4befa3af6..c9ed8485ba4 100644 --- a/components/constellation/lib.rs +++ b/components/constellation/lib.rs @@ -6,9 +6,11 @@ #![cfg_attr(feature = "unstable", feature(conservative_impl_trait))] #[macro_use] +extern crate crossbeam_channel; +#[macro_use] extern crate log; #[macro_use] -extern crate servo_channel; +extern crate serde; mod browsingcontext; mod constellation; diff --git a/components/constellation/network_listener.rs b/components/constellation/network_listener.rs index a417f5cdeeb..687170231ea 100644 --- a/components/constellation/network_listener.rs +++ b/components/constellation/network_listener.rs @@ -6,6 +6,7 @@ //! Any redirects that are encountered are followed. Whenever a non-redirect //! response is received, it is forwarded to the appropriate script thread. +use crossbeam_channel::Sender; use http::header::LOCATION; use ipc_channel::ipc; use ipc_channel::router::ROUTER; @@ -15,7 +16,6 @@ use net_traits::request::{Destination, RequestInit}; use net_traits::response::ResponseInit; use net_traits::{CoreResourceMsg, FetchChannels, FetchMetadata, FetchResponseMsg}; use net_traits::{IpcSend, NetworkError, ResourceThreads}; -use servo_channel::Sender; pub struct NetworkListener { res_init: Option<ResponseInit>, diff --git a/components/constellation/pipeline.rs b/components/constellation/pipeline.rs index 5d6cc038a14..71ce43ad55d 100644 --- a/components/constellation/pipeline.rs +++ b/components/constellation/pipeline.rs @@ -8,6 +8,7 @@ use compositing::compositor_thread::Msg as CompositorMsg; use compositing::CompositionPipeline; use compositing::CompositorProxy; use crate::event_loop::EventLoop; +use crossbeam_channel::Sender; use devtools_traits::{DevtoolsControlMsg, ScriptToDevtoolsControlMsg}; use euclid::{TypedScale, TypedSize2D}; use gfx::font_cache_thread::FontCacheThread; @@ -28,7 +29,6 @@ use script_traits::{DocumentActivity, InitialScriptState}; use script_traits::{LayoutControlMsg, LayoutMsg, LoadData}; use script_traits::{NewLayoutInfo, SWManagerMsg, SWManagerSenders}; use script_traits::{ScriptThreadFactory, TimerSchedulerMsg, WindowSizeData}; -use servo_channel::Sender; use servo_config::opts::{self, Opts}; use servo_config::prefs::{Pref, PREFS}; use servo_url::ServoUrl; diff --git a/components/constellation/timer_scheduler.rs b/components/constellation/timer_scheduler.rs index 6581c3f0916..f08314d1d5e 100644 --- a/components/constellation/timer_scheduler.rs +++ b/components/constellation/timer_scheduler.rs @@ -2,9 +2,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use crossbeam_channel::{self, TryRecvError}; use ipc_channel::ipc::{self, IpcSender}; use script_traits::{TimerEvent, TimerEventRequest, TimerSchedulerMsg}; -use servo_channel::base_channel; use std::cmp::{self, Ord}; use std::collections::BinaryHeap; use std::thread; @@ -39,7 +39,7 @@ impl PartialEq for ScheduledEvent { impl TimerScheduler { pub fn start() -> IpcSender<TimerSchedulerMsg> { let (req_ipc_sender, req_ipc_receiver) = ipc::channel().expect("Channel creation failed."); - let (req_sender, req_receiver) = base_channel::bounded(1); + let (req_sender, req_receiver) = crossbeam_channel::bounded(1); // We could do this much more directly with recv_timeout // (https://github.com/rust-lang/rfcs/issues/962). @@ -69,29 +69,26 @@ impl TimerScheduler { scheduled_events.pop(); } // Look to see if there are any incoming events - select! { - recv(req_receiver, msg) => match msg { - // If there is an event, add it to the priority queue - Some(TimerSchedulerMsg::Request(req)) => { - let TimerEventRequest(_, _, _, delay) = req; - let schedule = Instant::now() + Duration::from_millis(delay.get()); - let event = ScheduledEvent { - request: req, - for_time: schedule, - }; - scheduled_events.push(event); - }, - // If the channel is closed or we are shutting down, we are done. - Some(TimerSchedulerMsg::Exit) | - None => break, + match req_receiver.try_recv() { + // If there is an event, add it to the priority queue + Ok(TimerSchedulerMsg::Request(req)) => { + let TimerEventRequest(_, _, _, delay) = req; + let schedule = Instant::now() + Duration::from_millis(delay.get()); + let event = ScheduledEvent { + request: req, + for_time: schedule, + }; + scheduled_events.push(event); }, // If there is no incoming event, park the thread, // it will either be unparked when a new event arrives, // or by a timeout. - default => match scheduled_events.peek() { + Err(TryRecvError::Empty) => match scheduled_events.peek() { None => thread::park(), Some(event) => thread::park_timeout(event.for_time - now), }, + // If the channel is closed or we are shutting down, we are done. + Ok(TimerSchedulerMsg::Exit) | Err(TryRecvError::Disconnected) => break, } } // This thread can terminate if the req_ipc_sender is dropped. diff --git a/components/debugger/Cargo.toml b/components/debugger/Cargo.toml index 2c9b38a4a70..a7bef79f0e8 100644 --- a/components/debugger/Cargo.toml +++ b/components/debugger/Cargo.toml @@ -12,6 +12,6 @@ path = "lib.rs" crate_type = ["rlib"] [dependencies] +crossbeam-channel = "0.3" log = "0.4" -servo_channel = {path = "../channel"} ws = "0.7.3" diff --git a/components/debugger/lib.rs b/components/debugger/lib.rs index b6185663165..a09fb003e87 100644 --- a/components/debugger/lib.rs +++ b/components/debugger/lib.rs @@ -12,7 +12,7 @@ enum Message { ShutdownServer, } -pub struct Sender(servo_channel::Sender<Message>); +pub struct Sender(crossbeam_channel::Sender<Message>); struct Connection { sender: ws::Sender, @@ -35,7 +35,7 @@ impl Handler for Connection { pub fn start_server(port: u16) -> Sender { debug!("Starting server."); - let (sender, receiver) = servo_channel::channel(); + let (sender, receiver) = crossbeam_channel::unbounded(); thread::Builder::new() .name("debugger".to_owned()) .spawn(move || { @@ -49,7 +49,7 @@ pub fn start_server(port: u16) -> Sender { socket.listen(("127.0.0.1", port)).unwrap(); }) .expect("Thread spawning failed"); - while let Some(message) = receiver.recv() { + while let Ok(message) = receiver.recv() { match message { Message::ShutdownServer => { break; diff --git a/components/devtools/Cargo.toml b/components/devtools/Cargo.toml index 706550068ff..20c2ff5abc8 100644 --- a/components/devtools/Cargo.toml +++ b/components/devtools/Cargo.toml @@ -11,6 +11,7 @@ name = "devtools" path = "lib.rs" [dependencies] +crossbeam-channel = "0.3" devtools_traits = {path = "../devtools_traits"} headers-core = "0.0.1" headers-ext = "0.0.3" @@ -22,5 +23,4 @@ log = "0.4" msg = {path = "../msg"} serde = "1.0" serde_json = "1.0" -servo_channel = {path = "../channel"} time = "0.1" diff --git a/components/devtools/lib.rs b/components/devtools/lib.rs index 0768a79ed09..ddf89cd4436 100644 --- a/components/devtools/lib.rs +++ b/components/devtools/lib.rs @@ -33,12 +33,12 @@ use crate::actors::thread::ThreadActor; use crate::actors::timeline::TimelineActor; use crate::actors::worker::WorkerActor; use crate::protocol::JsonPacketStream; +use crossbeam_channel::{unbounded, Receiver, Sender}; use devtools_traits::{ChromeToDevtoolsControlMsg, ConsoleMessage, DevtoolsControlMsg}; use devtools_traits::{DevtoolScriptControlMsg, DevtoolsPageInfo, LogLevel, NetworkEvent}; use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId}; use ipc_channel::ipc::IpcSender; use msg::constellation_msg::PipelineId; -use servo_channel::{channel, Receiver, Sender}; use std::borrow::ToOwned; use std::cell::RefCell; use std::collections::hash_map::Entry::{Occupied, Vacant}; @@ -125,7 +125,7 @@ struct ResponseStartUpdateMsg { /// Spin up a devtools server that listens for connections on the specified port. pub fn start_server(port: u16) -> Sender<DevtoolsControlMsg> { - let (sender, receiver) = channel(); + let (sender, receiver) = unbounded(); { let sender = sender.clone(); thread::Builder::new() @@ -549,7 +549,7 @@ fn run_server( }) .expect("Thread spawning failed"); - while let Some(msg) = receiver.recv() { + while let Ok(msg) = receiver.recv() { match msg { DevtoolsControlMsg::FromChrome(ChromeToDevtoolsControlMsg::AddClient(stream)) => { let actors = actors.clone(); diff --git a/components/embedder_traits/Cargo.toml b/components/embedder_traits/Cargo.toml index 6d9fef7f8e0..ab6d5e36229 100644 --- a/components/embedder_traits/Cargo.toml +++ b/components/embedder_traits/Cargo.toml @@ -11,13 +11,13 @@ name = "embedder_traits" path = "lib.rs" [dependencies] +crossbeam-channel = "0.3" ipc-channel = "0.11" keyboard-types = "0.4.3" lazy_static = "1" log = "0.4" msg = {path = "../msg"} serde = "1.0" -servo_channel = {path = "../channel"} servo_url = {path = "../url"} style_traits = {path = "../style_traits", features = ["servo"]} webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]} diff --git a/components/embedder_traits/lib.rs b/components/embedder_traits/lib.rs index 96364c5e639..b0095ec8963 100644 --- a/components/embedder_traits/lib.rs +++ b/components/embedder_traits/lib.rs @@ -11,10 +11,10 @@ extern crate serde; pub mod resources; +use crossbeam_channel::{Receiver, Sender}; use ipc_channel::ipc::IpcSender; use keyboard_types::KeyboardEvent; use msg::constellation_msg::{InputMethodType, TopLevelBrowsingContextId}; -use servo_channel::{Receiver, Sender}; use servo_url::ServoUrl; use std::fmt::{Debug, Error, Formatter}; use style_traits::cursor::CursorKind; @@ -60,7 +60,7 @@ impl EmbedderReceiver { pub fn try_recv_embedder_msg( &mut self, ) -> Option<(Option<TopLevelBrowsingContextId>, EmbedderMsg)> { - self.receiver.try_recv() + self.receiver.try_recv().ok() } pub fn recv_embedder_msg(&mut self) -> (Option<TopLevelBrowsingContextId>, EmbedderMsg) { self.receiver.recv().unwrap() diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml index 06de13c951f..ccda6a62867 100644 --- a/components/layout/Cargo.toml +++ b/components/layout/Cargo.toml @@ -17,6 +17,7 @@ app_units = "0.7" atomic_refcell = "0.1" bitflags = "1.0" canvas_traits = {path = "../canvas_traits"} +crossbeam-channel = "0.3" euclid = "0.19" fnv = "1.0" fxhash = "0.2" @@ -41,7 +42,6 @@ selectors = { path = "../selectors" } serde = "1.0" servo_arc = {path = "../servo_arc"} servo_atoms = {path = "../atoms"} -servo_channel = {path = "../channel"} servo_geometry = {path = "../geometry"} serde_json = "1.0" servo_config = {path = "../config"} diff --git a/components/layout/animation.rs b/components/layout/animation.rs index 0903c1b7fa5..a1fd1e334a4 100644 --- a/components/layout/animation.rs +++ b/components/layout/animation.rs @@ -8,12 +8,12 @@ use crate::context::LayoutContext; use crate::display_list::items::OpaqueNode; use crate::flow::{Flow, GetBaseFlow}; use crate::opaque_node::OpaqueNodeMethods; +use crossbeam_channel::Receiver; use fxhash::FxHashMap; use ipc_channel::ipc::IpcSender; use msg::constellation_msg::PipelineId; use script_traits::UntrustedNodeAddress; use script_traits::{AnimationState, ConstellationControlMsg, LayoutMsg as ConstellationMsg}; -use servo_channel::Receiver; use style::animation::{update_style_for_animation, Animation}; use style::dom::TElement; use style::font_metrics::ServoMetricsProvider; @@ -36,7 +36,7 @@ pub fn update_animation_state<E>( E: TElement, { let mut new_running_animations = vec![]; - while let Some(animation) = new_animations_receiver.try_recv() { + while let Ok(animation) = new_animations_receiver.try_recv() { let mut should_push = true; if let Animation::Keyframes(ref node, _, ref name, ref state) = animation { // If the animation was already present in the list for the diff --git a/components/layout_thread/Cargo.toml b/components/layout_thread/Cargo.toml index 30369ad2780..4c1f53ec48c 100644 --- a/components/layout_thread/Cargo.toml +++ b/components/layout_thread/Cargo.toml @@ -16,6 +16,7 @@ unstable = ["parking_lot/nightly"] [dependencies] app_units = "0.7" atomic_refcell = "0.1" +crossbeam-channel = "0.3" embedder_traits = {path = "../embedder_traits"} euclid = "0.19" fnv = "1.0" @@ -47,7 +48,6 @@ serde_json = "1.0" servo_allocator = {path = "../allocator"} servo_arc = {path = "../servo_arc"} servo_atoms = {path = "../atoms"} -servo_channel = {path = "../channel"} servo_config = {path = "../config"} servo_geometry = {path = "../geometry"} servo_url = {path = "../url"} diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 91b801464fe..772375b5994 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -6,6 +6,8 @@ //! painted. #[macro_use] +extern crate crossbeam_channel; +#[macro_use] extern crate html5ever; #[macro_use] extern crate layout; @@ -15,14 +17,13 @@ extern crate lazy_static; extern crate log; #[macro_use] extern crate profile_traits; -#[macro_use] -extern crate servo_channel; mod dom_wrapper; use app_units::Au; use crate::dom_wrapper::drop_style_and_layout_data; use crate::dom_wrapper::{ServoLayoutDocument, ServoLayoutElement, ServoLayoutNode}; +use crossbeam_channel::{unbounded, Receiver, Sender}; use embedder_traits::resources::{self, Resource}; use euclid::{Point2D, Rect, Size2D, TypedScale, TypedSize2D}; use fnv::FnvHashMap; @@ -33,6 +34,7 @@ use gfx::font_context; use gfx_traits::{node_id_from_scroll_id, Epoch}; use histogram::Histogram; use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; +use ipc_channel::router::ROUTER; use layout::animation; use layout::construct::ConstructionResult; use layout::context::malloc_size_of_persistent_local_context; @@ -82,7 +84,6 @@ use script_traits::{ScrollState, UntrustedNodeAddress}; use selectors::Element; use servo_arc::Arc as ServoArc; use servo_atoms::Atom; -use servo_channel::{channel, route_ipc_receiver_to_new_servo_receiver, Receiver, Sender}; use servo_config::opts; use servo_config::prefs::PREFS; use servo_geometry::MaxRect; @@ -474,14 +475,15 @@ impl LayoutThread { debug!("Possible layout Threads: {}", layout_threads); // Create the channel on which new animations can be sent. - let (new_animations_sender, new_animations_receiver) = channel(); + let (new_animations_sender, new_animations_receiver) = unbounded(); // Proxy IPC messages from the pipeline to the layout thread. - let pipeline_receiver = route_ipc_receiver_to_new_servo_receiver(pipeline_port); + let pipeline_receiver = ROUTER.route_ipc_receiver_to_new_crossbeam_receiver(pipeline_port); // Ask the router to proxy IPC messages from the font cache thread to the layout thread. let (ipc_font_cache_sender, ipc_font_cache_receiver) = ipc::channel().unwrap(); - let font_cache_receiver = route_ipc_receiver_to_new_servo_receiver(ipc_font_cache_receiver); + let font_cache_receiver = + ROUTER.route_ipc_receiver_to_new_crossbeam_receiver(ipc_font_cache_receiver); LayoutThread { id: id, @@ -612,9 +614,9 @@ impl LayoutThread { } let request = select! { - recv(self.pipeline_port.select(), msg) => Request::FromPipeline(msg.unwrap()), - recv(self.port.select(), msg) => Request::FromScript(msg.unwrap()), - recv(self.font_cache_receiver.select(), msg) => { msg.unwrap(); Request::FromFontCache } + recv(self.pipeline_port) -> msg => Request::FromPipeline(msg.unwrap()), + recv(self.port) -> msg => Request::FromScript(msg.unwrap()), + recv(self.font_cache_receiver) -> msg => { msg.unwrap(); Request::FromFontCache } }; match request { diff --git a/components/layout_traits/Cargo.toml b/components/layout_traits/Cargo.toml index 881e67315e8..1eea8e5e0c5 100644 --- a/components/layout_traits/Cargo.toml +++ b/components/layout_traits/Cargo.toml @@ -11,6 +11,7 @@ name = "layout_traits" path = "lib.rs" [dependencies] +crossbeam-channel = "0.3" gfx = {path = "../gfx"} ipc-channel = "0.11" metrics = {path = "../metrics"} @@ -18,6 +19,5 @@ msg = {path = "../msg"} net_traits = {path = "../net_traits"} profile_traits = {path = "../profile_traits"} script_traits = {path = "../script_traits"} -servo_channel = {path = "../channel"} servo_url = {path = "../url"} webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]} diff --git a/components/layout_traits/lib.rs b/components/layout_traits/lib.rs index 8ecf214fbb0..bf8b22d9b41 100644 --- a/components/layout_traits/lib.rs +++ b/components/layout_traits/lib.rs @@ -9,6 +9,7 @@ // The traits are here instead of in layout so // that these modules won't have to depend on layout. +use crossbeam_channel::{Receiver, Sender}; use gfx::font_cache_thread::FontCacheThread; use ipc_channel::ipc::{IpcReceiver, IpcSender}; use metrics::PaintTimeMetrics; @@ -18,7 +19,6 @@ use net_traits::image_cache::ImageCache; use profile_traits::{mem, time}; use script_traits::LayoutMsg as ConstellationMsg; use script_traits::{ConstellationControlMsg, LayoutControlMsg}; -use servo_channel::{Receiver, Sender}; use servo_url::ServoUrl; use std::sync::Arc; diff --git a/components/malloc_size_of/Cargo.toml b/components/malloc_size_of/Cargo.toml index 4ca42aa7472..47d586c3092 100644 --- a/components/malloc_size_of/Cargo.toml +++ b/components/malloc_size_of/Cargo.toml @@ -10,13 +10,13 @@ path = "lib.rs" [features] servo = [ + "crossbeam-channel", "hyper", "hyper_serde", "keyboard-types", "mozjs", "serde", "serde_bytes", - "servo_channel", "string_cache", "time", "url", @@ -26,6 +26,7 @@ servo = [ [dependencies] app_units = "0.7" +crossbeam-channel = { version = "0.3", optional = true } cssparser = "0.25" euclid = "0.19" hashglobe = { path = "../hashglobe" } @@ -37,7 +38,6 @@ selectors = { path = "../selectors" } serde = { version = "1.0.27", optional = true } serde_bytes = { version = "0.10", optional = true } servo_arc = { path = "../servo_arc" } -servo_channel = { path = "../channel", optional = true } smallbitvec = "2.1.0" smallvec = "0.6" string_cache = { version = "0.7", optional = true } diff --git a/components/malloc_size_of/lib.rs b/components/malloc_size_of/lib.rs index 69dc48ce30d..778082b5f06 100644 --- a/components/malloc_size_of/lib.rs +++ b/components/malloc_size_of/lib.rs @@ -44,6 +44,8 @@ //! `<Box<_> as MallocSizeOf>::size_of(field, ops)`. extern crate app_units; +#[cfg(feature = "servo")] +extern crate crossbeam_channel; extern crate cssparser; extern crate euclid; extern crate hashglobe; @@ -61,8 +63,6 @@ extern crate serde; #[cfg(feature = "servo")] extern crate serde_bytes; extern crate servo_arc; -#[cfg(feature = "servo")] -extern crate servo_channel; extern crate smallbitvec; extern crate smallvec; #[cfg(feature = "servo")] @@ -1027,7 +1027,7 @@ where // Placeholder for unique case where internals of Sender cannot be measured. // malloc size of is 0 macro complains about type supplied! #[cfg(feature = "servo")] -impl<T> MallocSizeOf for servo_channel::Sender<T> { +impl<T> MallocSizeOf for crossbeam_channel::Sender<T> { fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { 0 } diff --git a/components/net/Cargo.toml b/components/net/Cargo.toml index 3ea3b9f117b..f3eb07e0cc3 100644 --- a/components/net/Cargo.toml +++ b/components/net/Cargo.toml @@ -20,6 +20,7 @@ base64 = "0.9" brotli = "2.5" bytes = "0.4" cookie_rs = {package = "cookie", version = "0.11"} +crossbeam-channel = "0.3" devtools_traits = {path = "../devtools_traits"} embedder_traits = { path = "../embedder_traits" } flate2 = "1" @@ -47,7 +48,6 @@ serde = "1.0" serde_json = "1.0" servo_allocator = {path = "../allocator"} servo_arc = {path = "../servo_arc"} -servo_channel = {path = "../channel"} servo_config = {path = "../config"} servo_url = {path = "../url"} tokio = "0.1" diff --git a/components/net/fetch/methods.rs b/components/net/fetch/methods.rs index 499070c04d2..51eebd5fc80 100644 --- a/components/net/fetch/methods.rs +++ b/components/net/fetch/methods.rs @@ -9,6 +9,7 @@ use crate::filemanager_thread::FileManager; use crate::http_loader::{determine_request_referrer, http_fetch, HttpState}; use crate::http_loader::{set_default_accept, set_default_accept_language}; use crate::subresource_integrity::is_response_integrity_valid; +use crossbeam_channel::{unbounded, Receiver, Sender}; use devtools_traits::DevtoolsControlMsg; use headers_core::HeaderMapExt; use headers_ext::{AccessControlExposeHeaders, ContentType, Range}; @@ -22,7 +23,6 @@ use net_traits::request::{CredentialsMode, Destination, Referrer, Request, Reque use net_traits::request::{Origin, ResponseTainting, Window}; use net_traits::response::{Response, ResponseBody, ResponseType}; use net_traits::{FetchTaskTarget, NetworkError, ReferrerPolicy}; -use servo_channel::{channel, Receiver, Sender}; use servo_url::ServoUrl; use std::borrow::Cow; use std::fs::File; @@ -540,7 +540,7 @@ fn scheme_fetch( let mut response = Response::new(url); response.headers.typed_insert(ContentType::from(mime)); - let (done_sender, done_receiver) = channel(); + let (done_sender, done_receiver) = unbounded(); *done_chan = Some((done_sender.clone(), done_receiver)); *response.body.lock().unwrap() = ResponseBody::Receiving(vec![]); diff --git a/components/net/http_cache.rs b/components/net/http_cache.rs index d467a38baf3..30694f2c8e0 100644 --- a/components/net/http_cache.rs +++ b/components/net/http_cache.rs @@ -8,6 +8,7 @@ //! and <http://tools.ietf.org/html/rfc7232>. use crate::fetch::methods::{Data, DoneChannel}; +use crossbeam_channel::{unbounded, Sender}; use headers_core::HeaderMapExt; use headers_ext::{CacheControl, ContentRange, Expires, LastModified, Pragma, Range, Vary}; use http::header::HeaderValue; @@ -21,7 +22,6 @@ use net_traits::request::Request; use net_traits::response::{HttpsState, Response, ResponseBody}; use net_traits::{FetchMetadata, Metadata}; use servo_arc::Arc; -use servo_channel::{channel, Sender}; use servo_config::prefs::PREFS; use servo_url::ServoUrl; use std::collections::HashMap; @@ -306,7 +306,7 @@ fn create_cached_response( response.headers = cached_headers.clone(); response.body = cached_resource.body.clone(); if let ResponseBody::Receiving(_) = *cached_resource.body.lock().unwrap() { - let (done_sender, done_receiver) = channel(); + let (done_sender, done_receiver) = unbounded(); *done_chan = Some((done_sender.clone(), done_receiver)); cached_resource .awaiting_body @@ -670,7 +670,7 @@ impl HttpCache { // Otherwise, create a new dedicated channel to update the consumer. // The response constructed here will replace the 304 one from the network. let in_progress_channel = match *cached_resource.body.lock().unwrap() { - ResponseBody::Receiving(..) => Some(channel()), + ResponseBody::Receiving(..) => Some(unbounded()), ResponseBody::Empty | ResponseBody::Done(..) => None, }; match in_progress_channel { diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index 0ef715361fe..000afe70ee3 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -15,6 +15,7 @@ use crate::fetch::methods::{Data, DoneChannel, FetchContext, Target}; use crate::hsts::HstsList; use crate::http_cache::HttpCache; use crate::resource_thread::AuthCache; +use crossbeam_channel::{unbounded, Sender}; use devtools_traits::{ ChromeToDevtoolsControlMsg, DevtoolsControlMsg, HttpRequest as DevtoolsHttpRequest, }; @@ -44,7 +45,6 @@ use net_traits::request::{ResponseTainting, ServiceWorkersMode}; use net_traits::response::{HttpsState, Response, ResponseBody, ResponseType}; use net_traits::{CookieSource, FetchMetadata, NetworkError, ReferrerPolicy}; use openssl::ssl::SslConnectorBuilder; -use servo_channel::{channel, Sender}; use servo_url::{ImmutableOrigin, ServoUrl}; use std::collections::{HashMap, HashSet}; use std::error::Error; @@ -1215,7 +1215,7 @@ fn http_network_fetch( let res_body = response.body.clone(); // We're about to spawn a future to be waited on here - let (done_sender, done_receiver) = channel(); + let (done_sender, done_receiver) = unbounded(); *done_chan = Some((done_sender.clone(), done_receiver)); let meta = match response .metadata() diff --git a/components/net/resource_thread.rs b/components/net/resource_thread.rs index 0ae1f548525..57550bd6c78 100644 --- a/components/net/resource_thread.rs +++ b/components/net/resource_thread.rs @@ -15,6 +15,7 @@ use crate::http_cache::HttpCache; use crate::http_loader::{http_redirect_fetch, HttpState, HANDLE}; use crate::storage_thread::StorageThreadFactory; use crate::websocket_loader; +use crossbeam_channel::Sender; use devtools_traits::DevtoolsControlMsg; use embedder_traits::resources::{self, Resource}; use embedder_traits::EmbedderProxy; @@ -32,7 +33,6 @@ use profile_traits::mem::ProfilerChan as MemProfilerChan; use profile_traits::mem::{Report, ReportKind, ReportsChan}; use profile_traits::time::ProfilerChan; use serde::{Deserialize, Serialize}; -use servo_channel::Sender; use servo_config::opts; use servo_url::ServoUrl; use std::borrow::{Cow, ToOwned}; diff --git a/components/net/tests/fetch.rs b/components/net/tests/fetch.rs index 5183c8d8ff4..a61b8a7178e 100644 --- a/components/net/tests/fetch.rs +++ b/components/net/tests/fetch.rs @@ -9,6 +9,7 @@ use crate::{ create_embedder_proxy, fetch, make_server, make_ssl_server, new_fetch_context, DEFAULT_USER_AGENT, }; +use crossbeam_channel::{unbounded, Sender}; use devtools_traits::HttpRequest as DevtoolsHttpRequest; use devtools_traits::HttpResponse as DevtoolsHttpResponse; use headers_core::HeaderMapExt; @@ -37,7 +38,6 @@ use net_traits::response::{CacheState, Response, ResponseBody, ResponseType}; use net_traits::IncludeSubdomains; use net_traits::NetworkError; use net_traits::ReferrerPolicy; -use servo_channel::{channel, Sender}; use servo_url::{ImmutableOrigin, ServoUrl}; use std::fs::File; use std::io::Read; @@ -891,7 +891,7 @@ fn test_fetch_redirect_updates_method_runner( #[test] fn test_fetch_redirect_updates_method() { - let (tx, rx) = channel(); + let (tx, rx) = unbounded(); test_fetch_redirect_updates_method_runner( tx.clone(), @@ -901,17 +901,17 @@ fn test_fetch_redirect_updates_method() { assert_eq!(rx.recv().unwrap(), true); assert_eq!(rx.recv().unwrap(), true); // make sure the test doesn't send more data than expected - assert_eq!(rx.try_recv().is_none(), true); + assert_eq!(rx.try_recv().is_err(), true); test_fetch_redirect_updates_method_runner(tx.clone(), StatusCode::FOUND, Method::POST); assert_eq!(rx.recv().unwrap(), true); assert_eq!(rx.recv().unwrap(), true); - assert_eq!(rx.try_recv().is_none(), true); + assert_eq!(rx.try_recv().is_err(), true); test_fetch_redirect_updates_method_runner(tx.clone(), StatusCode::SEE_OTHER, Method::GET); assert_eq!(rx.recv().unwrap(), true); assert_eq!(rx.recv().unwrap(), true); - assert_eq!(rx.try_recv().is_none(), true); + assert_eq!(rx.try_recv().is_err(), true); let extension = Method::from_bytes(b"FOO").unwrap(); @@ -923,18 +923,18 @@ fn test_fetch_redirect_updates_method() { assert_eq!(rx.recv().unwrap(), true); // for MovedPermanently and Found, Method should only be changed if it was Post assert_eq!(rx.recv().unwrap(), false); - assert_eq!(rx.try_recv().is_none(), true); + assert_eq!(rx.try_recv().is_err(), true); test_fetch_redirect_updates_method_runner(tx.clone(), StatusCode::FOUND, extension.clone()); assert_eq!(rx.recv().unwrap(), true); assert_eq!(rx.recv().unwrap(), false); - assert_eq!(rx.try_recv().is_none(), true); + assert_eq!(rx.try_recv().is_err(), true); test_fetch_redirect_updates_method_runner(tx.clone(), StatusCode::SEE_OTHER, extension.clone()); assert_eq!(rx.recv().unwrap(), true); // for SeeOther, Method should always be changed, so this should be true assert_eq!(rx.recv().unwrap(), true); - assert_eq!(rx.try_recv().is_none(), true); + assert_eq!(rx.try_recv().is_err(), true); } fn response_is_done(response: &Response) -> bool { @@ -1044,7 +1044,7 @@ fn test_fetch_with_devtools() { let mut request = Request::new(url.clone(), Some(origin), Some(TEST_PIPELINE_ID)); request.referrer = Referrer::NoReferrer; - let (devtools_chan, devtools_port) = channel(); + let (devtools_chan, devtools_port) = unbounded(); let _ = fetch(&mut request, Some(devtools_chan)); let _ = server.close(); diff --git a/components/net/tests/http_loader.rs b/components/net/tests/http_loader.rs index ba8f2e1a3fd..ce369c3a9d3 100644 --- a/components/net/tests/http_loader.rs +++ b/components/net/tests/http_loader.rs @@ -7,6 +7,7 @@ use crate::fetch; use crate::fetch_with_context; use crate::make_server; use crate::new_fetch_context; +use crossbeam_channel::{unbounded, Receiver}; use devtools_traits::HttpRequest as DevtoolsHttpRequest; use devtools_traits::HttpResponse as DevtoolsHttpResponse; use devtools_traits::{ChromeToDevtoolsControlMsg, DevtoolsControlMsg, NetworkEvent}; @@ -31,7 +32,6 @@ use net::test::replace_host_table; use net_traits::request::{CredentialsMode, Destination, Request, RequestInit, RequestMode}; use net_traits::response::ResponseBody; use net_traits::{CookieSource, NetworkError}; -use servo_channel::{channel, Receiver}; use servo_url::{ImmutableOrigin, ServoUrl}; use std::collections::HashMap; use std::io::Write; @@ -243,7 +243,7 @@ fn test_request_and_response_data_with_network_messages() { pipeline_id: Some(TEST_PIPELINE_ID), ..RequestInit::default() }); - let (devtools_chan, devtools_port) = channel(); + let (devtools_chan, devtools_port) = unbounded(); let response = fetch(&mut request, Some(devtools_chan)); assert!( response @@ -344,7 +344,7 @@ fn test_request_and_response_message_from_devtool_without_pipeline_id() { pipeline_id: None, ..RequestInit::default() }); - let (devtools_chan, devtools_port) = channel(); + let (devtools_chan, devtools_port) = unbounded(); let response = fetch(&mut request, Some(devtools_chan)); assert!( response @@ -359,7 +359,7 @@ fn test_request_and_response_message_from_devtool_without_pipeline_id() { let _ = server.close(); // notification received from devtools - assert!(devtools_port.try_recv().is_none()); + assert!(devtools_port.try_recv().is_err()); } #[test] @@ -388,7 +388,7 @@ fn test_redirected_request_to_devtools() { pipeline_id: Some(TEST_PIPELINE_ID), ..RequestInit::default() }); - let (devtools_chan, devtools_port) = channel(); + let (devtools_chan, devtools_port) = unbounded(); fetch(&mut request, Some(devtools_chan)); let _ = pre_server.close(); diff --git a/components/net/tests/main.rs b/components/net/tests/main.rs index 48063adad81..2015407e29a 100644 --- a/components/net/tests/main.rs +++ b/components/net/tests/main.rs @@ -19,6 +19,7 @@ mod mime_classifier; mod resource_thread; mod subresource_integrity; +use crossbeam_channel::{unbounded, Sender}; use devtools_traits::DevtoolsControlMsg; use embedder_traits::resources::{self, Resource}; use embedder_traits::{EmbedderProxy, EventLoopWaker}; @@ -36,7 +37,6 @@ use net_traits::request::Request; use net_traits::response::Response; use net_traits::FetchTaskTarget; use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod}; -use servo_channel::{channel, Sender}; use servo_url::ServoUrl; use std::net::TcpListener as StdTcpListener; use std::path::PathBuf; @@ -56,7 +56,7 @@ struct FetchResponseCollector { } fn create_embedder_proxy() -> EmbedderProxy { - let (sender, _) = channel(); + let (sender, _) = unbounded(); let event_loop_waker = || { struct DummyEventLoopWaker {} impl DummyEventLoopWaker { @@ -111,7 +111,7 @@ fn fetch(request: &mut Request, dc: Option<Sender<DevtoolsControlMsg>>) -> Respo } fn fetch_with_context(request: &mut Request, context: &FetchContext) -> Response { - let (sender, receiver) = channel(); + let (sender, receiver) = unbounded(); let mut target = FetchResponseCollector { sender: sender }; methods::fetch(request, &mut target, context); @@ -120,7 +120,7 @@ fn fetch_with_context(request: &mut Request, context: &FetchContext) -> Response } fn fetch_with_cors_cache(request: &mut Request, cache: &mut CorsCache) -> Response { - let (sender, receiver) = channel(); + let (sender, receiver) = unbounded(); let mut target = FetchResponseCollector { sender: sender }; methods::fetch_with_cors_cache(request, cache, &mut target, &new_fetch_context(None, None)); diff --git a/components/profile_traits/Cargo.toml b/components/profile_traits/Cargo.toml index 28553f59de0..6c32f23ae10 100644 --- a/components/profile_traits/Cargo.toml +++ b/components/profile_traits/Cargo.toml @@ -15,12 +15,12 @@ energy-profiling = ["energymon", "energy-monitor"] [dependencies] bincode = "1" +crossbeam-channel = "0.3" energy-monitor = {version = "0.2.0", optional = true} energymon = {git = "https://github.com/energymon/energymon-rust.git", optional = true} ipc-channel = "0.11" log = "0.4" serde = "1.0" -servo_channel = {path = "../channel"} servo_config = {path = "../config"} signpost = {git = "https://github.com/pcwalton/signpost.git"} time = "0.1.12" diff --git a/components/profile_traits/mem.rs b/components/profile_traits/mem.rs index 7b90a1274d3..fa9e2872b3e 100644 --- a/components/profile_traits/mem.rs +++ b/components/profile_traits/mem.rs @@ -6,9 +6,9 @@ #![deny(missing_docs)] +use crossbeam_channel::Sender; use ipc_channel::ipc::{self, IpcSender}; use ipc_channel::router::ROUTER; -use servo_channel::Sender; use std::marker::Send; /// A trait to abstract away the various kinds of message senders we use. diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index d2d13c2eb1b..83d827ea6a2 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -42,6 +42,7 @@ canvas_traits = {path = "../canvas_traits"} caseless = "0.2" cookie = "0.11" chrono = "0.4" +crossbeam-channel = "0.3" cssparser = "0.25" deny_public_fields = {path = "../deny_public_fields"} devtools_traits = {path = "../devtools_traits"} @@ -94,7 +95,6 @@ serde_bytes = "0.10" servo_allocator = {path = "../allocator"} servo_arc = {path = "../servo_arc"} servo_atoms = {path = "../atoms"} -servo_channel = {path = "../channel"} servo_config = {path = "../config"} servo_geometry = {path = "../geometry" } servo-media = {git = "https://github.com/servo/media"} diff --git a/components/script/dom/abstractworkerglobalscope.rs b/components/script/dom/abstractworkerglobalscope.rs index e01b98cf944..14cbabd3cf0 100644 --- a/components/script/dom/abstractworkerglobalscope.rs +++ b/components/script/dom/abstractworkerglobalscope.rs @@ -11,8 +11,8 @@ use crate::dom::worker::TrustedWorkerAddress; use crate::dom::workerglobalscope::WorkerGlobalScope; use crate::script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort}; use crate::task_queue::{QueuedTaskConversion, TaskQueue}; +use crossbeam_channel::{Receiver, Sender}; use devtools_traits::DevtoolScriptControlMsg; -use servo_channel::{Receiver, Sender}; /// A ScriptChan that can be cloned freely and will silently send a TrustedWorkerAddress with /// common event loop messages. While this SendableWorkerScriptChan is alive, the associated @@ -69,9 +69,9 @@ impl ScriptChan for WorkerThreadWorkerChan { impl ScriptPort for Receiver<DedicatedWorkerScriptMsg> { fn recv(&self) -> Result<CommonScriptMsg, ()> { let common_msg = match self.recv() { - Some(DedicatedWorkerScriptMsg::CommonWorker(_worker, common_msg)) => common_msg, - None => return Err(()), - Some(DedicatedWorkerScriptMsg::WakeUp) => panic!("unexpected worker event message!"), + Ok(DedicatedWorkerScriptMsg::CommonWorker(_worker, common_msg)) => common_msg, + Err(_) => return Err(()), + Ok(DedicatedWorkerScriptMsg::WakeUp) => panic!("unexpected worker event message!"), }; match common_msg { WorkerScriptMsg::Common(script_msg) => Ok(script_msg), @@ -108,17 +108,18 @@ pub fn run_worker_event_loop<T, TimerMsg, WorkerMsg, Event>( let scope = worker_scope.upcast::<WorkerGlobalScope>(); let timer_event_port = worker_scope.timer_event_port(); let devtools_port = match scope.from_devtools_sender() { - Some(_) => Some(scope.from_devtools_receiver().select()), + Some(_) => Some(scope.from_devtools_receiver()), None => None, }; let task_queue = worker_scope.task_queue(); let event = select! { - recv(task_queue.select(), msg) => { + recv(task_queue.select()) -> msg => { task_queue.take_tasks(msg.unwrap()); worker_scope.from_worker_msg(task_queue.recv().unwrap()) }, - recv(timer_event_port.select(), msg) => worker_scope.from_timer_msg(msg.unwrap()), - recv(devtools_port, msg) => worker_scope.from_devtools_msg(msg.unwrap()), + recv(timer_event_port) -> msg => worker_scope.from_timer_msg(msg.unwrap()), + recv(devtools_port.unwrap_or(&crossbeam_channel::never())) -> msg => + worker_scope.from_devtools_msg(msg.unwrap()), }; let mut sequential = vec![]; sequential.push(event); @@ -131,14 +132,15 @@ pub fn run_worker_event_loop<T, TimerMsg, WorkerMsg, Event>( // Batch all events that are ready. // The task queue will throttle non-priority tasks if necessary. match task_queue.try_recv() { - None => match timer_event_port.try_recv() { - None => match devtools_port.and_then(|port| port.try_recv()) { - None => break, - Some(ev) => sequential.push(worker_scope.from_devtools_msg(ev)), + Err(_) => match timer_event_port.try_recv() { + Err(_) => match devtools_port.map(|port| port.try_recv()) { + None => {}, + Some(Err(_)) => break, + Some(Ok(ev)) => sequential.push(worker_scope.from_devtools_msg(ev)), }, - Some(ev) => sequential.push(worker_scope.from_timer_msg(ev)), + Ok(ev) => sequential.push(worker_scope.from_timer_msg(ev)), }, - Some(ev) => sequential.push(worker_scope.from_worker_msg(ev)), + Ok(ev) => sequential.push(worker_scope.from_worker_msg(ev)), } } // Step 3 diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index f3cc904e807..c1b059b0ea0 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -49,6 +49,7 @@ use crate::dom::bindings::utils::WindowProxyHandler; use crate::dom::document::PendingRestyle; use crate::dom::htmlimageelement::SourceSet; use crate::dom::htmlmediaelement::MediaFrameRenderer; +use crossbeam_channel::{Receiver, Sender}; use cssparser::RGBA; use devtools_traits::{CSSError, TimelineMarkerType, WorkerId}; use encoding_rs::{Decoder, Encoding}; @@ -93,7 +94,6 @@ use selectors::matching::ElementSelectorFlags; use serde::{Deserialize, Serialize}; use servo_arc::Arc as ServoArc; use servo_atoms::Atom; -use servo_channel::{Receiver, Sender}; use servo_media::audio::analyser_node::AnalysisEngine; use servo_media::audio::buffer_source_node::AudioBuffer; use servo_media::audio::context::AudioContext; diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index f9a3debe9b4..362177ea72b 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -26,6 +26,7 @@ use crate::script_runtime::ScriptThreadEventCategory::WorkerEvent; use crate::script_runtime::{new_rt_and_cx, CommonScriptMsg, Runtime, ScriptChan, ScriptPort}; use crate::task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue}; use crate::task_source::TaskSourceName; +use crossbeam_channel::{unbounded, Receiver, Sender}; use devtools_traits::DevtoolScriptControlMsg; use dom_struct::dom_struct; use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; @@ -38,7 +39,6 @@ use msg::constellation_msg::TopLevelBrowsingContextId; use net_traits::request::{CredentialsMode, Destination, RequestInit}; use net_traits::{load_whole_resource, IpcSend}; use script_traits::{TimerEvent, TimerSource, WorkerGlobalScopeInit, WorkerScriptLoadOrigin}; -use servo_channel::{channel, route_ipc_receiver_to_new_servo_sender, Receiver, Sender}; use servo_rand::random; use servo_url::ServoUrl; use std::mem::replace; @@ -329,10 +329,13 @@ impl DedicatedWorkerGlobalScope { let runtime = unsafe { new_rt_and_cx() }; - let (devtools_mpsc_chan, devtools_mpsc_port) = channel(); - route_ipc_receiver_to_new_servo_sender(from_devtools_receiver, devtools_mpsc_chan); + let (devtools_mpsc_chan, devtools_mpsc_port) = unbounded(); + ROUTER.route_ipc_receiver_to_crossbeam_sender( + from_devtools_receiver, + devtools_mpsc_chan, + ); - let (timer_tx, timer_rx) = channel(); + let (timer_tx, timer_rx) = unbounded(); let (timer_ipc_chan, timer_ipc_port) = ipc::channel().unwrap(); let worker_for_route = worker.clone(); ROUTER.add_route( @@ -404,7 +407,7 @@ impl DedicatedWorkerGlobalScope { } pub fn new_script_pair(&self) -> (Box<dyn ScriptChan + Send>, Box<dyn ScriptPort + Send>) { - let (tx, rx) = channel(); + let (tx, rx) = unbounded(); let chan = Box::new(SendableWorkerScriptChan { sender: tx, worker: self.worker.borrow().as_ref().unwrap().clone(), diff --git a/components/script/dom/paintworkletglobalscope.rs b/components/script/dom/paintworkletglobalscope.rs index 6a9a517298f..61eaabb1b03 100644 --- a/components/script/dom/paintworkletglobalscope.rs +++ b/components/script/dom/paintworkletglobalscope.rs @@ -23,6 +23,7 @@ use crate::dom::worklet::WorkletExecutor; use crate::dom::workletglobalscope::WorkletGlobalScope; use crate::dom::workletglobalscope::WorkletGlobalScopeInit; use crate::dom::workletglobalscope::WorkletTask; +use crossbeam_channel::{unbounded, Sender}; use dom_struct::dom_struct; use euclid::TypedScale; use euclid::TypedSize2D; @@ -49,8 +50,6 @@ use profile_traits::ipc; use script_traits::Painter; use script_traits::{DrawAPaintImageResult, PaintWorkletError}; use servo_atoms::Atom; -use servo_channel::base_channel; -use servo_channel::{channel, Sender}; use servo_config::prefs::PREFS; use servo_url::ServoUrl; use std::cell::Cell; @@ -426,7 +425,7 @@ impl PaintWorkletGlobalScope { arguments: Vec<String>, ) -> Result<DrawAPaintImageResult, PaintWorkletError> { let name = self.name.clone(); - let (sender, receiver) = channel(); + let (sender, receiver) = unbounded(); let task = PaintWorkletTask::DrawAPaintImage( name, size, @@ -445,12 +444,9 @@ impl PaintWorkletGlobalScope { .as_u64() .unwrap_or(10u64); - select! { - recv(base_channel::after(Duration::from_millis(timeout))) => { - Err(PaintWorkletError::Timeout) - } - recv(receiver.select(), msg) => msg.ok_or(PaintWorkletError::Timeout) - } + receiver + .recv_timeout(Duration::from_millis(timeout)) + .map_err(|e| PaintWorkletError::from(e)) } } Box::new(WorkletPainter { diff --git a/components/script/dom/serviceworkerglobalscope.rs b/components/script/dom/serviceworkerglobalscope.rs index 45e8934d0de..6916cd41f96 100644 --- a/components/script/dom/serviceworkerglobalscope.rs +++ b/components/script/dom/serviceworkerglobalscope.rs @@ -22,9 +22,11 @@ use crate::dom::workerglobalscope::WorkerGlobalScope; use crate::script_runtime::{new_rt_and_cx, CommonScriptMsg, Runtime, ScriptChan}; use crate::task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue}; use crate::task_source::TaskSourceName; +use crossbeam_channel::{unbounded, Receiver, Sender}; use devtools_traits::DevtoolScriptControlMsg; use dom_struct::dom_struct; use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; +use ipc_channel::router::ROUTER; use js::jsapi::{JSAutoCompartment, JSContext, JS_AddInterruptCallback}; use js::jsval::UndefinedValue; use net_traits::request::{CredentialsMode, Destination, RequestInit}; @@ -32,7 +34,6 @@ use net_traits::{load_whole_resource, CustomResponseMediator, IpcSend}; use script_traits::{ ScopeThings, ServiceWorkerMsg, TimerEvent, WorkerGlobalScopeInit, WorkerScriptLoadOrigin, }; -use servo_channel::{channel, route_ipc_receiver_to_new_servo_sender, Receiver, Sender}; use servo_config::prefs::PREFS; use servo_rand::random; use servo_url::ServoUrl; @@ -293,11 +294,12 @@ impl ServiceWorkerGlobalScope { let runtime = unsafe { new_rt_and_cx() }; - let (devtools_mpsc_chan, devtools_mpsc_port) = channel(); - route_ipc_receiver_to_new_servo_sender(devtools_receiver, devtools_mpsc_chan); + let (devtools_mpsc_chan, devtools_mpsc_port) = unbounded(); + ROUTER + .route_ipc_receiver_to_crossbeam_sender(devtools_receiver, devtools_mpsc_chan); // TODO XXXcreativcoder use this timer_ipc_port, when we have a service worker instance here let (timer_ipc_chan, _timer_ipc_port) = ipc::channel().unwrap(); - let (timer_chan, timer_port) = channel(); + let (timer_chan, timer_port) = unbounded(); let global = ServiceWorkerGlobalScope::new( init, url, diff --git a/components/script/dom/servoparser/async_html.rs b/components/script/dom/servoparser/async_html.rs index d982c75e975..39b94c9c644 100644 --- a/components/script/dom/servoparser/async_html.rs +++ b/components/script/dom/servoparser/async_html.rs @@ -20,6 +20,7 @@ use crate::dom::node::Node; use crate::dom::processinginstruction::ProcessingInstruction; use crate::dom::servoparser::{create_element_for_token, ElementAttribute, ParsingAlgorithm}; use crate::dom::virtualmethods::vtable_for; +use crossbeam_channel::{unbounded, Receiver, Sender}; use html5ever::buffer_queue::BufferQueue; use html5ever::tendril::fmt::UTF8; use html5ever::tendril::{SendTendril, StrTendril, Tendril}; @@ -29,7 +30,6 @@ use html5ever::tree_builder::{ }; use html5ever::tree_builder::{TreeBuilder, TreeBuilderOpts}; use html5ever::{Attribute as HtmlAttribute, ExpandedName, QualName}; -use servo_channel::{channel, Receiver, Sender}; use servo_url::ServoUrl; use std::borrow::Cow; use std::cell::Cell; @@ -215,9 +215,9 @@ impl Tokenizer { fragment_context: Option<super::FragmentContext>, ) -> Self { // Messages from the Tokenizer (main thread) to HtmlTokenizer (parser thread) - let (to_html_tokenizer_sender, html_tokenizer_receiver) = channel(); + let (to_html_tokenizer_sender, html_tokenizer_receiver) = unbounded(); // Messages from HtmlTokenizer and Sink (parser thread) to Tokenizer (main thread) - let (to_tokenizer_sender, tokenizer_receiver) = channel(); + let (to_tokenizer_sender, tokenizer_receiver) = unbounded(); let mut tokenizer = Tokenizer { document: Dom::from_ref(document), diff --git a/components/script/dom/testworkletglobalscope.rs b/components/script/dom/testworkletglobalscope.rs index e443dfa8e6b..a7e6f4f9de5 100644 --- a/components/script/dom/testworkletglobalscope.rs +++ b/components/script/dom/testworkletglobalscope.rs @@ -10,10 +10,10 @@ use crate::dom::bindings::str::DOMString; use crate::dom::worklet::WorkletExecutor; use crate::dom::workletglobalscope::WorkletGlobalScope; use crate::dom::workletglobalscope::WorkletGlobalScopeInit; +use crossbeam_channel::Sender; use dom_struct::dom_struct; use js::rust::Runtime; use msg::constellation_msg::PipelineId; -use servo_channel::Sender; use servo_url::ServoUrl; use std::collections::HashMap; diff --git a/components/script/dom/vrdisplay.rs b/components/script/dom/vrdisplay.rs index 1cf43df4553..312ee71a9a3 100644 --- a/components/script/dom/vrdisplay.rs +++ b/components/script/dom/vrdisplay.rs @@ -33,11 +33,11 @@ use crate::dom::webglrenderingcontext::WebGLRenderingContext; use crate::script_runtime::CommonScriptMsg; use crate::script_runtime::ScriptThreadEventCategory::WebVREvent; use crate::task_source::TaskSourceName; +use crossbeam_channel::{unbounded, Sender}; use dom_struct::dom_struct; use ipc_channel::ipc::IpcSender; use profile_traits::ipc; use serde_bytes::ByteBuf; -use servo_channel::{channel, Sender}; use std::cell::Cell; use std::mem; use std::ops::Deref; @@ -538,7 +538,7 @@ impl VRDisplay { thread::Builder::new() .name("WebVR_RAF".into()) .spawn(move || { - let (raf_sender, raf_receiver) = channel(); + let (raf_sender, raf_receiver) = unbounded(); let mut near = near_init; let mut far = far_init; diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 51c379145c2..a8a9ce1d960 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -68,6 +68,7 @@ use crate::task_manager::TaskManager; use crate::task_source::TaskSourceName; use crate::timers::{IsInterval, TimerCallback}; use crate::webdriver_handlers::jsval_to_webdriver; +use crossbeam_channel::{unbounded, Sender, TryRecvError}; use cssparser::{Parser, ParserInput}; use devtools_traits::{ScriptToDevtoolsControlMsg, TimelineMarker, TimelineMarkerType}; use dom_struct::dom_struct; @@ -104,7 +105,6 @@ use script_traits::{ConstellationControlMsg, DocumentState, LoadData}; use script_traits::{ScriptMsg, ScriptToConstellationChan, ScrollState, TimerEvent, TimerEventId}; use script_traits::{TimerSchedulerMsg, UntrustedNodeAddress, WindowSizeData, WindowSizeType}; use selectors::attr::CaseSensitivity; -use servo_channel::{channel, Sender}; use servo_config::opts; use servo_geometry::{f32_rect_to_au_rect, MaxRect}; use servo_url::{Host, ImmutableOrigin, MutableOrigin, ServoUrl}; @@ -348,7 +348,7 @@ impl Window { } pub fn new_script_pair(&self) -> (Box<dyn ScriptChan + Send>, Box<dyn ScriptPort + Send>) { - let (tx, rx) = channel(); + let (tx, rx) = unbounded(); (Box::new(SendableMainThreadScriptChan(tx)), Box::new(rx)) } @@ -1394,7 +1394,7 @@ impl Window { }; // Layout will let us know when it's done. - let (join_chan, join_port) = channel(); + let (join_chan, join_port) = unbounded(); // On debug mode, print the reflow event information. if opts::get().relayout_event { @@ -1427,16 +1427,15 @@ impl Window { debug!("script: layout forked"); - let complete = select! { - recv(join_port.select(), msg) => if let Some(reflow_complete) = msg { - reflow_complete - } else { - panic!("Layout thread failed while script was waiting for a result."); - }, - default => { + let complete = match join_port.try_recv() { + Err(TryRecvError::Empty) => { info!("script: waiting on layout"); join_port.recv().unwrap() - } + }, + Ok(reflow_complete) => reflow_complete, + Err(TryRecvError::Disconnected) => { + panic!("Layout thread failed while script was waiting for a result."); + }, }; debug!("script: layout joined"); @@ -2033,7 +2032,7 @@ impl Window { webrender_api_sender: RenderApiSender, ) -> DomRoot<Self> { let layout_rpc: Box<dyn LayoutRPC + Send> = { - let (rpc_send, rpc_recv) = channel(); + let (rpc_send, rpc_recv) = unbounded(); layout_chan.send(Msg::GetRPC(rpc_send)).unwrap(); rpc_recv.recv().unwrap() }; diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs index 957d630ece1..ca55ba8ee98 100644 --- a/components/script/dom/worker.rs +++ b/components/script/dom/worker.rs @@ -21,6 +21,7 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::messageevent::MessageEvent; use crate::dom::workerglobalscope::prepare_workerscope_init; use crate::task::TaskOnce; +use crossbeam_channel::{unbounded, Sender}; use devtools_traits::{DevtoolsPageInfo, ScriptToDevtoolsControlMsg}; use dom_struct::dom_struct; use ipc_channel::ipc; @@ -28,7 +29,6 @@ use js::jsapi::{JSAutoCompartment, JSContext, JS_RequestInterruptCallback}; use js::jsval::UndefinedValue; use js::rust::HandleValue; use script_traits::WorkerScriptLoadOrigin; -use servo_channel::{channel, Sender}; use std::cell::Cell; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; @@ -79,7 +79,7 @@ impl Worker { Err(_) => return Err(Error::Syntax), }; - let (sender, receiver) = channel(); + let (sender, receiver) = unbounded(); let closing = Arc::new(AtomicBool::new(false)); let worker = Worker::new(global, sender.clone(), closing.clone()); global.track_worker(closing.clone()); diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index 015c18f2644..59307e5700d 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -32,6 +32,7 @@ use crate::task_source::performance_timeline::PerformanceTimelineTaskSource; use crate::task_source::remote_event::RemoteEventTaskSource; use crate::task_source::websocket::WebsocketTaskSource; use crate::timers::{IsInterval, TimerCallback}; +use crossbeam_channel::Receiver; use devtools_traits::{DevtoolScriptControlMsg, WorkerId}; use dom_struct::dom_struct; use ipc_channel::ipc::IpcSender; @@ -44,7 +45,6 @@ use net_traits::request::{CredentialsMode, Destination, RequestInit as NetReques use net_traits::{load_whole_resource, IpcSend}; use script_traits::WorkerGlobalScopeInit; use script_traits::{TimerEvent, TimerEventId}; -use servo_channel::Receiver; use servo_url::{MutableOrigin, ServoUrl}; use std::default::Default; use std::rc::Rc; diff --git a/components/script/dom/worklet.rs b/components/script/dom/worklet.rs index 48405c626fb..312c362e61e 100644 --- a/components/script/dom/worklet.rs +++ b/components/script/dom/worklet.rs @@ -39,6 +39,7 @@ use crate::script_runtime::ScriptThreadEventCategory; use crate::script_thread::{MainThreadScriptMsg, ScriptThread}; use crate::task::TaskBox; use crate::task_source::TaskSourceName; +use crossbeam_channel::{unbounded, Receiver, Sender}; use dom_struct::dom_struct; use js::jsapi::JSGCParamKey; use js::jsapi::JSTracer; @@ -50,7 +51,6 @@ use net_traits::request::Destination; use net_traits::request::RequestInit; use net_traits::request::RequestMode; use net_traits::IpcSend; -use servo_channel::{channel, Receiver, Sender}; use servo_url::ImmutableOrigin; use servo_url::ServoUrl; use std::cmp::max; @@ -334,7 +334,7 @@ impl WorkletThreadPool { /// For testing. pub fn test_worklet_lookup(&self, id: WorkletId, key: String) -> Option<String> { - let (sender, receiver) = channel(); + let (sender, receiver) = unbounded(); let msg = WorkletData::Task(id, WorkletTask::Test(TestWorkletTask::Lookup(key, sender))); let _ = self.primary_sender.send(msg); receiver.recv().expect("Test worklet has died?") @@ -388,7 +388,7 @@ struct WorkletThreadRole { impl WorkletThreadRole { fn new(is_hot_backup: bool, is_cold_backup: bool) -> WorkletThreadRole { - let (sender, receiver) = channel(); + let (sender, receiver) = unbounded(); WorkletThreadRole { sender: sender, receiver: receiver, @@ -452,7 +452,7 @@ impl WorkletThread { #[allow(unsafe_code)] #[allow(unrooted_must_root)] fn spawn(role: WorkletThreadRole, init: WorkletThreadInit) -> Sender<WorkletControl> { - let (control_sender, control_receiver) = channel(); + let (control_sender, control_receiver) = unbounded(); // TODO: name this thread thread::spawn(move || { // TODO: add a new IN_WORKLET thread state? @@ -522,12 +522,12 @@ impl WorkletThread { if let Some(control) = self.control_buffer.take() { self.process_control(control); } - while let Some(control) = self.control_receiver.try_recv() { + while let Ok(control) = self.control_receiver.try_recv() { self.process_control(control); } self.gc(); } else if self.control_buffer.is_none() { - if let Some(control) = self.control_receiver.try_recv() { + if let Ok(control) = self.control_receiver.try_recv() { self.control_buffer = Some(control); let msg = WorkletData::StartSwapRoles(self.role.sender.clone()); let _ = self.cold_backup_sender.send(msg); diff --git a/components/script/dom/workletglobalscope.rs b/components/script/dom/workletglobalscope.rs index 3d971390614..65b837ac350 100644 --- a/components/script/dom/workletglobalscope.rs +++ b/components/script/dom/workletglobalscope.rs @@ -11,6 +11,7 @@ use crate::dom::testworkletglobalscope::TestWorkletGlobalScope; use crate::dom::testworkletglobalscope::TestWorkletTask; use crate::dom::worklet::WorkletExecutor; use crate::script_thread::MainThreadScriptMsg; +use crossbeam_channel::Sender; use devtools_traits::ScriptToDevtoolsControlMsg; use dom_struct::dom_struct; use ipc_channel::ipc; @@ -26,7 +27,6 @@ use profile_traits::time; use script_traits::{Painter, ScriptMsg}; use script_traits::{ScriptToConstellationChan, TimerSchedulerMsg}; use servo_atoms::Atom; -use servo_channel::Sender; use servo_url::ImmutableOrigin; use servo_url::MutableOrigin; use servo_url::ServoUrl; diff --git a/components/script/lib.rs b/components/script/lib.rs index 8d591886a52..132115d9e4e 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -20,6 +20,8 @@ #[macro_use] extern crate bitflags; #[macro_use] +extern crate crossbeam_channel; +#[macro_use] extern crate cssparser; #[macro_use] extern crate deny_public_fields; @@ -46,8 +48,6 @@ extern crate profile_traits; #[macro_use] extern crate servo_atoms; #[macro_use] -extern crate servo_channel; -#[macro_use] extern crate style; #[macro_use] diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index fe102a0a7b3..4b866f6d996 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -83,6 +83,7 @@ use crate::task_source::user_interaction::UserInteractionTaskSource; use crate::task_source::websocket::WebsocketTaskSource; use crate::task_source::TaskSourceName; use crate::webdriver_handlers; +use crossbeam_channel::{unbounded, Receiver, Sender}; use devtools_traits::CSSError; use devtools_traits::{DevtoolScriptControlMsg, DevtoolsPageInfo}; use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId}; @@ -93,6 +94,7 @@ use headers_ext::LastModified; use headers_ext::ReferrerPolicy as ReferrerPolicyHeader; use hyper_serde::Serde; use ipc_channel::ipc::{self, IpcSender}; +use ipc_channel::router::ROUTER; use js::glue::GetWindowProxyClass; use js::jsapi::{JSAutoCompartment, JSContext, JS_SetWrapObjectCallbacks}; use js::jsapi::{JSTracer, SetWindowProxyClass}; @@ -122,10 +124,6 @@ use script_traits::{ScriptToConstellationChan, TimerEvent, TimerSchedulerMsg}; use script_traits::{TimerSource, TouchEventType, TouchId, UntrustedNodeAddress}; use script_traits::{UpdatePipelineIdReason, WindowSizeData, WindowSizeType}; use servo_atoms::Atom; -use servo_channel::{channel, Receiver, Sender}; -use servo_channel::{ - route_ipc_receiver_to_new_servo_receiver, route_ipc_receiver_to_new_servo_sender, -}; use servo_config::opts; use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl}; use std::cell::Cell; @@ -321,39 +319,39 @@ impl OpaqueSender<CommonScriptMsg> for Box<dyn ScriptChan + Send> { impl ScriptPort for Receiver<CommonScriptMsg> { fn recv(&self) -> Result<CommonScriptMsg, ()> { - self.recv().ok_or(()) + self.recv().map_err(|_| ()) } } impl ScriptPort for Receiver<MainThreadScriptMsg> { fn recv(&self) -> Result<CommonScriptMsg, ()> { match self.recv() { - Some(MainThreadScriptMsg::Common(script_msg)) => Ok(script_msg), - Some(_) => panic!("unexpected main thread event message!"), - None => Err(()), + Ok(MainThreadScriptMsg::Common(script_msg)) => Ok(script_msg), + Ok(_) => panic!("unexpected main thread event message!"), + Err(_) => Err(()), } } } impl ScriptPort for Receiver<(TrustedWorkerAddress, CommonScriptMsg)> { fn recv(&self) -> Result<CommonScriptMsg, ()> { - self.recv().map(|(_, msg)| msg).ok_or(()) + self.recv().map(|(_, msg)| msg).map_err(|_| ()) } } impl ScriptPort for Receiver<(TrustedWorkerAddress, MainThreadScriptMsg)> { fn recv(&self) -> Result<CommonScriptMsg, ()> { match self.recv().map(|(_, msg)| msg) { - Some(MainThreadScriptMsg::Common(script_msg)) => Ok(script_msg), - Some(_) => panic!("unexpected main thread event message!"), - None => Err(()), + Ok(MainThreadScriptMsg::Common(script_msg)) => Ok(script_msg), + Ok(_) => panic!("unexpected main thread event message!"), + Err(_) => Err(()), } } } impl ScriptPort for Receiver<(TrustedServiceWorkerAddress, CommonScriptMsg)> { fn recv(&self) -> Result<CommonScriptMsg, ()> { - self.recv().map(|(_, msg)| msg).ok_or(()) + self.recv().map(|(_, msg)| msg).map_err(|_| ()) } } @@ -648,9 +646,9 @@ impl ScriptThreadFactory for ScriptThread { state: InitialScriptState, load_data: LoadData, ) -> (Sender<message::Msg>, Receiver<message::Msg>) { - let (script_chan, script_port) = channel(); + let (script_chan, script_port) = unbounded(); - let (sender, receiver) = channel(); + let (sender, receiver) = unbounded(); let layout_chan = sender.clone(); thread::Builder::new() .name(format!("ScriptThread {:?}", state.id)) @@ -1004,16 +1002,17 @@ impl ScriptThread { // Ask the router to proxy IPC messages from the devtools to us. let (ipc_devtools_sender, ipc_devtools_receiver) = ipc::channel().unwrap(); - let devtools_port = route_ipc_receiver_to_new_servo_receiver(ipc_devtools_receiver); + let devtools_port = + ROUTER.route_ipc_receiver_to_new_crossbeam_receiver(ipc_devtools_receiver); - let (timer_event_chan, timer_event_port) = channel(); + let (timer_event_chan, timer_event_port) = unbounded(); // Ask the router to proxy IPC messages from the control port to us. - let control_port = route_ipc_receiver_to_new_servo_receiver(state.control_port); + let control_port = ROUTER.route_ipc_receiver_to_new_crossbeam_receiver(state.control_port); let boxed_script_sender = Box::new(MainThreadScriptChan(chan.clone())); - let (image_cache_channel, image_cache_port) = channel(); + let (image_cache_channel, image_cache_port) = unbounded(); let task_queue = TaskQueue::new(port, chan.clone()); @@ -1130,14 +1129,15 @@ impl ScriptThread { // Receive at least one message so we don't spinloop. debug!("Waiting for event."); let mut event = select! { - recv(self.task_queue.select(), msg) => { + recv(self.task_queue.select()) -> msg => { self.task_queue.take_tasks(msg.unwrap()); FromScript(self.task_queue.recv().unwrap()) }, - recv(self.control_port.select(), msg) => FromConstellation(msg.unwrap()), - recv(self.timer_event_port.select(), msg) => FromScheduler(msg.unwrap()), - recv(self.devtools_chan.as_ref().map(|_| self.devtools_port.select()), msg) => FromDevtools(msg.unwrap()), - recv(self.image_cache_port.select(), msg) => FromImageCache(msg.unwrap()), + recv(self.control_port) -> msg => FromConstellation(msg.unwrap()), + recv(self.timer_event_port) -> msg => FromScheduler(msg.unwrap()), + recv(self.devtools_chan.as_ref().map(|_| &self.devtools_port).unwrap_or(&crossbeam_channel::never())) -> msg + => FromDevtools(msg.unwrap()), + recv(self.image_cache_port) -> msg => FromImageCache(msg.unwrap()), }; debug!("Got event."); @@ -1221,20 +1221,20 @@ impl ScriptThread { // and check for more resize events. If there are no events pending, we'll move // on and execute the sequential non-resize events we've seen. match self.control_port.try_recv() { - None => match self.task_queue.try_recv() { - None => match self.timer_event_port.try_recv() { - None => match self.devtools_port.try_recv() { - None => match self.image_cache_port.try_recv() { - None => break, - Some(ev) => event = FromImageCache(ev), + Err(_) => match self.task_queue.try_recv() { + Err(_) => match self.timer_event_port.try_recv() { + Err(_) => match self.devtools_port.try_recv() { + Err(_) => match self.image_cache_port.try_recv() { + Err(_) => break, + Ok(ev) => event = FromImageCache(ev), }, - Some(ev) => event = FromDevtools(ev), + Ok(ev) => event = FromDevtools(ev), }, - Some(ev) => event = FromScheduler(ev), + Ok(ev) => event = FromScheduler(ev), }, - Some(ev) => event = FromScript(ev), + Ok(ev) => event = FromScript(ev), }, - Some(ev) => event = FromConstellation(ev), + Ok(ev) => event = FromConstellation(ev), } } @@ -1843,7 +1843,7 @@ impl ScriptThread { layout_threads, } = new_layout_info; - let layout_pair = channel(); + let layout_pair = unbounded(); let layout_chan = layout_pair.0.clone(); let msg = message::Msg::CreateLayoutThread(NewLayoutThreadInfo { @@ -2253,7 +2253,7 @@ impl ScriptThread { // We shut down layout before removing the document, // since layout might still be in the middle of laying it out. debug!("preparing to shut down layout for page {}", id); - let (response_chan, response_port) = channel(); + let (response_chan, response_port) = unbounded(); chan.send(message::Msg::PrepareToExit(response_chan)).ok(); let _ = response_port.recv(); @@ -2571,7 +2571,10 @@ impl ScriptThread { let MainThreadScriptChan(ref sender) = self.chan; let (ipc_timer_event_chan, ipc_timer_event_port) = ipc::channel().unwrap(); - route_ipc_receiver_to_new_servo_sender(ipc_timer_event_port, self.timer_event_chan.clone()); + ROUTER.route_ipc_receiver_to_crossbeam_sender( + ipc_timer_event_port, + self.timer_event_chan.clone(), + ); let origin = if final_url.as_str() == "about:blank" { incomplete.origin.clone() diff --git a/components/script/serviceworker_manager.rs b/components/script/serviceworker_manager.rs index 198c230adf9..f269e6b23be 100644 --- a/components/script/serviceworker_manager.rs +++ b/components/script/serviceworker_manager.rs @@ -11,11 +11,12 @@ use crate::dom::abstractworker::WorkerScriptMsg; use crate::dom::bindings::structuredclone::StructuredCloneData; use crate::dom::serviceworkerglobalscope::{ServiceWorkerGlobalScope, ServiceWorkerScriptMsg}; use crate::dom::serviceworkerregistration::longest_prefix_match; +use crossbeam_channel::{unbounded, Receiver, RecvError, Sender}; use devtools_traits::{DevtoolsPageInfo, ScriptToDevtoolsControlMsg}; use ipc_channel::ipc::{self, IpcSender}; +use ipc_channel::router::ROUTER; use net_traits::{CoreResourceMsg, CustomResponseMediator}; use script_traits::{DOMMessage, SWManagerMsg, SWManagerSenders, ScopeThings, ServiceWorkerMsg}; -use servo_channel::{channel, route_ipc_receiver_to_new_servo_receiver, Receiver, Sender}; use servo_config::prefs::PREFS; use servo_url::ServoUrl; use std::collections::HashMap; @@ -58,8 +59,8 @@ impl ServiceWorkerManager { let (own_sender, from_constellation_receiver) = ipc::channel().unwrap(); let (resource_chan, resource_port) = ipc::channel().unwrap(); let from_constellation = - route_ipc_receiver_to_new_servo_receiver(from_constellation_receiver); - let resource_port = route_ipc_receiver_to_new_servo_receiver(resource_port); + ROUTER.route_ipc_receiver_to_new_crossbeam_receiver(from_constellation_receiver); + let resource_port = ROUTER.route_ipc_receiver_to_new_crossbeam_receiver(resource_port); let _ = sw_senders .resource_sender .send(CoreResourceMsg::NetworkMediator(resource_chan)); @@ -90,7 +91,7 @@ impl ServiceWorkerManager { ) -> Option<Sender<ServiceWorkerScriptMsg>> { let scope_things = self.registered_workers.get(&scope_url); if let Some(scope_things) = scope_things { - let (sender, receiver) = channel(); + let (sender, receiver) = unbounded(); let (devtools_sender, devtools_receiver) = ipc::channel().unwrap(); if let Some(ref chan) = scope_things.devtools_chan { let title = format!("ServiceWorker for {}", scope_things.script_url); @@ -122,7 +123,7 @@ impl ServiceWorkerManager { } fn handle_message(&mut self) { - while let Some(message) = self.receive_message() { + while let Ok(message) = self.receive_message() { let should_continue = match message { Message::FromConstellation(msg) => self.handle_message_from_constellation(msg), Message::FromResource(msg) => self.handle_message_from_resource(msg), @@ -196,10 +197,10 @@ impl ServiceWorkerManager { true } - fn receive_message(&mut self) -> Option<Message> { + fn receive_message(&mut self) -> Result<Message, RecvError> { select! { - recv(self.own_port.select(), msg) => msg.map(Message::FromConstellation), - recv(self.resource_receiver.select(), msg) => msg.map(Message::FromResource), + recv(self.own_port) -> msg => msg.map(Message::FromConstellation), + recv(self.resource_receiver) -> msg => msg.map(Message::FromResource), } } } diff --git a/components/script/task_queue.rs b/components/script/task_queue.rs index 4d5d041f24c..04d47de5ac7 100644 --- a/components/script/task_queue.rs +++ b/components/script/task_queue.rs @@ -9,8 +9,8 @@ use crate::dom::worker::TrustedWorkerAddress; use crate::script_runtime::ScriptThreadEventCategory; use crate::task::TaskBox; use crate::task_source::TaskSourceName; +use crossbeam_channel::{self, Receiver, Sender}; use msg::constellation_msg::PipelineId; -use servo_channel::{base_channel, Receiver, Sender}; use std::cell::Cell; use std::collections::{HashMap, VecDeque}; use std::default::Default; @@ -63,7 +63,7 @@ impl<T: QueuedTaskConversion> TaskQueue<T> { if !first_msg.is_wake_up() { incoming.push(first_msg); } - while let Some(msg) = self.port.try_recv() { + while let Ok(msg) = self.port.try_recv() { if !msg.is_wake_up() { incoming.push(msg); } @@ -110,21 +110,21 @@ impl<T: QueuedTaskConversion> TaskQueue<T> { /// Reset the queue for a new iteration of the event-loop, /// returning the port about whose readiness we want to be notified. - pub fn select(&self) -> &base_channel::Receiver<T> { + pub fn select(&self) -> &crossbeam_channel::Receiver<T> { // This is a new iteration of the event-loop, so we reset the "business" counter. self.taken_task_counter.set(0); // We want to be notified when the script-port is ready to receive. // Hence that's the one we need to include in the select. - self.port.select() + &self.port } /// Take a message from the front of the queue, without waiting if empty. - pub fn recv(&self) -> Option<T> { - self.msg_queue.borrow_mut().pop_front() + pub fn recv(&self) -> Result<T, ()> { + self.msg_queue.borrow_mut().pop_front().ok_or(()) } /// Same as recv. - pub fn try_recv(&self) -> Option<T> { + pub fn try_recv(&self) -> Result<T, ()> { self.recv() } diff --git a/components/script/task_source/history_traversal.rs b/components/script/task_source/history_traversal.rs index aa6877c9379..e0a2bfde2ae 100644 --- a/components/script/task_source/history_traversal.rs +++ b/components/script/task_source/history_traversal.rs @@ -6,8 +6,8 @@ use crate::script_runtime::{CommonScriptMsg, ScriptThreadEventCategory}; use crate::script_thread::MainThreadScriptMsg; use crate::task::{TaskCanceller, TaskOnce}; use crate::task_source::{TaskSource, TaskSourceName}; +use crossbeam_channel::Sender; use msg::constellation_msg::PipelineId; -use servo_channel::Sender; #[derive(Clone, JSTraceable)] pub struct HistoryTraversalTaskSource(pub Sender<MainThreadScriptMsg>, pub PipelineId); diff --git a/components/script/task_source/media_element.rs b/components/script/task_source/media_element.rs index d57368ecae1..aa49828d9b6 100644 --- a/components/script/task_source/media_element.rs +++ b/components/script/task_source/media_element.rs @@ -11,9 +11,9 @@ use crate::script_runtime::{CommonScriptMsg, ScriptThreadEventCategory}; use crate::script_thread::MainThreadScriptMsg; use crate::task::{TaskCanceller, TaskOnce}; use crate::task_source::{TaskSource, TaskSourceName}; +use crossbeam_channel::Sender; use msg::constellation_msg::PipelineId; use servo_atoms::Atom; -use servo_channel::Sender; use std::fmt; use std::result::Result; diff --git a/components/script/task_source/user_interaction.rs b/components/script/task_source/user_interaction.rs index fcf6a39e17b..0fd9dd400b2 100644 --- a/components/script/task_source/user_interaction.rs +++ b/components/script/task_source/user_interaction.rs @@ -11,9 +11,9 @@ use crate::script_runtime::{CommonScriptMsg, ScriptThreadEventCategory}; use crate::script_thread::MainThreadScriptMsg; use crate::task::{TaskCanceller, TaskOnce}; use crate::task_source::{TaskSource, TaskSourceName}; +use crossbeam_channel::Sender; use msg::constellation_msg::PipelineId; use servo_atoms::Atom; -use servo_channel::Sender; use std::fmt; use std::result::Result; diff --git a/components/script_layout_interface/Cargo.toml b/components/script_layout_interface/Cargo.toml index b41b501138f..ec88d901742 100644 --- a/components/script_layout_interface/Cargo.toml +++ b/components/script_layout_interface/Cargo.toml @@ -15,6 +15,7 @@ app_units = "0.7" atomic_refcell = "0.1" canvas_traits = {path = "../canvas_traits"} cssparser = "0.25" +crossbeam-channel = "0.3" euclid = "0.19" gfx_traits = {path = "../gfx_traits"} html5ever = "0.22" @@ -33,7 +34,6 @@ script_traits = {path = "../script_traits"} selectors = { path = "../selectors" } servo_arc = {path = "../servo_arc"} servo_atoms = {path = "../atoms"} -servo_channel = {path = "../channel"} servo_url = {path = "../url"} style = {path = "../style", features = ["servo"]} webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]} diff --git a/components/script_layout_interface/message.rs b/components/script_layout_interface/message.rs index 5c504d06e84..c296f4afbc0 100644 --- a/components/script_layout_interface/message.rs +++ b/components/script_layout_interface/message.rs @@ -5,6 +5,7 @@ use app_units::Au; use crate::rpc::LayoutRPC; use crate::{OpaqueStyleAndLayoutData, PendingImage, TrustedNodeAddress}; +use crossbeam_channel::{Receiver, Sender}; use euclid::{Point2D, Rect}; use gfx_traits::Epoch; use ipc_channel::ipc::{IpcReceiver, IpcSender}; @@ -17,7 +18,6 @@ use script_traits::{ConstellationControlMsg, LayoutControlMsg, LayoutMsg as Cons use script_traits::{ScrollState, UntrustedNodeAddress, WindowSizeData}; use servo_arc::Arc as ServoArc; use servo_atoms::Atom; -use servo_channel::{Receiver, Sender}; use servo_url::ServoUrl; use std::sync::Arc; use style::context::QuirksMode; diff --git a/components/script_traits/Cargo.toml b/components/script_traits/Cargo.toml index 3faaeec0de9..349af63ebc8 100644 --- a/components/script_traits/Cargo.toml +++ b/components/script_traits/Cargo.toml @@ -14,6 +14,7 @@ path = "lib.rs" bluetooth_traits = {path = "../bluetooth_traits"} canvas_traits = {path = "../canvas_traits"} cookie = "0.11" +crossbeam-channel = "0.3" devtools_traits = {path = "../devtools_traits"} embedder_traits = {path = "../embedder_traits"} euclid = "0.19" @@ -31,7 +32,6 @@ net_traits = {path = "../net_traits"} profile_traits = {path = "../profile_traits"} serde = "1.0" servo_atoms = {path = "../atoms"} -servo_channel = {path = "../channel"} servo_url = {path = "../url"} style_traits = {path = "../style_traits", features = ["servo"]} time = "0.1.12" diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs index 00a60d1f3e8..eba51e6ae75 100644 --- a/components/script_traits/lib.rs +++ b/components/script_traits/lib.rs @@ -22,6 +22,7 @@ pub mod webdriver_msg; use bluetooth_traits::BluetoothRequest; use canvas_traits::webgl::WebGLPipeline; use crate::webdriver_msg::{LoadStatus, WebDriverScriptCommand}; +use crossbeam_channel::{Receiver, RecvTimeoutError, Sender}; use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg, WorkerId}; use euclid::{Length, Point2D, Rect, TypedScale, TypedSize2D, Vector2D}; use gfx_traits::Epoch; @@ -42,7 +43,6 @@ use profile_traits::mem; use profile_traits::time as profile_time; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use servo_atoms::Atom; -use servo_channel::{Receiver, Sender}; use servo_url::ImmutableOrigin; use servo_url::ServoUrl; use std::collections::HashMap; @@ -828,6 +828,12 @@ pub enum PaintWorkletError { WorkletNotFound, } +impl From<RecvTimeoutError> for PaintWorkletError { + fn from(_: RecvTimeoutError) -> PaintWorkletError { + PaintWorkletError::Timeout + } +} + /// Execute paint code in the worklet thread pool. pub trait Painter: SpeculativePainter { /// <https://drafts.css-houdini.org/css-paint-api/#draw-a-paint-image> diff --git a/components/servo/Cargo.toml b/components/servo/Cargo.toml index 6244fb2926c..8a04e9378f3 100644 --- a/components/servo/Cargo.toml +++ b/components/servo/Cargo.toml @@ -40,7 +40,7 @@ canvas = {path = "../canvas"} canvas_traits = {path = "../canvas_traits"} compositing = {path = "../compositing", features = ["gleam"]} constellation = {path = "../constellation"} -crossbeam-channel = "0.2" +crossbeam-channel = "0.3" debugger = {path = "../debugger"} devtools = {path = "../devtools"} devtools_traits = {path = "../devtools_traits"} @@ -60,7 +60,6 @@ profile_traits = {path = "../profile_traits"} script = {path = "../script"} script_layout_interface = {path = "../script_layout_interface"} script_traits = {path = "../script_traits"} -servo_channel = {path = "../channel"} servo_config = {path = "../config"} servo_geometry = {path = "../geometry"} servo_url = {path = "../url"} diff --git a/components/servo/lib.rs b/components/servo/lib.rs index ce3ee0962b1..6639da00560 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -42,7 +42,6 @@ pub use profile_traits; pub use script; pub use script_layout_interface; pub use script_traits; -pub use servo_channel; pub use servo_config; pub use servo_geometry; pub use servo_url; @@ -71,6 +70,7 @@ use compositing::{IOCompositor, RenderNotifier, ShutdownState}; use constellation::content_process_sandbox_profile; use constellation::{Constellation, InitialConstellationState, UnprivilegedPipelineContent}; use constellation::{FromCompositorLogger, FromScriptLogger}; +use crossbeam_channel::{unbounded, Sender}; use embedder_traits::{EmbedderMsg, EmbedderProxy, EmbedderReceiver, EventLoopWaker}; use env_logger::Builder as EnvLoggerBuilder; #[cfg(all(not(target_os = "windows"), not(target_os = "ios")))] @@ -86,7 +86,6 @@ use profile::time as profile_time; use profile_traits::mem; use profile_traits::time; use script_traits::{ConstellationMsg, SWManagerSenders, ScriptToConstellationChan}; -use servo_channel::{channel, Sender}; use servo_config::opts; use servo_config::prefs::PREFS; use std::borrow::Cow; @@ -451,7 +450,7 @@ where fn create_embedder_channel( event_loop_waker: Box<dyn EventLoopWaker>, ) -> (EmbedderProxy, EmbedderReceiver) { - let (sender, receiver) = channel(); + let (sender, receiver) = unbounded(); ( EmbedderProxy { sender: sender, @@ -464,7 +463,7 @@ fn create_embedder_channel( fn create_compositor_channel( event_loop_waker: Box<dyn EventLoopWaker>, ) -> (CompositorProxy, CompositorReceiver) { - let (sender, receiver) = channel(); + let (sender, receiver) = unbounded(); ( CompositorProxy { sender: sender, diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index 15e41751603..bf0cb25d62c 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -21,7 +21,7 @@ gecko = ["num_cpus", use_bindgen = ["bindgen", "regex", "toml"] servo = ["serde", "style_traits/servo", "servo_atoms", "servo_config", "html5ever", "cssparser/serde", "encoding_rs", "malloc_size_of/servo", "arrayvec/use_union", - "servo_url", "string_cache", "servo_channel"] + "servo_url", "string_cache", "crossbeam-channel"] gecko_debug = [] [dependencies] @@ -32,6 +32,7 @@ bitflags = "1.0" byteorder = "1.0" cfg-if = "0.1.0" cssparser = "0.25" +crossbeam-channel = { version = "0.3", optional = true } new_debug_unreachable = "1.0" encoding_rs = {version = "0.7", optional = true} euclid = "0.19" @@ -59,7 +60,6 @@ selectors = { path = "../selectors" } serde = {version = "1.0", optional = true, features = ["derive"]} servo_arc = { path = "../servo_arc" } servo_atoms = {path = "../atoms", optional = true} -servo_channel = {path = "../channel", optional = true} servo_config = {path = "../config", optional = true} smallbitvec = "2.1.1" smallvec = "0.6" diff --git a/components/style/animation.rs b/components/style/animation.rs index 094f3049b67..19c8c9e6a4d 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -25,9 +25,8 @@ use crate::values::computed::TimingFunction; use crate::values::generics::box_::AnimationIterationCount; use crate::values::generics::easing::{StepPosition, TimingFunction as GenericTimingFunction}; use crate::Atom; +use crossbeam_channel::Sender; use servo_arc::Arc; -#[cfg(feature = "servo")] -use servo_channel::Sender; use std::fmt; #[cfg(feature = "gecko")] use std::sync::mpsc::Sender; diff --git a/components/style/context.rs b/components/style/context.rs index 4bfee508ee8..6510d4c56cf 100644 --- a/components/style/context.rs +++ b/components/style/context.rs @@ -29,6 +29,8 @@ use crate::thread_state::{self, ThreadState}; use crate::timer::Timer; use crate::traversal::DomTraversal; use crate::traversal_flags::TraversalFlags; +#[cfg(feature = "servo")] +use crossbeam_channel::Sender; use euclid::Size2D; use euclid::TypedScale; use fxhash::FxHashMap; @@ -39,8 +41,6 @@ use selectors::NthIndexCache; use servo_arc::Arc; #[cfg(feature = "servo")] use servo_atoms::Atom; -#[cfg(feature = "servo")] -use servo_channel::Sender; use std::fmt; use std::ops; #[cfg(feature = "servo")] diff --git a/components/style/lib.rs b/components/style/lib.rs index 77927826523..cd1267d99f5 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -36,6 +36,8 @@ extern crate byteorder; #[macro_use] #[no_link] extern crate cfg_if; +#[cfg(feature = "servo")] +extern crate crossbeam_channel; #[macro_use] extern crate cssparser; #[macro_use] @@ -85,8 +87,6 @@ pub extern crate servo_arc; #[macro_use] extern crate servo_atoms; #[cfg(feature = "servo")] -extern crate servo_channel; -#[cfg(feature = "servo")] extern crate servo_config; #[cfg(feature = "servo")] extern crate servo_url; diff --git a/components/webdriver_server/Cargo.toml b/components/webdriver_server/Cargo.toml index 567e3f8a4f7..10a26009805 100644 --- a/components/webdriver_server/Cargo.toml +++ b/components/webdriver_server/Cargo.toml @@ -13,6 +13,7 @@ path = "lib.rs" [dependencies] base64 = "0.9" cookie = "0.11" +crossbeam-channel = "0.3" euclid = "0.19" hyper = "0.12" image = "0.20" @@ -25,7 +26,6 @@ regex = "1.0" serde = "1" serde_json = "1" script_traits = {path = "../script_traits"} -servo_channel = {path = "../channel"} servo_config = {path = "../config"} servo_url = {path = "../url"} url = "1.2" diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs index 347c5315100..7e779fccbd6 100644 --- a/components/webdriver_server/lib.rs +++ b/components/webdriver_server/lib.rs @@ -12,6 +12,7 @@ extern crate log; extern crate serde; use base64; +use crossbeam_channel::Sender; use euclid::TypedSize2D; use hyper::Method; use image::{DynamicImage, ImageFormat, RgbImage}; @@ -28,7 +29,6 @@ use script_traits::{ConstellationMsg, LoadData, WebDriverCommandMsg}; use serde::de::{Deserialize, Deserializer, MapAccess, Visitor}; use serde::ser::{Serialize, Serializer}; use serde_json::{self, Value}; -use servo_channel::Sender; use servo_config::prefs::{PrefValue, PREFS}; use servo_url::ServoUrl; use std::borrow::ToOwned; diff --git a/components/webvr/Cargo.toml b/components/webvr/Cargo.toml index e42f65cfcaf..e25d2e1c98b 100644 --- a/components/webvr/Cargo.toml +++ b/components/webvr/Cargo.toml @@ -16,12 +16,12 @@ oculusvr = ['rust-webvr/oculusvr'] [dependencies] canvas_traits = {path = "../canvas_traits"} +crossbeam-channel = "0.3" euclid = "0.19" ipc-channel = "0.11" log = "0.4" msg = {path = "../msg"} rust-webvr = {version = "0.9", features = ["openvr"]} script_traits = {path = "../script_traits"} -servo_channel = {path = "../channel"} servo_config = {path = "../config"} webvr_traits = {path = "../webvr_traits" } diff --git a/components/webvr/webvr_thread.rs b/components/webvr/webvr_thread.rs index 1a46a33c9cc..fa387fdad9a 100644 --- a/components/webvr/webvr_thread.rs +++ b/components/webvr/webvr_thread.rs @@ -3,13 +3,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use canvas_traits::webgl; +use crossbeam_channel::{unbounded, Receiver, Sender}; use euclid::Size2D; use ipc_channel::ipc; use ipc_channel::ipc::{IpcReceiver, IpcSender}; use msg::constellation_msg::PipelineId; use rust_webvr::VRServiceManager; use script_traits::ConstellationMsg; -use servo_channel::{channel, Receiver, Sender}; use servo_config::prefs::PREFS; use std::collections::{HashMap, HashSet}; use std::{thread, time}; @@ -71,7 +71,7 @@ impl WebVRThread { vr_compositor_chan: WebVRCompositorSender, ) -> (IpcSender<WebVRMsg>, Sender<Sender<ConstellationMsg>>) { let (sender, receiver) = ipc::channel().unwrap(); - let (constellation_sender, constellation_receiver) = channel(); + let (constellation_sender, constellation_receiver) = unbounded(); let sender_clone = sender.clone(); thread::Builder::new() .name("WebVRThread".into()) @@ -361,7 +361,7 @@ pub type WebVRCompositorSender = Sender<Option<WebVRCompositor>>; impl WebVRCompositorHandler { pub fn new() -> (Box<WebVRCompositorHandler>, WebVRCompositorSender) { - let (sender, receiver) = channel(); + let (sender, receiver) = unbounded(); let instance = Box::new(WebVRCompositorHandler { compositors: HashMap::new(), webvr_thread_receiver: receiver, |