#[macro_export]
macro_rules! sleep {
($seconds:expr) => {
::std::thread::sleep(::std::time::Duration::from_secs($seconds))
}
}
pub use sleep;
#[macro_export]
macro_rules! sleep_millis {
($millis:expr) => {
::std::thread::sleep(::std::time::Duration::from_millis($millis))
}
}
pub use sleep_millis;
#[macro_export]
macro_rules! sleep_micros {
($micros:expr) => {
::std::thread::sleep(::std::time::Duration::from_micros($micros))
}
}
pub use sleep_micros;
#[macro_export]
macro_rules! sleep_nanos {
($nanos:expr) => {
::std::thread::sleep(::std::time::Duration::from_nanos($nanos))
}
}
pub use sleep_nanos;
#[macro_export]
macro_rules! park {
() => {
::std::thread::park()
}
}
pub use park;
#[macro_export]
macro_rules! threads {
() => {
match ::std::thread::available_parallelism() {
Ok(t) => usize::from(t),
Err(e) => {
#[cfg(feature = "log")]
::log::error!("std::thread::available_parallelism() failed, returning 1!");
1_usize
},
}
}
}
pub use threads;
#[macro_export]
macro_rules! quarter_threads {
() => {{
let threads = $crate::threads!();
match threads {
1|2 => 1,
_ => (threads as f64 * 0.5).floor() as usize,
}
}}
}
pub use quarter_threads;
#[macro_export]
macro_rules! half_threads {
() => {{
let threads = $crate::threads!();
match threads {
1|2 => 1,
_ => (threads as f64 * 0.5).floor() as usize,
}
}}
}
pub use half_threads;
#[macro_export]
macro_rules! most_threads {
() => {{
let threads = $crate::threads!();
match threads {
1|2 => 1,
3 => 2,
4 => 3,
_ => (threads as f64 * 0.8).floor() as usize,
}
}}
}
pub use most_threads;