[][src]Struct reclaim::Unlinked

#[must_use = "unlinked values are meant to be retired, otherwise a memory leak is highly likely"]
pub struct Unlinked<T, R, N> { /* fields omitted */ }

A reference to a value that has been removed from its previous location in memory and is hence no longer reachable by other threads.

Unlinked values are the result of (successful) atomic swap or compare-and-swap operations on Atomic values. They are move-only types, but they don't have full ownership semantics, either. Dropping an Unlinked value without explicitly retiring it almost certainly results in a memory leak.

The safety invariants around retiring Unlinked references are explained in detail in the documentation for retire_local.

Methods

impl<T, R: Reclaim, N: Unsigned> Unlinked<T, R, N>[src]

pub fn none() -> Option<Self>[src]

Creates a None variant for an Option<Self>.

This is useful for calls to store, swap or compare_exchange_*, when a null pointer needs to be inserted. These methods accept values of various non-nullable pointer types (Shared, Owned, Unlinked and Unprotected) and Option types thereof as argument. However, the compiler is usually not able to infer the concrete type, when a None is inserted, and this function is intended for these cases.

Example

use std::sync::atomic::Ordering;

type Atomic<T> = reclaim::leak::Atomic<T, reclaim::typenum::U0>;
type Owned<T> = reclaim::leak::Owned<T, reclaim::typenum::U0>;
type Unlinked<T> = reclaim::leak::Unlinked<T, reclaim::typenum::U0>;

let atomic = Atomic::new(1);
let swap = atomic.swap(Owned::none(), Ordering::Relaxed).unwrap();

assert_eq!(swap.as_ref(), &1);
unsafe { Unlinked::retire(swap) }; // leaks memory

pub fn null() -> Marked<Self>[src]

Creates an unmarked Null variant for a Marked<Self>.

pub fn null_with_tag(tag: usize) -> Marked<Self>[src]

Creates a marked Null variant for a Marked<Self> with the given tag.

pub fn compose(unlinked: Self, tag: usize) -> Self[src]

Consumes the given Self and returns the same value but with the specified tag.

Any previous tag is overwritten.

pub fn decompose_ref(unlinked: &Self) -> (&T, usize)[src]

Decomposes the marked reference, returning the reference itself and the separated tag.

pub fn into_unprotected(shared: Self) -> Unprotected<T, R, N>[src]

Converts the Unlinked reference into an Unprotected.

pub unsafe fn cast<U>(unlinked: Self) -> Unlinked<U, R, N>[src]

Casts the Unlinked to a reference to a different type.

Safety

The caller has to ensure the cast is valid.

pub unsafe fn retire_local(self, local: &R::Local) where
    T: 'static, 
[src]

Retires a record by calling retire_local on the generic reclamation parameter R.

Safety

The same caveats as with LocalReclaim::retire_local apply.

Note

This method takes self as receiver, which means it may conflict with methods of T, since Unlinked implements Deref. This is a deliberate trade-off in favor of better ergonomics around retiring records.

pub unsafe fn retire_local_unchecked(self, local: &R::Local)[src]

Retires a record by calling retire_local_unchecked on the generic reclamation parameter R.

Safety

The same caveats as with LocalReclaim::retire_local_unchecked apply.

Note

This method takes self as receiver, which means it may conflict with methods of T, since Unlinked implements Deref. This is a deliberate trade-off in favor of better ergonomics around retiring records.

impl<T, R: GlobalReclaim, N: Unsigned> Unlinked<T, R, N>[src]

pub unsafe fn retire(self) where
    T: 'static, 
[src]

Retires a record by calling retire on the generic reclamation parameter R.

Safety

The same caveats as with Reclaim::retire apply.

Note

This method takes self as receiver, which means it may conflict with methods of T, since Unlinked implements Deref. This is a deliberate trade-off in favor of better ergonomics around retiring records.

pub unsafe fn retire_unchecked(self)[src]

Retires a record by calling retire_unchecked on the generic reclamation parameter R.

Safety

The same caveats as with Reclaim::retire_unchecked apply.

Note

This method takes self as receiver, which means it may conflict with methods of T, since Unlinked implements Deref. This is a deliberate trade-off in favor of better ergonomics around retiring records.

Trait Implementations

impl<T, R: Reclaim, N: Unsigned> MarkedPointer for Unlinked<T, R, N>[src]

type Pointer = Self

The pointer type.

type Item = T

The pointed-to type.

type MarkBits = N

Number of bits available for tagging.

impl<T, R, N: Unsigned> NonNullable for Unlinked<T, R, N>[src]

type Item = T

The pointed-to type.

type MarkBits = N

Number of bits available for tagging.

impl<T: PartialEq, R: PartialEq, N: PartialEq> PartialEq<Unlinked<T, R, N>> for Unlinked<T, R, N>[src]

impl<T, R: Reclaim, N: Unsigned> AsRef<T> for Unlinked<T, R, N>[src]

impl<T: PartialOrd, R: PartialOrd, N: PartialOrd> PartialOrd<Unlinked<T, R, N>> for Unlinked<T, R, N>[src]

impl<T: Eq, R: Eq, N: Eq> Eq for Unlinked<T, R, N>[src]

impl<T: Ord, R: Ord, N: Ord> Ord for Unlinked<T, R, N>[src]

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl<T, R: Reclaim, N: Unsigned> Deref for Unlinked<T, R, N>[src]

type Target = T

The resulting type after dereferencing.

impl<T, R: Reclaim, N: Unsigned> Debug for Unlinked<T, R, N>[src]

impl<T, R: Reclaim, N: Unsigned> Pointer for Unlinked<T, R, N>[src]

Auto Trait Implementations

impl<T, R, N> Unpin for Unlinked<T, R, N> where
    N: Unpin,
    R: Unpin,
    T: Unpin

impl<T, R, N> !Sync for Unlinked<T, R, N>

impl<T, R, N> !Send for Unlinked<T, R, N>

impl<T, R, N> RefUnwindSafe for Unlinked<T, R, N> where
    N: RefUnwindSafe,
    R: RefUnwindSafe,
    T: RefUnwindSafe

impl<T, R, N> UnwindSafe for Unlinked<T, R, N> where
    N: UnwindSafe,
    R: UnwindSafe,
    T: RefUnwindSafe + UnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same<T> for T[src]

type Output = T

Should always be Self