RcuPtr

Struct RcuPtr 

Source
pub struct RcuPtr<T> { /* private fields */ }
Expand description

A pointer managed by the RCU state machine.

This pointer can be read from multiple threads concurrently without blocking. When the pointer is written, reads may continue to see the old value of the pointer for some period of time.

Callers are responsible managing the lifetime of the object referenced by the pointer. When the the pointer value is written, the caller should typically use rcu_call or rcu_drop to defer cleanup of the object referenced by the old pointer value until the RCU state machine has made sufficient progress to ensure that no concurrent readers are holding read guards.

Implementations§

Source§

impl<T> RcuPtr<T>

Source

pub fn new(ptr: *mut T) -> Self

Create a new RCU pointer from a raw pointer.

Source

pub fn from_ref(reference: &T) -> Self

Create a new RCU pointer from a reference.

Source

pub fn null() -> Self

Create a null RCU pointer.

Source

pub fn get(&self) -> RcuReadGuard<T>

Get the value pointed to by the RCU pointer.

If the RCU pointer is null, this function will panic.

The object referenced by the RCU pointer will remain valid until the RcuReadGuard is dropped. However, another thread running concurrently might see a different value for the object.

Source

pub fn maybe_get(&self) -> Option<RcuReadGuard<T>>

Get the value pointed to by the RCU pointer.

If the RCU pointer is null, this function will return None.

The object referenced by the RCU pointer will remain valid until the RcuReadGuard is dropped. However, another thread running concurrently might see a different value for the object.

Source

pub fn read<'a>(&self, scope: &'a RcuReadScope) -> RcuPtrRef<'a, T>

Read the value of the RCU pointer.

The returned pointer will remain valid until the RcuReadScope is dropped. However, another thread running concurrently might see a different value for the object.

Source

pub fn assign(&self, ptr: *mut T)

Assign a new value to the RCU pointer.

Concurrent readers may continue to see the old value of the pointer until the RCU state machine has made sufficient progress. To wait until all concurrent readers have dropped their read guards, call rcu_synchronize().

Source

pub fn assign_ptr(&self, ptr: RcuPtrRef<'_, T>)

Assign a new value to the RCU pointer.

Concurrent readers may continue to see the old value of the pointer until the RCU state machine has made sufficient progress. To wait until all concurrent readers have dropped their read guards, call rcu_synchronize().

Source

pub fn replace(&self, ptr: *mut T) -> *mut T

Replace the value of the RCU pointer.

Concurrent readers may continue to see the old value of the pointer until the RCU state machine has made sufficient progress. To wait until all concurrent readers have dropped their read guards, call rcu_synchronize().

Source

pub fn replace_ptr(&self, ptr: RcuPtrRef<'_, T>) -> *mut T

Replace the value of the RCU pointer.

Concurrent readers may continue to see the old value of the pointer until the RCU state machine has made sufficient progress. To wait until all concurrent readers have dropped their read guards, call rcu_synchronize().

Source

pub fn poison(&self)

Poison the RCU pointer.

Poisoning the RCU pointer will cause readers to see a dangling pointer. Useful when the pointer is no longer valid for reading.

Trait Implementations§

Source§

impl<T: Debug> Debug for RcuPtr<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for RcuPtr<T>

§

impl<T> RefUnwindSafe for RcuPtr<T>

§

impl<T> Send for RcuPtr<T>

§

impl<T> Sync for RcuPtr<T>

§

impl<T> Unpin for RcuPtr<T>

§

impl<T> UnwindSafe for RcuPtr<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.