Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upUpdate crossbeam-channel to 0.3 #22142
Conversation
highfive
commented
Nov 7, 2018
|
Heads up! This PR modifies the following files:
|
|
cc @stjepang |
| 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()), | ||
| // TODO: recv(devtools_port) -> msg => worker_scope.from_devtools_msg(msg.unwrap()), |
This comment has been minimized.
This comment has been minimized.
Eijebong
Nov 7, 2018
Author
Member
So here is the only thing I didn't know how to do. select! doesn't support recv(Option<Receiver>) anymore. Do I have to write that with Select then ?
This comment has been minimized.
This comment has been minimized.
stjepang
Nov 8, 2018
Contributor
You could do that with Select, but you don't have to. There's another way:
recv(devtools_port.unwrap_or(&crossbeam_channel::never())) -> msg => ...See here for documentation on never.
I removed the ability to use Option<&Receiver<_>> in select! because it was an ugly hack that abuses traits and doesn't work as well as I hoped for. Maybe I'll add it again sometime in the future when we get specialization in Rust.
|
Looks like a good start! I left some comments inline. |
| @@ -9,6 +9,7 @@ use crate::{ | |||
| create_embedder_proxy, fetch, make_server, make_ssl_server, new_fetch_context, | |||
| DEFAULT_USER_AGENT, | |||
| }; | |||
| use crossbeam_channel::{channel, Sender}; | |||
This comment has been minimized.
This comment has been minimized.
stjepang
Nov 8, 2018
Contributor
This function is called unbounded, not channel. The same error appears in some other files, which is why CI is currently failing.
This comment has been minimized.
This comment has been minimized.
| 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()), | ||
| // TODO: recv(devtools_port) -> msg => worker_scope.from_devtools_msg(msg.unwrap()), |
This comment has been minimized.
This comment has been minimized.
stjepang
Nov 8, 2018
Contributor
You could do that with Select, but you don't have to. There's another way:
recv(devtools_port.unwrap_or(&crossbeam_channel::never())) -> msg => ...See here for documentation on never.
I removed the ability to use Option<&Receiver<_>> in select! because it was an ugly hack that abuses traits and doesn't work as well as I hoped for. Maybe I'll add it again sometime in the future when we get specialization in Rust.
|
|
db426a4
to
65573a1
|
|
|
@bors-servo try |
Update crossbeam-channel to 0.3 servo/ipc-channel#210 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22142) <!-- Reviewable:end -->
|
|
|
@stjepang Should be ready to go now |
|
A few more nits. We can merge after they get resolved. |
| @@ -70,9 +70,9 @@ impl TimerScheduler { | |||
| } | |||
| // Look to see if there are any incoming events | |||
| select! { | |||
| recv(req_receiver, msg) => match msg { | |||
| recv(req_receiver) -> msg => match msg { | |||
This comment has been minimized.
This comment has been minimized.
stjepang
Nov 10, 2018
Contributor
Let's rewrite this whole select! block using match req_receiver.try_recv():
// Look to see if there are any incoming events
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.
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,
}| @@ -68,7 +68,7 @@ impl ScriptChan for WorkerThreadWorkerChan { | |||
|
|
|||
| impl ScriptPort for Receiver<DedicatedWorkerScriptMsg> { | |||
| fn recv(&self) -> Result<CommonScriptMsg, ()> { | |||
| let common_msg = match self.recv() { | |||
| let common_msg = match self.recv().ok() { | |||
This comment has been minimized.
This comment has been minimized.
stjepang
Nov 10, 2018
Contributor
Nit: Remove this .ok() and change below:
SometoOkNonetoErr(_)
| None => match timer_event_port.try_recv() { | ||
| None => match devtools_port.and_then(|port| port.try_recv()) { | ||
| None => match timer_event_port.try_recv().ok() { | ||
| None => match devtools_port.and_then(|port| port.try_recv().ok()) { |
This comment has been minimized.
This comment has been minimized.
stjepang
Nov 10, 2018
Contributor
Nit: Remove those two .ok()s and change:
SometoOkNonetoErr(_)
| @@ -446,10 +445,10 @@ impl PaintWorkletGlobalScope { | |||
| .unwrap_or(10u64); | |||
|
|
|||
| select! { | |||
| recv(base_channel::after(Duration::from_millis(timeout))) => { | |||
| recv(crossbeam_channel::after(Duration::from_millis(timeout))) -> _ => { | |||
This comment has been minimized.
This comment has been minimized.
stjepang
Nov 10, 2018
Contributor
Let's replace this select! with:
receiver.recv_timeout(timeout_duration)
.map_err(|e| PaintWorkletError::from(e))And then restore this impl, which was removed in the PR that migrated from mpsc to crossbeam-channel v0.2:
https://github.com/gterzian/servo/blob/e784f5a9f7a4c3eec92b946b0debd4cbcb942ae7/components/script_traits/lib.rs#L807-L811
| @@ -1498,7 +1498,7 @@ impl Window { | |||
| debug!("script: layout forked"); | |||
|
|
|||
| let complete = select! { | |||
| recv(join_port.select(), msg) => if let Some(reflow_complete) = msg { | |||
| recv(join_port) -> msg => if let Ok(reflow_complete) = msg { | |||
This comment has been minimized.
This comment has been minimized.
stjepang
Nov 10, 2018
Contributor
We can replace this select! with:
let complete = match join_port.try_recv() {
Err(Empty) => {
info!("script: waiting on layout");
join_port.recv().unwrap()
}
Ok(reflow_complete) => reflow_complete,
Err(Disconnected) => {
panic!("Layout thread failed while script was waiting for a result.");
}
};| 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.ok().map(Message::FromConstellation), | ||
| recv(self.resource_receiver) -> msg => msg.ok().map(Message::FromResource), |
This comment has been minimized.
This comment has been minimized.
stjepang
Nov 10, 2018
Contributor
Let's revert this whole method to (roughly) what it used to be:
fn receive_message(&mut self) -> Result<Message, RecvError> {
select! {
recv(self.own_port) -> msg => msg.map(Message::FromConstellation),
recv(self.resource_receiver) -> msg => msg.map(Message::FromResource),
}
}There's a Some in handle_message that'll need to be changed to Ok.
| @@ -110,12 +110,12 @@ 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 comment has been minimized.
This comment has been minimized.
stjepang
Nov 10, 2018
Contributor
Methods recv and try_recv below this select method used to return Result<T, ()>. Perhaps we should restore that.
| } | ||
| } | ||
|
|
||
| impl ScriptPort for Receiver<MainThreadScriptMsg> { | ||
| fn recv(&self) -> Result<CommonScriptMsg, ()> { | ||
| match self.recv() { | ||
| match self.recv().ok() { |
This comment has been minimized.
This comment has been minimized.
| } | ||
| } | ||
|
|
||
| impl ScriptPort for Receiver<(TrustedWorkerAddress, MainThreadScriptMsg)> { | ||
| fn recv(&self) -> Result<CommonScriptMsg, ()> { | ||
| match self.recv().map(|(_, msg)| msg) { | ||
| match self.recv().map(|(_, msg)| msg).ok() { |
This comment has been minimized.
This comment has been minimized.
| None => match self.image_cache_port.try_recv() { | ||
| None => match self.timer_event_port.try_recv().ok() { | ||
| None => match self.devtools_port.try_recv().ok() { | ||
| None => match self.image_cache_port.try_recv().ok() { |
This comment has been minimized.
This comment has been minimized.
|
|
|
Done. @bors-servo try=wpt |
|
|
|
|
|
Rebased |
|
@bors-servo r+ |
|
|
Update crossbeam-channel to 0.3 servo/ipc-channel#210 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22142) <!-- Reviewable:end -->
|
|
Cherry-picks servo/servo#22142
Cherry-picks servo/servo#22142
Cherry-picks servo/servo#22142
Cherry-picks servo/servo#22142
Eijebong commentedNov 7, 2018
•
edited by SimonSapin
servo/ipc-channel#210
This change is