pub struct AtomicOptionSystemTime(/* private fields */);std only.Expand description
An atomic version of Option<std::time::SystemTime>.
Some values must be at or after SystemTime::UNIX_EPOCH.
Implementations§
Source§impl AtomicOptionSystemTime
impl AtomicOptionSystemTime
Sourcepub const fn none() -> Self
pub const fn none() -> Self
Equivalent to atomic version Option::<SystemTime>::None.
§Examples
use atomic_time::AtomicOptionSystemTime;
let none = AtomicOptionSystemTime::none();
assert_eq!(none.load(std::sync::atomic::Ordering::SeqCst), None);Sourcepub fn now() -> Self
pub fn now() -> Self
Returns the system time corresponding to “now”.
§Examples
use atomic_time::AtomicOptionSystemTime;
let sys_time = AtomicOptionSystemTime::now();Sourcepub fn new(system_time: Option<SystemTime>) -> Self
pub fn new(system_time: Option<SystemTime>) -> Self
Creates a new AtomicOptionSystemTime with the given SystemTime value.
§Panics
If the given SystemTime value is earlier than the UNIX_EPOCH.
Sourcepub fn load(&self, order: Ordering) -> Option<SystemTime>
pub fn load(&self, order: Ordering) -> Option<SystemTime>
Loads a value from the atomic system time.
Sourcepub fn store(&self, system_time: Option<SystemTime>, order: Ordering)
pub fn store(&self, system_time: Option<SystemTime>, order: Ordering)
Stores a value into the atomic system time.
§Panics
If the given SystemTime value is earlier than the UNIX_EPOCH.
Sourcepub fn swap(
&self,
system_time: Option<SystemTime>,
order: Ordering,
) -> Option<SystemTime>
pub fn swap( &self, system_time: Option<SystemTime>, order: Ordering, ) -> Option<SystemTime>
Stores a value into the atomic system time, returning the previous value.
§Panics
If the given SystemTime value is earlier than the UNIX_EPOCH.
Sourcepub fn compare_exchange(
&self,
current: Option<SystemTime>,
new: Option<SystemTime>,
success: Ordering,
failure: Ordering,
) -> Result<Option<SystemTime>, Option<SystemTime>>
pub fn compare_exchange( &self, current: Option<SystemTime>, new: Option<SystemTime>, success: Ordering, failure: Ordering, ) -> Result<Option<SystemTime>, Option<SystemTime>>
Stores a value into the atomic system time if the current value is the same as the current
value.
§Panics
If the given SystemTime value is earlier than the UNIX_EPOCH.
Sourcepub fn compare_exchange_weak(
&self,
current: Option<SystemTime>,
new: Option<SystemTime>,
success: Ordering,
failure: Ordering,
) -> Result<Option<SystemTime>, Option<SystemTime>>
pub fn compare_exchange_weak( &self, current: Option<SystemTime>, new: Option<SystemTime>, success: Ordering, failure: Ordering, ) -> Result<Option<SystemTime>, Option<SystemTime>>
Stores a value into the atomic system time if the current value is the same as the current
value.
§Panics
If the given SystemTime value is earlier than the UNIX_EPOCH.
Sourcepub fn try_update<F>(
&self,
set_order: Ordering,
fetch_order: Ordering,
f: F,
) -> Result<Option<SystemTime>, Option<SystemTime>>
pub fn try_update<F>( &self, set_order: Ordering, fetch_order: Ordering, f: F, ) -> Result<Option<SystemTime>, Option<SystemTime>>
Fetches the value and applies a function that can choose whether to store a new value.
Returns Ok(previous_value) when f returns Some(_), and
Err(previous_value) when it returns None. The outer Option is the
update decision; returning Some(None) stores None. The closure can run
more than once when another thread changes the value concurrently, but it
is applied only once to the value that is stored.
set_order describes the ordering of the successful update and
fetch_order describes failed compare-and-exchange loads. They have the
same requirements as the success and failure orderings of
compare_exchange.
§Panics
Panics if the orderings are invalid for
compare_exchange, or if a Some value passed
to or returned from the function is earlier than
UNIX_EPOCH.
§Examples
use atomic_time::AtomicOptionSystemTime;
use std::{sync::atomic::Ordering, time::{Duration, SystemTime}};
let start = SystemTime::UNIX_EPOCH + Duration::from_secs(7);
let x = AtomicOptionSystemTime::new(Some(start));
assert_eq!(x.try_update(Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(Some(start)));
assert_eq!(x.try_update(Ordering::SeqCst, Ordering::SeqCst, |old| Some(old.map(|time| time + Duration::from_secs(1)))), Ok(Some(start)));Sourcepub fn fetch_update<F>(
&self,
set_order: Ordering,
fetch_order: Ordering,
f: F,
) -> Result<Option<SystemTime>, Option<SystemTime>>
pub fn fetch_update<F>( &self, set_order: Ordering, fetch_order: Ordering, f: F, ) -> Result<Option<SystemTime>, Option<SystemTime>>
Fetches the value, and applies a function to it that returns an optional
new value. Returns a Result of Ok(previous_value) if the function returned Some(_), else
Err(previous_value).
Note: This may call the function multiple times if the value has been changed from other threads in
the meantime, as long as the function returns Some(_), but the function will have been applied
only once to the stored value.
fetch_update takes two Ordering arguments to describe the memory ordering of this operation.
The first describes the required ordering for when the operation finally succeeds while the second
describes the required ordering for loads. These correspond to the success and failure orderings of
compare_exchange respectively.
Using Acquire as success ordering makes the store part
of this operation Relaxed, and using Release makes the final successful load
Relaxed. The (failed) load ordering can only be SeqCst, Acquire or Relaxed
and must be equivalent to or weaker than the success ordering.
§Panics
If the given SystemTime value is earlier than the UNIX_EPOCH.
§Examples
use atomic_time::AtomicOptionSystemTime;
use std::{time::{Duration, SystemTime}, sync::atomic::Ordering};
let now = SystemTime::now();
let x = AtomicOptionSystemTime::none();
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(None));
x.store(Some(now), Ordering::SeqCst);
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x.map(|val| val + Duration::from_secs(1)))), Ok(Some(now)));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x.map(|val| val + Duration::from_secs(1)))), Ok(Some(now + Duration::from_secs(1))));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x.map(|val| val + Duration::from_secs(1)))), Ok(Some(now + Duration::from_secs(2))));
assert_eq!(x.load(Ordering::SeqCst), Some(now + Duration::from_secs(3)));Sourcepub fn update<F>(
&self,
set_order: Ordering,
fetch_order: Ordering,
f: F,
) -> Option<SystemTime>
pub fn update<F>( &self, set_order: Ordering, fetch_order: Ordering, f: F, ) -> Option<SystemTime>
Fetches the value, applies a function to produce a new value, stores it, and returns the previous value.
The closure can run more than once when another thread changes the value
concurrently, but it is applied only once to the value that is stored.
set_order and fetch_order have the same requirements as the success
and failure orderings of compare_exchange.
§Panics
Panics if the orderings are invalid for
compare_exchange, or if a Some value passed
to or returned from the function is earlier than
UNIX_EPOCH.
§Examples
use atomic_time::AtomicOptionSystemTime;
use std::{sync::atomic::Ordering, time::{Duration, SystemTime}};
let start = SystemTime::UNIX_EPOCH + Duration::from_secs(7);
let x = AtomicOptionSystemTime::new(Some(start));
assert_eq!(x.update(Ordering::SeqCst, Ordering::SeqCst, |old| old.map(|time| time + Duration::from_secs(1))), Some(start));
assert_eq!(x.load(Ordering::SeqCst), Some(start + Duration::from_secs(1)));Sourcepub fn fetch_min(
&self,
val: Option<SystemTime>,
order: Ordering,
) -> Option<SystemTime>
pub fn fetch_min( &self, val: Option<SystemTime>, order: Ordering, ) -> Option<SystemTime>
Atomically stores the smaller of the current value and val, returning
the previous value.
None is ordered before every Some value, and Some values are ordered
by their duration from UNIX_EPOCH. order
describes the memory ordering of the read-modify-write operation. Using
Acquire makes its store part relaxed, and using
Release makes its load part relaxed.
§Panics
Panics if a Some value in val is earlier than
UNIX_EPOCH.
§Examples
use atomic_time::AtomicOptionSystemTime;
use std::{sync::atomic::Ordering, time::{Duration, SystemTime}};
let low = SystemTime::UNIX_EPOCH + Duration::from_secs(5);
let middle = low + Duration::from_secs(1);
let high = middle + Duration::from_secs(1);
let x = AtomicOptionSystemTime::new(Some(middle));
assert_eq!(x.fetch_min(Some(high), Ordering::SeqCst), Some(middle));
assert_eq!(x.fetch_min(Some(low), Ordering::SeqCst), Some(middle));
assert_eq!(x.load(Ordering::SeqCst), Some(low));Sourcepub fn fetch_max(
&self,
val: Option<SystemTime>,
order: Ordering,
) -> Option<SystemTime>
pub fn fetch_max( &self, val: Option<SystemTime>, order: Ordering, ) -> Option<SystemTime>
Atomically stores the larger of the current value and val, returning
the previous value.
None is ordered before every Some value, and Some values are ordered
by their duration from UNIX_EPOCH. order
describes the memory ordering of the read-modify-write operation. Using
Acquire makes its store part relaxed, and using
Release makes its load part relaxed.
§Panics
Panics if a Some value in val is earlier than
UNIX_EPOCH.
§Examples
use atomic_time::AtomicOptionSystemTime;
use std::{sync::atomic::Ordering, time::{Duration, SystemTime}};
let high = SystemTime::UNIX_EPOCH + Duration::from_secs(7);
let x = AtomicOptionSystemTime::none();
assert_eq!(x.fetch_max(None, Ordering::SeqCst), None);
assert_eq!(x.fetch_max(Some(high), Ordering::SeqCst), None);
assert_eq!(x.load(Ordering::SeqCst), Some(high));Sourcepub fn is_lock_free() -> bool
pub fn is_lock_free() -> bool
Returns true if operations on values of this type are lock-free.
If the compiler or the platform doesn’t support the necessary
atomic instructions, global locks for every potentially
concurrent atomic operation will be used.
§Examples
use atomic_time::AtomicOptionSystemTime;
let is_lock_free = AtomicOptionSystemTime::is_lock_free();Sourcepub const fn is_always_lock_free() -> bool
pub const fn is_always_lock_free() -> bool
Returns whether operations on values of this type are always lock-free.
A false result does not preclude lock-free operations selected through
runtime CPU feature detection; use is_lock_free
to query the current target at runtime.
§Examples
use atomic_time::AtomicOptionSystemTime;
const ALWAYS_LOCK_FREE: bool = AtomicOptionSystemTime::is_always_lock_free();
let _ = ALWAYS_LOCK_FREE;Sourcepub fn into_inner(self) -> Option<SystemTime>
pub fn into_inner(self) -> Option<SystemTime>
Consumes the atomic and returns the contained value.
This is safe because passing self by value guarantees that no other threads are
concurrently accessing the atomic data.
Trait Implementations§
Source§impl Arbitrary for AtomicOptionSystemTime
Available on crate feature quickcheck only.
impl Arbitrary for AtomicOptionSystemTime
quickcheck only.Source§impl Arbitrary for AtomicOptionSystemTime
Available on crate feature proptest only.
impl Arbitrary for AtomicOptionSystemTime
proptest only.Source§type Parameters = ()
type Parameters = ()
arbitrary_with accepts for configuration
of the generated Strategy. Parameters must implement Default.Source§type Strategy = BoxedStrategy<AtomicOptionSystemTime>
type Strategy = BoxedStrategy<AtomicOptionSystemTime>
Strategy used to generate values of type Self.Source§fn arbitrary_with(_: Self::Parameters) -> Self::Strategy
fn arbitrary_with(_: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for AtomicOptionSystemTime
Available on crate feature arbitrary only.
impl<'a> Arbitrary<'a> for AtomicOptionSystemTime
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl Clone for AtomicOptionSystemTime
Available on crate feature quickcheck only.
impl Clone for AtomicOptionSystemTime
quickcheck only.Source§fn clone(&self) -> Self
fn clone(&self) -> Self
Creates an atomic snapshot of this value with sequentially consistent ordering.
If another thread writes concurrently, the clone contains the value observed at this load’s atomic linearization point.
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AtomicOptionSystemTime
impl Debug for AtomicOptionSystemTime
Source§impl Default for AtomicOptionSystemTime
impl Default for AtomicOptionSystemTime
Source§impl<'de> Deserialize<'de> for AtomicOptionSystemTime
Available on crate feature serde only.
impl<'de> Deserialize<'de> for AtomicOptionSystemTime
serde only.Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl From<Option<SystemTime>> for AtomicOptionSystemTime
impl From<Option<SystemTime>> for AtomicOptionSystemTime
Source§fn from(system_time: Option<SystemTime>) -> Self
fn from(system_time: Option<SystemTime>) -> Self
§Panics
Panics if the given SystemTime value is earlier than UNIX_EPOCH.