pub struct AtomicOption<T: Well>(/* private fields */);Expand description
Potentially empty atomic potential well.
Internally, this just wraps a pointer to <T as Deref>::Target and uses atomic pointer
operations to access it. However, the number of operations on the pointer is limited to
ensure correctness in safe code.
Implementations§
Source§impl<T: Well> AtomicOption<T>
impl<T: Well> AtomicOption<T>
Sourcepub fn none() -> AtomicOption<T>
pub fn none() -> AtomicOption<T>
Creates atomic without anything inside.
Sourcepub fn some(well: T) -> AtomicOption<T>
pub fn some(well: T) -> AtomicOption<T>
Creates atomic with something inside.
Sourcepub unsafe fn as_raw_unchecked(&self) -> &AtomicPtr<<T as Deref>::Target>
pub unsafe fn as_raw_unchecked(&self) -> &AtomicPtr<<T as Deref>::Target>
Gives access to the underlying AtomicPtr.
§Safety
The pointer inside the atomic must always be null, or a valid pointer from Well::remove.
Additionally, keep in mind that this atomic owns the pointer, and if you want to move it
out, you must put a different pointer in its place first.
Sourcepub fn load(&self, ordering: Ordering) -> Option<&<T as Deref>::Target>
pub fn load(&self, ordering: Ordering) -> Option<&<T as Deref>::Target>
Loads the inner data as an immutable reference.
This is equivalent to an atomic load.
Sourcepub fn swap(&self, well: T, ordering: Ordering) -> Option<T>
pub fn swap(&self, well: T, ordering: Ordering) -> Option<T>
Atomically swaps the data inside the well.
This is equivalent to an atomic swap.
Sourcepub fn take(&self, ordering: Ordering) -> Option<T>
pub fn take(&self, ordering: Ordering) -> Option<T>
Takes the data out of the well.
This is equivalent to an atomic swap with a null pointer.
Sourcepub fn insert(
&self,
well: T,
success: Ordering,
failure: Ordering,
) -> Result<(), T>
pub fn insert( &self, well: T, success: Ordering, failure: Ordering, ) -> Result<(), T>
Inserts data into the well.
This uses compare_exchange to avoid inserting into the well if it’s already full. If you
want to use compare_exchange_weak instead, use insert_weak.
Sourcepub fn insert_weak(
&self,
well: T,
success: Ordering,
failure: Ordering,
) -> Result<(), T>
pub fn insert_weak( &self, well: T, success: Ordering, failure: Ordering, ) -> Result<(), T>
Inserts data into the well, sometimes failing spuriously.
This uses compare_exchange_weak to avoid inserting into the well if it’s already full,
which may spuriously fail. If you want to use compare_exchange instead, use insert.
Source§impl<T: WellMut<Target: Unpin>> AtomicOption<T>
impl<T: WellMut<Target: Unpin>> AtomicOption<T>
Source§impl<T: WellMut> AtomicOption<Pin<T>>
impl<T: WellMut> AtomicOption<Pin<T>>
Source§impl<T: Well + Clone> AtomicOption<T>
impl<T: Well + Clone> AtomicOption<T>
Sourcepub fn load_clone(&self, ordering: Ordering) -> Option<T>
pub fn load_clone(&self, ordering: Ordering) -> Option<T>
Loads a clone of the inner data.
This still performs an atomic load, but instead of offering a reference, the smart
pointer is cloned instead.
Trait Implementations§
Source§impl<T: Well> Default for AtomicOption<T>
By default, nothing is stored in the atomic.
impl<T: Well> Default for AtomicOption<T>
By default, nothing is stored in the atomic.