pub struct Backoff { /* private fields */ }
Expand description
An exponential backoff for spin loops.
This is a helper struct for spinning in a busy loop, with an exponentially increasing number of spins up to a maximum value.
Implementations§
Source§impl Backoff
impl Backoff
Sourcepub const DEFAULT_MAX_EXPONENT: u8 = 8u8
pub const DEFAULT_MAX_EXPONENT: u8 = 8u8
The default maximum exponent (2^8).
This is the maximum exponent returned by Backoff::new()
and
Backoff::default()
. To override the maximum exponent, use
Backoff::with_max_exponent()
.
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Returns a new exponential backoff with the maximum exponent set to
Self::DEFAULT_MAX_EXPONENT
.
Sourcepub fn with_max_exponent(max: u8) -> Self
pub fn with_max_exponent(max: u8) -> Self
Returns a new exponential backoff with the provided max exponent.
Sourcepub fn spin(&mut self)
pub fn spin(&mut self)
Backs off in a spin loop.
This should be used when an operation needs to be retried because
another thread or core made progress. Depending on the target
architecture, this will generally issue a sequence of yield
or pause
instructions.
Each time this function is called, it will issue 2^exp
[spin loop
hints], where exp
is the current exponent value (starting at 0). If
exp
is less than the configured maximum exponent, the exponent is
incremented once the spin is complete.
Trait Implementations§
impl Copy for Backoff
Auto Trait Implementations§
impl Freeze for Backoff
impl RefUnwindSafe for Backoff
impl Send for Backoff
impl Sync for Backoff
impl Unpin for Backoff
impl UnwindSafe for Backoff
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)