Struct spin_sleep::SpinSleeper
source · pub struct SpinSleeper { /* private fields */ }
Expand description
Accuracy container for spin sleeping. See crate docs.
Implementations§
source§impl SpinSleeper
impl SpinSleeper
sourcepub fn new(native_accuracy_ns: SubsecondNanoseconds) -> SpinSleeper
pub fn new(native_accuracy_ns: SubsecondNanoseconds) -> SpinSleeper
Constructs new SpinSleeper with the input native sleep accuracy.
The lower the native_accuracy_ns
the more we effectively trust the accuracy of the
native_sleep
function.
sourcepub fn native_accuracy_ns(self) -> SubsecondNanoseconds
pub fn native_accuracy_ns(self) -> SubsecondNanoseconds
Returns configured native_accuracy_ns.
sourcepub fn spin_strategy(self) -> SpinStrategy
pub fn spin_strategy(self) -> SpinStrategy
Returns configured spin strategy.
sourcepub fn with_spin_strategy(self, strategy: SpinStrategy) -> Self
pub fn with_spin_strategy(self, strategy: SpinStrategy) -> Self
Returns a spin sleeper with the given SpinStrategy
.
Example
use spin_sleep::{SpinSleeper, SpinStrategy};
let sleeper = SpinSleeper::default().with_spin_strategy(SpinStrategy::SpinLoopHint);
sourcepub fn sleep(self, duration: Duration)
pub fn sleep(self, duration: Duration)
Puts the current thread to sleep for the duration less the configured native accuracy. Then spins until the specified duration has elapsed.
sourcepub fn sleep_s(self, seconds: Seconds)
pub fn sleep_s(self, seconds: Seconds)
Puts the current thread to sleep for the give seconds-duration less the configured native accuracy. Then spins until the specified duration has elapsed.
sourcepub fn sleep_ns(self, nanoseconds: Nanoseconds)
pub fn sleep_ns(self, nanoseconds: Nanoseconds)
Puts the current thread to sleep for the give nanoseconds-duration less the configured native accuracy. Then spins until the specified duration has elapsed.
Trait Implementations§
source§impl Clone for SpinSleeper
impl Clone for SpinSleeper
source§fn clone(&self) -> SpinSleeper
fn clone(&self) -> SpinSleeper
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SpinSleeper
impl Debug for SpinSleeper
source§impl Default for SpinSleeper
impl Default for SpinSleeper
source§impl Hash for SpinSleeper
impl Hash for SpinSleeper
source§impl PartialEq for SpinSleeper
impl PartialEq for SpinSleeper
source§fn eq(&self, other: &SpinSleeper) -> bool
fn eq(&self, other: &SpinSleeper) -> bool
self
and other
values to be equal, and is used
by ==
.