diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-09-12 13:33:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-12 13:33:45 -0400 |
commit | 910cc23a6e85cced43905f7615065b23bdb54b42 (patch) | |
tree | 3ceae959c0ebdf3f224c5c07f5b8c2cbd31dddf1 /components/script/dom/worklet.rs | |
parent | 9a83ab6297ddb62937fc54521b7fd4d19017e6b1 (diff) | |
parent | 2a996fbc8fef722b264389680cc55c25c46807d1 (diff) | |
download | servo-910cc23a6e85cced43905f7615065b23bdb54b42.tar.gz servo-910cc23a6e85cced43905f7615065b23bdb54b42.zip |
Auto merge of #21325 - gterzian:crossbeam_integration, r=SimonSapin,jdm
Replace mpsc with crossbeam-channel
Follow up on https://github.com/servo/servo/pull/19515
---
Selecting over multiple channels in `std::sync::mpsc` is not stable and likely never will be:
https://github.com/rust-lang/rust/issues/27800#issuecomment-260136777
> It seems the only thing keeping `mpsc_select` around is Servo.
crossbeam-channel is designed specifically to replace `std::sync::mpsc` and fix many of its shortcomings:
https://github.com/stjepang/rfcs-crossbeam/blob/channel/text/2017-11-09-channel.md
This is to be landed together with https://github.com/servo/ipc-channel/pull/183.
<!-- 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/21325)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/worklet.rs')
-rw-r--r-- | components/script/dom/worklet.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/components/script/dom/worklet.rs b/components/script/dom/worklet.rs index d1b7ba9c44a..498cce10680 100644 --- a/components/script/dom/worklet.rs +++ b/components/script/dom/worklet.rs @@ -48,6 +48,7 @@ use script_runtime::Runtime; use script_runtime::ScriptThreadEventCategory; use script_runtime::new_rt_and_cx; use script_thread::{MainThreadScriptMsg, ScriptThread}; +use servo_channel::{channel, Sender, Receiver}; use servo_rand; use servo_url::ImmutableOrigin; use servo_url::ServoUrl; @@ -58,9 +59,6 @@ use std::rc::Rc; use std::sync::Arc; use std::sync::atomic::AtomicIsize; use std::sync::atomic::Ordering; -use std::sync::mpsc; -use std::sync::mpsc::Receiver; -use std::sync::mpsc::Sender; use std::thread; use style::thread_state::{self, ThreadState}; use swapper::Swapper; @@ -309,7 +307,7 @@ impl WorkletThreadPool { /// For testing. pub fn test_worklet_lookup(&self, id: WorkletId, key: String) -> Option<String> { - let (sender, receiver) = mpsc::channel(); + let (sender, receiver) = channel(); let msg = WorkletData::Task(id, WorkletTask::Test(TestWorkletTask::Lookup(key, sender))); let _ = self.primary_sender.send(msg); receiver.recv().expect("Test worklet has died?") @@ -355,7 +353,7 @@ struct WorkletThreadRole { impl WorkletThreadRole { fn new(is_hot_backup: bool, is_cold_backup: bool) -> WorkletThreadRole { - let (sender, receiver) = mpsc::channel(); + let (sender, receiver) = channel(); WorkletThreadRole { sender: sender, receiver: receiver, @@ -419,7 +417,7 @@ impl WorkletThread { #[allow(unsafe_code)] #[allow(unrooted_must_root)] fn spawn(role: WorkletThreadRole, init: WorkletThreadInit) -> Sender<WorkletControl> { - let (control_sender, control_receiver) = mpsc::channel(); + let (control_sender, control_receiver) = channel(); // TODO: name this thread thread::spawn(move || { // TODO: add a new IN_WORKLET thread state? @@ -488,12 +486,12 @@ impl WorkletThread { if let Some(control) = self.control_buffer.take() { self.process_control(control); } - while let Ok(control) = self.control_receiver.try_recv() { + while let Some(control) = self.control_receiver.try_recv() { self.process_control(control); } self.gc(); } else if self.control_buffer.is_none() { - if let Ok(control) = self.control_receiver.try_recv() { + if let Some(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); |