[−][src]Struct peril::HazardPointer
is the an atomic pointer that is safe to read when it is protected
Examples
use peril::{HazardRegistry, HazardValue, HazardRecord, HazardPointer}; let registry = HazardRegistry::default(); let hp = HazardPointer::new(HazardValue::boxed("test")); let mut record = HazardRecord::default(); loop { let scope = hp.protect(®istry, &mut record); // ... break; }
Implementations
impl<T: Send + ?Sized> HazardPointer<T>
[src]
pub fn new(value: HazardValue<'_, T>) -> HazardPointer<T>
[src]
create a HazardPointer
Arguments
value
- the HazardValue the pointer is initzialized with
Examples
use peril::{HazardRegistry, HazardValue, HazardRecord, HazardPointer, Ordering}; let hp = HazardPointer::new(HazardValue::boxed("test"));
#[must_use]pub fn protect<'registry, 'hazard>(
&'hazard self,
registry: &'registry HazardRegistry<T>,
record: &'hazard mut HazardRecord<'registry>
) -> HazardScope<'registry, 'hazard, T>
[src]
&'hazard self,
registry: &'registry HazardRegistry<T>,
record: &'hazard mut HazardRecord<'registry>
) -> HazardScope<'registry, 'hazard, T>
protect the hazardpointer so that it is safe to read and update using a CAS operation
Arguments
registry
- the HazardRegistry the pointer is registered with, usually HazardPointers in the same system share a common Registryrecord
- the HazardRecord, which caches an expensive operation for multiple itterations of the update loop
Examples
use peril::{HazardRegistry, HazardValue, HazardRecord, HazardPointer}; let registry = HazardRegistry::default(); let hp = HazardPointer::new(HazardValue::boxed("test")); let mut record = HazardRecord::default(); loop { let scope = hp.protect(®istry, &mut record); // ... break; }
pub fn compare_exchange_weak<'registry>(
&self,
registry: &'registry HazardRegistry<T>,
current: HazardValue<'registry, T>,
new: HazardValue<'registry, T>,
success: Ordering,
failure: Ordering
) -> Result<HazardValue<'registry, T>, HazardValue<'registry, T>>
[src]
&self,
registry: &'registry HazardRegistry<T>,
current: HazardValue<'registry, T>,
new: HazardValue<'registry, T>,
success: Ordering,
failure: Ordering
) -> Result<HazardValue<'registry, T>, HazardValue<'registry, T>>
compare_exchange_weak version of HazardPointer that uses a HazardValue as it's current value (comperator) 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
registry
- the HazardRegistry the pointer is registered with, usually HazardPointers in the same system share a common Registrycurrent
- the HazardValue used as a comparatornew
- 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, HazardPointer, Ordering}; let registry = HazardRegistry::default(); let hp = HazardPointer::<usize>::new(HazardValue::dummy(1)); loop { if hp.compare_exchange_weak(®istry, HazardValue::dummy(1), HazardValue::dummy(0), Ordering::Relaxed, Ordering::Relaxed).is_ok() { break; } }
pub fn compare_exchange<'registry>(
&self,
registry: &'registry HazardRegistry<T>,
current: HazardValue<'registry, T>,
new: HazardValue<'registry, T>,
success: Ordering,
failure: Ordering
) -> Result<HazardValue<'registry, T>, HazardValue<'registry, T>>
[src]
&self,
registry: &'registry HazardRegistry<T>,
current: HazardValue<'registry, T>,
new: HazardValue<'registry, T>,
success: Ordering,
failure: Ordering
) -> Result<HazardValue<'registry, T>, HazardValue<'registry, T>>
compare_exchange version of HazardPointer that uses a HazardValue as it's current value (comperator) 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
registry
- the HazardRegistry the pointer is registered with, usually HazardPointers in the same system share a common Registrycurrent
- the HazardValue used as a comparatornew
- 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, HazardPointer, Ordering}; let registry = HazardRegistry::default(); let hp = HazardPointer::<usize>::new(HazardValue::dummy(1)); loop { if hp.compare_exchange(®istry, HazardValue::dummy(1), HazardValue::dummy(0), Ordering::Relaxed, Ordering::Relaxed).is_ok() { break; } }
pub fn swap<'registry>(
&self,
registry: &'registry HazardRegistry<T>,
new: HazardValue<'registry, T>,
order: Ordering
) -> HazardValue<'registry, T>
[src]
&self,
registry: &'registry HazardRegistry<T>,
new: HazardValue<'registry, T>,
order: Ordering
) -> HazardValue<'registry, T>
swaps the value of a HazardPointer returning the old value
Arguments
registry
- the HazardRegistry the pointer is registered with, usually HazardPointers in the same system share a common Registrynew
- the HazardValue after the swaporder
- the Ordering during the swap operationreturn
- the HazardValue before the swap
Examples
use peril::{HazardRegistry, HazardValue, HazardRecord, HazardPointer, Ordering}; let registry = HazardRegistry::default(); let hp = HazardPointer::new(HazardValue::boxed("test")); let old = hp.swap(®istry, HazardValue::boxed("test2"), Ordering::Relaxed); assert!(old.as_ref().unwrap() == &"test");
pub fn swap_null<'registry>(
&self,
registry: &'registry HazardRegistry<T>,
order: Ordering
) -> HazardValue<'registry, T>
[src]
&self,
registry: &'registry HazardRegistry<T>,
order: Ordering
) -> HazardValue<'registry, T>
swaps the value of a HazardPointer with a null dummy HazardValue
Arguments
registry
- the HazardRegistry the pointer is registered with, usually HazardPointers in the same system share a common Registryorder
- the Ordering during the swap operationreturn
- the HazardValue before the swap
Examples
use peril::{HazardRegistry, HazardValue, HazardRecord, HazardPointer, Ordering}; let registry = HazardRegistry::default(); let hp = HazardPointer::new(HazardValue::boxed("test")); let old = hp.swap_null(®istry, Ordering::Relaxed); assert!(old.as_ref().unwrap() == &"test"); let old = hp.swap_null(®istry, Ordering::Relaxed); assert!(old.as_dummy().unwrap() == 0);
pub fn store<'registry>(
&self,
registry: &'registry HazardRegistry<T>,
new: HazardValue<'registry, T>,
order: Ordering
)
[src]
&self,
registry: &'registry HazardRegistry<T>,
new: HazardValue<'registry, T>,
order: Ordering
)
stores a new value of a HazardPointer and drops the old value, this internally uses a swap operation
Arguments
registry
- the HazardRegistry the pointer is registered with, usually HazardPointers in the same system share a common Registrynew
- the HazardValue after the storeorder
- the Ordering during the store operation
Examples
use peril::{HazardRegistry, HazardValue, HazardRecord, HazardPointer, Ordering}; let registry = HazardRegistry::default(); let hp = HazardPointer::new(HazardValue::boxed("test")); hp.store(®istry, HazardValue::dummy(1337), Ordering::Relaxed); let old = hp.swap(®istry, HazardValue::boxed("test2"), Ordering::Relaxed); assert!(old.as_dummy().unwrap() == 1337);
pub fn get_dummy(&self, order: Ordering) -> Option<usize>
[src]
get the value of the HazardPointer but only if it is a dummy
Arguments
order
- the Ordering during the store operation
Examples
use peril::{HazardRegistry, HazardValue, HazardRecord, HazardPointer, Ordering}; let hp = HazardPointer::<usize>::new(HazardValue::dummy(1337)); assert!(hp.get_dummy(Ordering::Relaxed).unwrap() == 1337);
Trait Implementations
Auto Trait Implementations
impl<T: ?Sized> RefUnwindSafe for HazardPointer<T>
[src]
impl<T: ?Sized> Send for HazardPointer<T>
[src]
impl<T: ?Sized> Sync for HazardPointer<T>
[src]
impl<T: ?Sized> Unpin for HazardPointer<T>
[src]
impl<T: ?Sized> UnwindSafe for HazardPointer<T> where
T: RefUnwindSafe,
[src]
T: RefUnwindSafe,
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>,