Skip to main content

Guard

Struct Guard 

Source
pub struct Guard<'a> { /* private fields */ }
Expand description

A guard that keeps the current thread marked as active, enabling protected loads of atomic pointers.

See Collector::enter for details.

Implementations§

Source§

impl Guard<'_>

Source

pub const unsafe fn unprotected() -> Guard<'static>

Returns a dummy guard.

Calling protect on an unprotected guard will load the pointer directly, and retire will reclaim objects immediately.

Unprotected guards are useful when calling guarded functions on a data structure that has just been created or is about to be destroyed, because you know that no other thread holds a reference to it.

§Safety

You must ensure that code used with this guard is sound with the unprotected behavior described above.

Source

pub fn protect<T>(&self, ptr: &Atomic<*mut T>, ordering: Ordering) -> *mut T
where T: AsLink,

Protects the load of an atomic pointer.

See the guide for details.

Source

pub unsafe fn defer_retire<T>(&self, ptr: *mut T, reclaim: unsafe fn(*mut Link))
where T: AsLink,

Retires a value, running reclaim when no threads hold a reference to it.

This method delays reclamation until the guard is dropped as opposed to Collector::retire, which may reclaim objects immediately.

See the guide for details.

Source

pub fn collector(&self) -> Option<&Collector>

Get a reference to the collector this guard we created from.

This method is useful when you need to ensure that all guards used with a data structure come from the same collector.

If this is an unprotected guard this method will return None.

Source

pub fn refresh(&mut self)

Refreshes the guard.

Refreshing a guard is similar to dropping and immediately creating a new guard. The curent thread remains active, but any pointers that were previously protected may be reclaimed.

§Safety

This method is not marked as unsafe, but will affect the validity of pointers returned by protect, similar to dropping a guard. It is intended to be used safely by users of concurrent data structures, as references will be tied to the guard and this method takes &mut self.

If this is an unprotected guard this method will be a no-op.

Source

pub fn flush(&self)

Flush any retired values in the local batch.

This method flushes any values from the current thread’s local batch, starting the reclamation process. Note that no memory can be reclaimed while this guard is active, but calling flush may allow memory to be reclaimed more quickly after the guard is dropped.

See Collector::batch_size for details about batching.

Source

pub fn thread_id(&self) -> usize

Returns a numeric identifier for the current thread.

Guards rely on thread-local state, including thread IDs. If you already have a guard you can use this method to get a cheap identifier for the current thread, avoiding TLS overhead. Note that thread IDs may be reused, so the value returned is only unique for the lifetime of this thread.

Trait Implementations§

Source§

impl Debug for Guard<'_>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for Guard<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a> !Send for Guard<'a>

§

impl<'a> !Sync for Guard<'a>

§

impl<'a> Freeze for Guard<'a>

§

impl<'a> RefUnwindSafe for Guard<'a>

§

impl<'a> Unpin for Guard<'a>

§

impl<'a> UnsafeUnpin for Guard<'a>

§

impl<'a> UnwindSafe for Guard<'a>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.