Skip to main content

ThreadLocalArena

Struct ThreadLocalArena 

Source
pub struct ThreadLocalArena;
Expand description

Thread-local, BTreeMap-backed reference-counted GC protection arena.

This provides the lowest overhead for protection operations by eliminating RefCell borrow checking — each thread gets its own ThreadLocalState (private) accessed through an UnsafeCell.

use miniextendr_api::refcount_protect::ThreadLocalArena;
unsafe { ThreadLocalArena::protect(x) };

Implementations§

Source§

impl ThreadLocalArena

Source

fn with_state<R, F: FnOnce(&mut ThreadLocalState) -> R>(f: F) -> R

Access the thread-local state.

Source

pub unsafe fn init()

Initialize the arena with default capacity (called automatically on first use).

§Safety

Must be called from the R main thread.

Source

pub unsafe fn init_with_capacity(capacity: usize)

Initialize the arena with specific capacity.

Use this when you know the expected number of distinct protected values to avoid backing VECSXP growth and map rehashing during operation.

If already initialized, this is a no-op.

§Safety

Must be called from the R main thread.

Source

pub unsafe fn protect(x: SEXP) -> SEXP

Protect a SEXP, incrementing its reference count.

§Safety

Must be called from the R main thread.

Source

pub unsafe fn unprotect(x: SEXP)

Unprotect a SEXP.

§Safety

Must be called from the R main thread.

Source

pub unsafe fn try_unprotect(x: SEXP) -> bool

Try to unprotect a SEXP.

§Safety

Must be called from the R main thread.

Source

pub unsafe fn protect_fast(x: SEXP) -> SEXP

Protect without checking initialization.

For hot loops where init() or init_with_capacity() has already been called.

§Safety
  • Must be called from the R main thread.
  • The arena must have been initialized via init() or init_with_capacity().
Source

pub unsafe fn unprotect_fast(x: SEXP)

Unprotect without checking initialization.

For hot loops where init() or init_with_capacity() has already been called.

§Safety
  • Must be called from the R main thread.
  • The arena must have been initialized via init() or init_with_capacity().
Source

pub unsafe fn try_unprotect_fast(x: SEXP) -> bool

Try to unprotect without checking initialization.

For hot loops where init() or init_with_capacity() has already been called.

§Safety
  • Must be called from the R main thread.
  • The arena must have been initialized via init() or init_with_capacity().
Source

pub fn is_protected(x: SEXP) -> bool

Check if a SEXP is protected.

Source

pub fn ref_count(x: SEXP) -> usize

Get reference count.

Source

pub fn len() -> usize

Number of protected SEXPs.

Source

pub fn is_empty() -> bool

Check if empty.

Source

pub fn capacity() -> usize

Get capacity.

Source

pub unsafe fn clear()

Clear all protections.

§Safety

Must be called from the R main thread.

Auto Trait Implementations§

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> SizeHint for T
where T: ?Sized,

Source§

default fn lower_bound(&self) -> usize

🔬This is a nightly-only experimental API. (core_io_internals)
Returns a lower bound on the number of elements this container-like item contains. For example, an array [u8; 12] could return any value between 0 and 12 inclusively as a correct implementation. Read more
Source§

default fn upper_bound(&self) -> Option<usize>

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an upper bound on the number of elements this container-like item contains if it can be determined, otherwise None. Read more
Source§

final fn size_hint(&self) -> (usize, Option<usize>)

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an estimate for the number of elements this container like type contains. Read more
Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. 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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 0 bytes