[][src]Struct peril::HazardScope

pub struct HazardScope<'registry, 'hazard, T: Send + 'registry> { /* fields omitted */ }

is the scope where the HazardPointer can be safely read

Examples

use peril::{HazardRegistry, HazardValue, HazardRecord, HazardPointer, Ordering};

let registry = HazardRegistry::default();
let hp = HazardPointer::new(HazardValue::boxed("test"), &registry);
let mut record = HazardRecord::default();
loop {
    let scope = hp.protect(&mut record);
    // ...
    if scope.compare_exchange_weak(HazardValue::dummy(0), Ordering::Relaxed, Ordering::Relaxed).is_ok()
    {
        break;
    }
}

Implementations

impl<'registry, 'hazard, T: Send + 'registry> HazardScope<'registry, 'hazard, T>[src]

pub fn compare_exchange_weak(
    self,
    new: HazardValue<'registry, T>,
    success: Ordering,
    failure: Ordering
) -> Result<HazardValue<'registry, T>, HazardValue<'registry, T>>
[src]

compare_exchange_weak version of HazardPointer that needs to use a protected HazardScope as the current value (comperator) is saved when the potection starts so that the value can be safely read and copied. When the CAS succeeds it will return the previous value held by the HazardPointer and when the CAS fails it will return the new value we just provided. for more detail see compare_exchange_weak

Arguments

  • new - the new value the HazardPointer should have when the CAS succeeds (and returned when the CAS fails)
  • success - the Ordering when the CAS succeeds
  • failure - the Ordering when the CAS fails
  • return - Result wrapping the old value if the CAS succeeds or the new value if it failed

Examples

use peril::{HazardRegistry, HazardValue, HazardRecord, HazardPointer, Ordering};

let registry = HazardRegistry::default();
let hp = HazardPointer::new(HazardValue::boxed("test"), &registry);
let mut record = HazardRecord::default();
loop {
    let scope = hp.protect(&mut record);
    // ...
    if scope.compare_exchange_weak(HazardValue::dummy(0), Ordering::Relaxed, Ordering::Relaxed).is_ok()
    {
        break;
    }
}

pub fn compare_exchange(
    self,
    new: HazardValue<'registry, T>,
    success: Ordering,
    failure: Ordering
) -> Result<HazardValue<'registry, T>, HazardValue<'registry, T>>
[src]

compare_exchange version of HazardPointer that needs to use a protected HazardScope as the current value (comperator) is saved when the potection starts so that the value can be safely read and copied. When the CAS succeeds it will return the previous value held by the HazardPointer and when the CAS fails it will return the new value we just provided. for more detail see compare_exchange

Arguments

  • new - the new value the HazardPointer should have when the CAS succeeds (and returned when the CAS fails)
  • success - the Ordering when the CAS succeeds
  • failure - the Ordering when the CAS fails
  • return - Result wrapping the old value if the CAS succeeds or the new value if it failed

Examples

use peril::{HazardRegistry, HazardValue, HazardRecord, HazardPointer, Ordering};

let registry = HazardRegistry::default();
let hp = HazardPointer::new(HazardValue::boxed("test"), &registry);
let mut record = HazardRecord::default();
loop {
    let scope = hp.protect(&mut record);
    // ...
    if scope.compare_exchange(HazardValue::dummy(0), Ordering::Relaxed, Ordering::Relaxed).is_ok()
    {
        break;
    }
}

pub fn is_dummy(&self) -> bool[src]

check if the protected value is a dummy

Examples

use peril::{HazardRegistry, HazardValue, HazardRecord, HazardPointer};

let registry = HazardRegistry::<usize>::default();
let hp = HazardPointer::new(HazardValue::dummy(0), &registry);
let mut record = HazardRecord::default();
loop {
    let scope = hp.protect(&mut record);
    assert!(scope.is_dummy());
    // ...
    break;
}

pub fn as_dummy(&self) -> Option<usize>[src]

read the dummy (pointer) value of a HazardPointer

Examples

use peril::{HazardRegistry, HazardValue, HazardRecord, HazardPointer};

let registry = HazardRegistry::<usize>::default();
let hp = HazardPointer::new(HazardValue::dummy(1337), &registry);
let mut record = HazardRecord::default();
loop {
    let scope = hp.protect(&mut record);
    assert!(scope.as_dummy().unwrap() == 1337);
    // ...
    break;
}

pub fn as_ref(&self) -> Option<&T>[src]

read the boxed value of a HazardPointer and returns None if the value is a dummy

Examples

use peril::{HazardRegistry, HazardValue, HazardRecord, HazardPointer, Ordering};

let registry = HazardRegistry::default();
let hp = HazardPointer::new(HazardValue::boxed(0), &registry);
let mut record = HazardRecord::default();
loop {
    let scope = hp.protect(&mut record);
    let new = *(scope.as_ref().unwrap()) + 1;
    match scope.compare_exchange(HazardValue::boxed(new), Ordering::Relaxed, Ordering::Relaxed)
    {
        Ok(old) =>
        {
            assert!(old.as_ref().unwrap() == &0);
            break;
        }
        Err(_) => assert!(false),
    }
}

Trait Implementations

impl<'registry, 'hazard, T: Send + 'registry> Drop for HazardScope<'registry, 'hazard, T>[src]

Auto Trait Implementations

impl<'registry, 'hazard, T> RefUnwindSafe for HazardScope<'registry, 'hazard, T> where
    T: RefUnwindSafe
[src]

impl<'registry, 'hazard, T> !Send for HazardScope<'registry, 'hazard, T>[src]

impl<'registry, 'hazard, T> !Sync for HazardScope<'registry, 'hazard, T>[src]

impl<'registry, 'hazard, T> Unpin for HazardScope<'registry, 'hazard, T> where
    'registry: 'hazard, 
[src]

impl<'registry, 'hazard, T> !UnwindSafe for HazardScope<'registry, 'hazard, T>[src]

Blanket Implementations

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

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

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

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.