-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish getting tests to work with shuttle
- Loading branch information
Showing
10 changed files
with
75 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[build] | ||
# Setting cfg here means our IDE and CLI both use the same values. | ||
#rustflags = "--cfg shuttle" | ||
#rustflags = "--cfg loom" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,54 @@ | ||
pub(crate) mod sync; | ||
|
||
#[cfg(not(shuttle))] | ||
#[cfg(not(feature = "shuttle"))] | ||
pub use std::thread; | ||
|
||
// This isn't available in loom or shuttle yet. Unfortunately for shuttle it means threads are | ||
// spawned outside its control, and it doesn't work. | ||
#[cfg(shuttle)] | ||
#[cfg(feature = "shuttle")] | ||
pub use shuttle::thread; | ||
|
||
#[cfg(not(shuttle))] | ||
#[cfg(not(feature = "shuttle"))] | ||
pub(crate) fn run_blocking<F, R>(f: F) -> R | ||
where | ||
F: FnOnce() -> R+Send, | ||
R: Send, | ||
F: FnOnce() -> R + Send, | ||
R: Send, | ||
{ | ||
// let (sender, receiver) = std::sync::mpsc::channel(); | ||
// std::thread::scope(|scope|{ | ||
// scope.spawn(f) | ||
// }); | ||
unimplemented!() | ||
if false { | ||
let (sender, receiver) = std::sync::mpsc::channel(); | ||
let tx_thread = std::thread::scope(|scope| { | ||
scope.spawn(|| { | ||
let res = f(); | ||
sender.send(res).unwrap(); | ||
}); | ||
receiver.recv().unwrap() | ||
}); | ||
tx_thread | ||
} else { | ||
f() | ||
} | ||
} | ||
|
||
#[cfg(shuttle)] | ||
#[cfg(feature = "shuttle")] | ||
pub(crate) fn run_blocking<F, R>(f: F) -> R | ||
where | ||
F: FnOnce() -> R+Send, | ||
R: Send, | ||
|
||
F: FnOnce() -> R + Send, | ||
R: Send, | ||
{ | ||
let (sender, receiver) = shuttle::sync::mpsc::channel(); | ||
std::thread::scope(|scope| { | ||
scope.spawn(f) | ||
}) | ||
use std::sync::mpsc; | ||
let (sender, receiver) = mpsc::channel(); | ||
let tx_thread = std::thread::scope(|scope| { | ||
scope.spawn(||{ | ||
let res = f(); | ||
sender.send(res).unwrap(); | ||
}); | ||
loop { | ||
shuttle::thread::yield_now(); | ||
match receiver.try_recv() { | ||
Err(mpsc::TryRecvError::Empty) => continue, | ||
default => return default.unwrap() | ||
} | ||
} | ||
}); | ||
tx_thread | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters