[][src]Trait reclaim::Protect

pub unsafe trait Protect where
    Self: Clone + Sized
{ type Reclaimer: Reclaim; fn release(&mut self);
fn protect<T, N: Unsigned>(
        &mut self,
        atomic: &Atomic<T, Self::Reclaimer, N>,
        order: Ordering
    ) -> Marked<Shared<T, Self::Reclaimer, N>>;
fn protect_if_equal<T, N: Unsigned>(
        &mut self,
        atomic: &Atomic<T, Self::Reclaimer, N>,
        expected: MarkedPtr<T, N>,
        order: Ordering
    ) -> AcquireResult<T, Self::Reclaimer, N>; fn try_fuse<T, N: Unsigned>(
        self,
        atomic: &Atomic<T, Self::Reclaimer, N>,
        order: Ordering
    ) -> Result<Guarded<T, Self, N>, Self> { ... } }

A trait for guard types that protect a specific value from reclamation during the lifetime of the protecting guard.

Examples

use core::sync::atomic::Ordering::Relaxed;

use reclaim::typenum::U0;
use reclaim::prelude::*;
// `Leaking` implements both `Protect` and `ProtectRegion`
use reclaim::leak::Guard;

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

let atomic = Atomic::new(1);

let mut guard = Guard::new();
let shared = atomic.load(Relaxed, &mut guard).unwrap();
assert_eq!(&*shared, &1);

Associated Types

type Reclaimer: Reclaim

The reclamation scheme associated with this type of guard

Loading content...

Required methods

fn release(&mut self)

Releases any current protection that may be provided by the guard.

By borrowing self mutably it is ensured that no loaded values protected by this guard can be used after calling this method. If Self additionally implements ProtectRegion, this is a no-op

fn protect<T, N: Unsigned>(
    &mut self,
    atomic: &Atomic<T, Self::Reclaimer, N>,
    order: Ordering
) -> Marked<Shared<T, Self::Reclaimer, N>>

Atomically takes a snapshot of atomic and returns a protected Shared reference wrapped in a Marked to it.

The loaded value is stored within self. If the value of atomic is null or a pure tag (marked null pointer), no protection has to be established. Any previously protected value will be overwritten and be no longer protected, regardless of the loaded value.

Panics

May panic if order is Release or AcqRel.

fn protect_if_equal<T, N: Unsigned>(
    &mut self,
    atomic: &Atomic<T, Self::Reclaimer, N>,
    expected: MarkedPtr<T, N>,
    order: Ordering
) -> AcquireResult<T, Self::Reclaimer, N>

Atomically takes a snapshot of atomic and returns a protected Shared reference wrapped in a Marked to it, if the loaded value is equal to expected.

A successfully loaded value is stored within self. If the value of atomic is null or a pure tag (marked null pointer), no protection has to be established. After a successful load, any previously protected value will be overwritten and be no longer protected, regardless of the loaded value. In case of a unsuccessful load, the previously protected value does not change.

Errors

This method returns an Err(NotEqualError) result, if the atomically loaded snapshot from atomic does not match the expected value.

Panics

May panic if order is Release or AcqRel.

Loading content...

Provided methods

fn try_fuse<T, N: Unsigned>(
    self,
    atomic: &Atomic<T, Self::Reclaimer, N>,
    order: Ordering
) -> Result<Guarded<T, Self, N>, Self>

Converts the guard into a Guarded by fusing it with a value loaded from atomic.

Errors

If the value loaded from atomic is null, this method instead self again, wrapped in an Err.

Loading content...

Implementors

impl Protect for Guard[src]

type Reclaimer = Leaking

fn release(&mut self)[src]

This is a no-op.

fn protect<T, N: Unsigned>(
    &mut self,
    atomic: &Atomic<T, N>,
    order: Ordering
) -> Marked<Shared<T, N>>
[src]

Acquires a value from shared memory.

fn protect_if_equal<T, N: Unsigned>(
    &mut self,
    atomic: &Atomic<T, N>,
    expected: MarkedPtr<T, N>,
    order: Ordering
) -> AcquireResult<T, Self::Reclaimer, N>
[src]

Acquires a value from shared memory if it equals expected.

Loading content...