Skip to main content

Handle

Struct Handle 

Source
pub struct Handle { /* private fields */ }
Expand description

A thread-local handle to the garbage collector.

Obtain one with handle(). A Handle is cheap to clone (it is reference-counted) and serves two purposes:

  1. Accessing the managed heap. Call pin() to get a Guard that lets you allocate, load, and dereference managed pointers.
  2. Extending pointer lifetimes. Pass it to Local::protect to keep a reference alive past its Guard with hazard-pointer protection.

§Examples

let handle = handle();
let guard = handle.pin();
let node = Local::new(Node { value: 1 }, &guard);
let kept = node.protect(&handle); // outlives the guard
drop(guard);
assert_eq!(kept.value, 1);

Implementations§

Source§

impl Handle

Source

pub fn pin(&self) -> Guard

Returns a Guard that grants access to the managed heap.

While the guard is alive, you may allocate managed objects, load atomic pointers, and freely dereference any Local obtained from those loads. Internally, this pins the current thread to the global epoch (entering a phase-critical section).

§Examples
let handle = handle();
let guard = handle.pin();
// ... access the managed heap through `guard` ...
drop(guard);
Source

pub fn is_pinned(&self) -> bool

Returns true if this handle’s thread is currently pinned, that is, if a Guard obtained from this handle is alive.

§Examples
let handle = handle();
assert!(!handle.is_pinned());
let guard = handle.pin();
assert!(handle.is_pinned());
drop(guard);
assert!(!handle.is_pinned());
Source

pub fn help_collect(&self)

Voluntarily assists the collector with pending work.

Useful in long-running threads that rarely allocate: calling it periodically helps the collector make progress. It pins the thread briefly for the duration of the call.

§Examples
let handle = handle();
handle.help_collect();

Trait Implementations§

Source§

impl Clone for Handle

Source§

fn clone(&self) -> Handle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Protector for Handle

Source§

type Shield = HazardPointer

Source§

fn protect<T: TraceObj>(&self, ptr: ManPtr<T>) -> Self::Shield

Auto Trait Implementations§

§

impl !RefUnwindSafe for Handle

§

impl !Send for Handle

§

impl !Sync for Handle

§

impl !UnwindSafe for Handle

§

impl Freeze for Handle

§

impl Unpin for Handle

§

impl UnsafeUnpin for Handle

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.