mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Update crossbeam-channel to 0.3
This commit is contained in:
parent
76195e0779
commit
9a7eeb349a
74 changed files with 303 additions and 521 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue