Struct portable_atomic::AtomicI64
source · [−]#[repr(C, align(8))]pub struct AtomicI64 { /* private fields */ }Expand description
An integer type which can be safely shared between threads.
This type has the same in-memory representation as the underlying integer type,
i64.
If the compiler or the platform supports atomic loads and stores of i64, this type is a wrapper for the standard library’s AtomicI64, otherwise synchronizes using global locks.
You can call AtomicI64::is_lock_free() to check whether
atomic instructions or locks will be used.
Implementations
sourceimpl AtomicI64
impl AtomicI64
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.
sourcepub const fn is_always_lock_free() -> bool
pub const fn is_always_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.
Note: If the atomic operation relies on dynamic CPU feature detection, this type may be lock-free even if the function returns false.
sourcepub fn get_mut(&mut self) -> &mut i64
pub fn get_mut(&mut self) -> &mut i64
Returns a mutable reference to the underlying integer.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
sourcepub fn into_inner(self) -> i64
pub fn into_inner(self) -> i64
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.
sourcepub fn swap(&self, val: i64, order: Ordering) -> i64
pub fn swap(&self, val: i64, order: Ordering) -> i64
Stores a value into the atomic integer, returning the previous value.
swap takes an Ordering argument which describes the memory ordering
of this operation. All ordering modes are possible. Note that using
Acquire makes the store part of this operation Relaxed, and
using Release makes the load part Relaxed.
sourcepub fn compare_exchange(
&self,
current: i64,
new: i64,
success: Ordering,
failure: Ordering
) -> Result<i64, i64>
pub fn compare_exchange(
&self,
current: i64,
new: i64,
success: Ordering,
failure: Ordering
) -> Result<i64, i64>
Stores a value into the atomic integer if the current value is the same as
the current value.
The return value is a result indicating whether the new value was written and
containing the previous value. On success this value is guaranteed to be equal to
current.
compare_exchange takes two Ordering arguments to describe the memory
ordering of this operation. success describes the required ordering for the
read-modify-write operation that takes place if the comparison with current succeeds.
failure describes the required ordering for the load operation that takes place when
the comparison fails. Using Acquire as success ordering makes the store part
of this operation Relaxed, and using Release makes the successful load
Relaxed. The failure ordering can only be SeqCst, Acquire or Relaxed
and must be equivalent to or weaker than the success ordering.
sourcepub fn compare_exchange_weak(
&self,
current: i64,
new: i64,
success: Ordering,
failure: Ordering
) -> Result<i64, i64>
pub fn compare_exchange_weak(
&self,
current: i64,
new: i64,
success: Ordering,
failure: Ordering
) -> Result<i64, i64>
Stores a value into the atomic integer if the current value is the same as
the current value.
Unlike compare_exchange
this function is allowed to spuriously fail even
when the comparison succeeds, which can result in more efficient code on some
platforms. The return value is a result indicating whether the new value was
written and containing the previous value.
compare_exchange_weak takes two Ordering arguments to describe the memory
ordering of this operation. success describes the required ordering for the
read-modify-write operation that takes place if the comparison with current succeeds.
failure describes the required ordering for the load operation that takes place when
the comparison fails. Using Acquire as success ordering makes the store part
of this operation Relaxed, and using Release makes the successful load
Relaxed. The failure ordering can only be SeqCst, Acquire or Relaxed
and must be equivalent to or weaker than the success ordering.
sourcepub fn fetch_add(&self, val: i64, order: Ordering) -> i64
pub fn fetch_add(&self, val: i64, order: Ordering) -> i64
Adds to the current value, returning the previous value.
This operation wraps around on overflow.
fetch_add takes an Ordering argument which describes the memory ordering
of this operation. All ordering modes are possible. Note that using
Acquire makes the store part of this operation Relaxed, and
using Release makes the load part Relaxed.
sourcepub fn fetch_sub(&self, val: i64, order: Ordering) -> i64
pub fn fetch_sub(&self, val: i64, order: Ordering) -> i64
Subtracts from the current value, returning the previous value.
This operation wraps around on overflow.
fetch_sub takes an Ordering argument which describes the memory ordering
of this operation. All ordering modes are possible. Note that using
Acquire makes the store part of this operation Relaxed, and
using Release makes the load part Relaxed.
sourcepub fn fetch_and(&self, val: i64, order: Ordering) -> i64
pub fn fetch_and(&self, val: i64, order: Ordering) -> i64
Bitwise “and” with the current value.
Performs a bitwise “and” operation on the current value and the argument val, and
sets the new value to the result.
Returns the previous value.
fetch_and takes an Ordering argument which describes the memory ordering
of this operation. All ordering modes are possible. Note that using
Acquire makes the store part of this operation Relaxed, and
using Release makes the load part Relaxed.
sourcepub fn fetch_nand(&self, val: i64, order: Ordering) -> i64
pub fn fetch_nand(&self, val: i64, order: Ordering) -> i64
Bitwise “nand” with the current value.
Performs a bitwise “nand” operation on the current value and the argument val, and
sets the new value to the result.
Returns the previous value.
fetch_nand takes an Ordering argument which describes the memory ordering
of this operation. All ordering modes are possible. Note that using
Acquire makes the store part of this operation Relaxed, and
using Release makes the load part Relaxed.
sourcepub fn fetch_or(&self, val: i64, order: Ordering) -> i64
pub fn fetch_or(&self, val: i64, order: Ordering) -> i64
Bitwise “or” with the current value.
Performs a bitwise “or” operation on the current value and the argument val, and
sets the new value to the result.
Returns the previous value.
fetch_or takes an Ordering argument which describes the memory ordering
of this operation. All ordering modes are possible. Note that using
Acquire makes the store part of this operation Relaxed, and
using Release makes the load part Relaxed.
sourcepub fn fetch_xor(&self, val: i64, order: Ordering) -> i64
pub fn fetch_xor(&self, val: i64, order: Ordering) -> i64
Bitwise “xor” with the current value.
Performs a bitwise “xor” operation on the current value and the argument val, and
sets the new value to the result.
Returns the previous value.
fetch_xor takes an Ordering argument which describes the memory ordering
of this operation. All ordering modes are possible. Note that using
Acquire makes the store part of this operation Relaxed, and
using Release makes the load part Relaxed.
sourcepub fn fetch_update<F>(
&self,
set_order: Ordering,
fetch_order: Ordering,
f: F
) -> Result<i64, i64> where
F: FnMut(i64) -> Option<i64>,
pub fn fetch_update<F>(
&self,
set_order: Ordering,
fetch_order: Ordering,
f: F
) -> Result<i64, i64> where
F: FnMut(i64) -> Option<i64>,
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.
sourcepub fn fetch_max(&self, val: i64, order: Ordering) -> i64
pub fn fetch_max(&self, val: i64, order: Ordering) -> i64
Maximum with the current value.
Finds the maximum of the current value and the argument val, and
sets the new value to the result.
Returns the previous value.
fetch_max takes an Ordering argument which describes the memory ordering
of this operation. All ordering modes are possible. Note that using
Acquire makes the store part of this operation Relaxed, and
using Release makes the load part Relaxed.
sourcepub fn fetch_min(&self, val: i64, order: Ordering) -> i64
pub fn fetch_min(&self, val: i64, order: Ordering) -> i64
Minimum with the current value.
Finds the minimum of the current value and the argument val, and
sets the new value to the result.
Returns the previous value.
fetch_min takes an Ordering argument which describes the memory ordering
of this operation. All ordering modes are possible. Note that using
Acquire makes the store part of this operation Relaxed, and
using Release makes the load part Relaxed.
Trait Implementations
sourceimpl<'de> Deserialize<'de> for AtomicI64
This is supported on crate feature serde only.
impl<'de> Deserialize<'de> for AtomicI64
serde only.sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl RefUnwindSafe for AtomicI64
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more