[−][src]Struct peril::HazardScope
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"), ®istry); 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]
self,
new: HazardValue<'registry, T>,
success: Ordering,
failure: Ordering
) -> Result<HazardValue<'registry, T>, HazardValue<'registry, T>>
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 succeedsfailure
- the Ordering when the CAS failsreturn
- 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"), ®istry); 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]
self,
new: HazardValue<'registry, T>,
success: Ordering,
failure: Ordering
) -> Result<HazardValue<'registry, T>, HazardValue<'registry, T>>
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 succeedsfailure
- the Ordering when the CAS failsreturn
- 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"), ®istry); 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), ®istry); 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), ®istry); 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), ®istry); 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]
T: RefUnwindSafe,
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]
'registry: 'hazard,
impl<'registry, 'hazard, T> !UnwindSafe for HazardScope<'registry, 'hazard, T>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,