AtomicSystemTime

Struct AtomicSystemTime 

Source
pub struct AtomicSystemTime(/* private fields */);
Available on crate feature std only.
Expand description

An atomic version of std::time::SystemTime.

Implementations§

Source§

impl AtomicSystemTime

Source

pub fn now() -> Self

Returns the system time corresponding to “now”.

§Examples
use atomic_time::AtomicSystemTime;

let sys_time = AtomicSystemTime::now();
Source

pub fn new(system_time: SystemTime) -> Self

Creates a new AtomicSystemTime with the given SystemTime value.

§Panics

If the given SystemTime value is earlier than the UNIX_EPOCH.

Source

pub fn load(&self, order: Ordering) -> SystemTime

Loads a value from the atomic system time.

Source

pub fn store(&self, system_time: SystemTime, order: Ordering)

Stores a value into the atomic system time.

§Panics

If the given SystemTime value is earlier than the UNIX_EPOCH.

Source

pub fn swap(&self, system_time: SystemTime, order: Ordering) -> 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.

Source

pub fn compare_exchange( &self, current: SystemTime, new: SystemTime, success: Ordering, failure: Ordering, ) -> Result<SystemTime, 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.

Source

pub fn compare_exchange_weak( &self, current: SystemTime, new: SystemTime, success: Ordering, failure: Ordering, ) -> Result<SystemTime, 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.

Source

pub fn fetch_update<F>( &self, set_order: Ordering, fetch_order: Ordering, f: F, ) -> Result<SystemTime, 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::AtomicSystemTime;
use std::{time::{Duration, SystemTime}, sync::atomic::Ordering};

let now = SystemTime::now();
let x = AtomicSystemTime::new(now);
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(now));

assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + Duration::from_secs(1))), Ok(now));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + Duration::from_secs(1))), Ok(now + Duration::from_secs(1)));
assert_eq!(x.load(Ordering::SeqCst), now + Duration::from_secs(2));
Source

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::AtomicSystemTime;

let is_lock_free = AtomicSystemTime::is_lock_free();

Trait Implementations§

Source§

impl<'de> Deserialize<'de> for AtomicSystemTime

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for AtomicSystemTime

Available on crate feature serde only.
Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,