Struct clocksource::coarse::AtomicDuration
source · pub struct AtomicDuration { /* private fields */ }
Expand description
A coarse::AtomicDuration
is a duration that is measured in seconds and
represented as an unsigned 32bit value. Since it is implemented using atomic
primitives, it can be used when the duration needs interior mutability and
atomic operations.
Implementations§
source§impl AtomicDuration
impl AtomicDuration
sourcepub fn from_secs(secs: u32) -> Self
pub fn from_secs(secs: u32) -> Self
Create a new atomic duration from a whole number of seconds.
sourcepub fn load(&self, ordering: Ordering) -> Duration
pub fn load(&self, ordering: Ordering) -> Duration
Loads the value of the duration.
See: core::sync::atomic::AtomicU32::load
for a description of the
memory orderings.
§Panics
Panics if ordering
is Release
or AcqRel
.
sourcepub fn store(&self, value: Duration, ordering: Ordering)
pub fn store(&self, value: Duration, ordering: Ordering)
Stores a new value for the duration.
See: core::sync::atomic::AtomicU32::store
for a description of the
memory orderings.
§Panics
Panics if ordering
is Acquire
or AcqRel
.
sourcepub fn swap(&self, value: Duration, order: Ordering) -> Duration
pub fn swap(&self, value: Duration, order: Ordering) -> Duration
Replaces the value of the duration and returns the previous value.
See: core::sync::atomic::AtomicU32::swap
for a description of the
memory orderings.
Note: This method is only available on platforms that support atomic
operations on u32
.
sourcepub fn compare_exchange(
&self,
current: Duration,
new: Duration,
success: Ordering,
failure: Ordering
) -> Result<Duration, Duration>
pub fn compare_exchange( &self, current: Duration, new: Duration, success: Ordering, failure: Ordering ) -> Result<Duration, Duration>
Stores a new value for the duration if the current duration is the same
as the current
duration.
See: core::sync::atomic::AtomicU32::compare_exchange
for a
description of the memory orderings.
Note: This method is only available on platforms that support atomic
operations on u32
.
sourcepub fn compare_exchange_weak(
&self,
current: Duration,
new: Duration,
success: Ordering,
failure: Ordering
) -> Result<Duration, Duration>
pub fn compare_exchange_weak( &self, current: Duration, new: Duration, success: Ordering, failure: Ordering ) -> Result<Duration, Duration>
Stores a new value for the duration if the current duration is the same
as the current
duration.
See: core::sync::atomic::AtomicU32::compare_exchange_weak
for a
description of the memory orderings.
Unlike AtomicDuration::compare_exchange
, this function is allowed to
spuriously fail. This allows for more efficient code on some platforms.
Note: This method is only available on platforms that support atomic
operations on u32
.
sourcepub fn fetch_add(&self, value: Duration, ordering: Ordering) -> Duration
pub fn fetch_add(&self, value: Duration, ordering: Ordering) -> Duration
Adds to the current duration, returning the previous duration.
This operation wraps around on overflow.
See: core::sync::atomic::AtomicU32::fetch_add
for a
description of the memory orderings.
Note: This method is only available on platforms that support atomic
operations on u32
.
sourcepub fn fetch_max(&self, value: Duration, ordering: Ordering) -> Duration
pub fn fetch_max(&self, value: Duration, ordering: Ordering) -> Duration
Maximum with the current duration.
Finds the maximum of the current duration and the argument value
, and
sets the new duration to the result.
Returns the previous duration.
See: core::sync::atomic::AtomicU32::fetch_max
for a
description of the memory orderings.
Note: This method is only available on platforms that support atomic
operations on u32
.
sourcepub fn fetch_min(&self, val: Duration, ordering: Ordering) -> Duration
pub fn fetch_min(&self, val: Duration, ordering: Ordering) -> Duration
Minimum with the current duration.
Finds the minimum of the current duration and the argument val
, and
sets the new duration to the result.
Returns the previous duration.
See: core::sync::atomic::AtomicU32::fetch_min
for a
description of the memory orderings.
Note: This method is only available on platforms that support atomic
operations on u32
.
sourcepub fn fetch_sub(&self, val: Duration, ordering: Ordering) -> Duration
pub fn fetch_sub(&self, val: Duration, ordering: Ordering) -> Duration
Subtracts from the current duration, returning the previous duration.
This operation wraps around on overflow.
See: core::sync::atomic::AtomicU32::fetch_sub
for a
description of the memory orderings.
Note: This method is only available on platforms that support atomic
operations on u32
.