Update crossbeam-channel to 0.3

This commit is contained in:
Bastien Orivel 2018-11-07 19:48:07 +01:00
parent 76195e0779
commit 9a7eeb349a
74 changed files with 303 additions and 521 deletions

View file

@ -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"}

View file

@ -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)
}
};

View file

@ -5,10 +5,12 @@
#![deny(unsafe_code)]
#![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;

View file

@ -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>,

View file

@ -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;

View file

@ -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.