new file: compiler.rs
new file: primitives.rs new file: store.rs new file: support.rs
This commit is contained in:
parent
96a783ae5a
commit
c86ad6e5ac
4 changed files with 213 additions and 0 deletions
39
src/support.rs
Normal file
39
src/support.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// Platform helpers to ease future no_std portability.
|
||||
// The crate currently depends on `std`, but concentrating platform-specific
|
||||
// pieces here makes migration simpler.
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::sync::Arc;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub fn run_parallel<L, R, OutL, OutR>(left: L, right: R) -> (OutL, OutR)
|
||||
where
|
||||
L: FnOnce() -> OutL + Send + 'static,
|
||||
R: FnOnce() -> OutR + Send + 'static,
|
||||
OutL: Send + 'static,
|
||||
OutR: Send + 'static,
|
||||
{
|
||||
let h1 = std::thread::spawn(left);
|
||||
let h2 = std::thread::spawn(right);
|
||||
(h1.join().unwrap(), h2.join().unwrap())
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
mod no_std_support {
|
||||
extern crate alloc;
|
||||
pub use alloc::sync::Arc;
|
||||
|
||||
pub fn run_parallel<L, R, OutL, OutR>(left: L, right: R) -> (OutL, OutR)
|
||||
where
|
||||
L: FnOnce() -> OutL + Send + 'static,
|
||||
R: FnOnce() -> OutR + Send + 'static,
|
||||
OutL: Send + 'static,
|
||||
OutR: Send + 'static,
|
||||
{
|
||||
// No threads available: fall back to sequential execution.
|
||||
(left(), right())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub use no_std_support::*;
|
||||
Loading…
Reference in a new issue