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_until(self, deadline: Instant)
pub fn sleep_until(self, deadline: Instant)
Puts the current thread to sleep until the deadline
less
the configured native accuracy. Then spins until the specified deadline is reached.
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 more