Struct clocksource::coarse::AtomicUnixInstant
source · pub struct AtomicUnixInstant { /* private fields */ }
Expand description
An atomic measurement of the system clock in seconds.
Internally, it reprsents the instant as a whole number of seconds from the
UNIX epoch using an AtomicU32
. This provides interior mutability with
atomic operations.
See the crate::coarse::UnixInstant
type for more details.
Implementations§
source§impl AtomicUnixInstant
impl AtomicUnixInstant
sourcepub fn new(value: UnixInstant) -> Self
pub fn new(value: UnixInstant) -> Self
Create a new AtomicUnixInstant
representing the provided UnixInstant
.
sourcepub fn load(&self, ordering: Ordering) -> UnixInstant
pub fn load(&self, ordering: Ordering) -> UnixInstant
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: UnixInstant, ordering: Ordering)
pub fn store(&self, value: UnixInstant, ordering: Ordering)
Stores a new value for the instant.
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: UnixInstant, ordering: Ordering) -> UnixInstant
pub fn swap(&self, value: UnixInstant, ordering: Ordering) -> UnixInstant
Replaces the value of the instant 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: UnixInstant,
new: UnixInstant,
success: Ordering,
failure: Ordering
) -> Result<UnixInstant, UnixInstant>
pub fn compare_exchange( &self, current: UnixInstant, new: UnixInstant, success: Ordering, failure: Ordering ) -> Result<UnixInstant, UnixInstant>
Stores a new value for the instant if the current instant is the same as
the current
instant.
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: UnixInstant,
new: UnixInstant,
success: Ordering,
failure: Ordering
) -> Result<UnixInstant, UnixInstant>
pub fn compare_exchange_weak( &self, current: UnixInstant, new: UnixInstant, success: Ordering, failure: Ordering ) -> Result<UnixInstant, UnixInstant>
Stores a new value for the instant if the current instant is the same as
the current
instant.
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) -> UnixInstant
pub fn fetch_add(&self, value: Duration, ordering: Ordering) -> UnixInstant
Adds to the current instant, returning the previous instant.
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: UnixInstant, ordering: Ordering) -> UnixInstant
pub fn fetch_max(&self, value: UnixInstant, ordering: Ordering) -> UnixInstant
Maximum with the current instant.
Finds the maximum of the current instant and the argument value
, and
sets the new instant to the result.
Returns the previous instant.
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, value: UnixInstant, ordering: Ordering) -> UnixInstant
pub fn fetch_min(&self, value: UnixInstant, ordering: Ordering) -> UnixInstant
Minimum with the current instant.
Finds the minimum of the current instant and the argument val
, and
sets the new instant to the result.
Returns the previous instant.
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, value: Duration, ordering: Ordering) -> UnixInstant
pub fn fetch_sub(&self, value: Duration, ordering: Ordering) -> UnixInstant
Subtracts from the current instant, returning the previous instant.
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
.