pub struct AtomicOption<W: Well> { /* private fields */ }Expand description
Potentially empty atomic potential well.
Internally, this just wraps a pointer to Bucket<T> 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<W: Well> AtomicOption<W>
impl<W: Well> AtomicOption<W>
Sourcepub fn none() -> AtomicOption<W>
pub fn none() -> AtomicOption<W>
Creates atomic without anything inside.
Sourcepub fn some(well: W) -> AtomicOption<W>
pub fn some(well: W) -> AtomicOption<W>
Creates atomic with something inside.
Sourcepub fn new(well: Option<W>) -> AtomicOption<W>
pub fn new(well: Option<W>) -> AtomicOption<W>
Creates atomic.
Sourcepub unsafe fn as_raw_unchecked(&self) -> &AtomicPtr<Bucket<W>>
pub unsafe fn as_raw_unchecked(&self) -> &AtomicPtr<Bucket<W>>
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 swap(&self, well: W, ordering: Ordering) -> Option<W>
pub fn swap(&self, well: W, ordering: Ordering) -> Option<W>
Atomically swaps the data inside the well.
This is equivalent to an atomic swap.
Sourcepub fn take(&self, ordering: Ordering) -> Option<W>
pub fn take(&self, ordering: Ordering) -> Option<W>
Takes the data out of the well.
This is equivalent to an atomic swap with a null pointer.
Sourcepub fn insert(
&self,
well: W,
success: Ordering,
failure: Ordering,
) -> Result<(), W>
pub fn insert( &self, well: W, success: Ordering, failure: Ordering, ) -> Result<(), W>
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: W,
success: Ordering,
failure: Ordering,
) -> Result<(), W>
pub fn insert_weak( &self, well: W, success: Ordering, failure: Ordering, ) -> Result<(), W>
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<W: WeakWell> AtomicOption<W>
impl<W: WeakWell> AtomicOption<W>
Source§impl<W: StrongWell> AtomicOption<W>
impl<W: StrongWell> AtomicOption<W>
Sourcepub fn load(&self, ordering: Ordering) -> Option<&Bucket<W>>
pub fn load(&self, ordering: Ordering) -> Option<&Bucket<W>>
Loads the inner data as an immutable reference.
This is equivalent to an atomic load.
Sourcepub fn swap_get(&self, well: W, ordering: Ordering) -> (Option<W>, &Bucket<W>)
pub fn swap_get(&self, well: W, ordering: Ordering) -> (Option<W>, &Bucket<W>)
Atomically swaps the data inside the well and returns a reference to the new data.
This is swap, but with the unsafe deref hidden behind a safe API.
Sourcepub fn insert_get(
&self,
well: W,
success: Ordering,
failure: Ordering,
) -> Result<&Bucket<W>, W>
pub fn insert_get( &self, well: W, success: Ordering, failure: Ordering, ) -> Result<&Bucket<W>, W>
Inserts data into the well and returns a reference to the new data.
This is insert, but with the unsafe deref hidden behind a safe API.
Sourcepub fn insert_weak_get(
&self,
well: W,
success: Ordering,
failure: Ordering,
) -> Result<&Bucket<W>, W>
pub fn insert_weak_get( &self, well: W, success: Ordering, failure: Ordering, ) -> Result<&Bucket<W>, W>
Inserts data into the well, returns reference to the new data, sometimes failing spuriously.
This is insert_weak, but with the unsafe deref hidden behind a safe API.
Source§impl<W: StrongWellMut + DerefMut<Target: Unpin>> AtomicOption<W>
impl<W: StrongWellMut + DerefMut<Target: Unpin>> AtomicOption<W>
Source§impl<W: StrongWellMut> AtomicOption<Pin<W>>
impl<W: StrongWellMut> AtomicOption<Pin<W>>
Source§impl<W: Well + Clone> AtomicOption<W>
impl<W: Well + Clone> AtomicOption<W>
Sourcepub fn load_clone(&self, ordering: Ordering) -> Option<W>
pub fn load_clone(&self, ordering: Ordering) -> Option<W>
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<W: Well> Default for AtomicOption<W>
By default, nothing is stored in the atomic.
impl<W: Well> Default for AtomicOption<W>
By default, nothing is stored in the atomic.