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
impl ThreadLocalArena
Sourcefn with_state<R, F: FnOnce(&mut ThreadLocalState) -> R>(f: F) -> R
fn with_state<R, F: FnOnce(&mut ThreadLocalState) -> R>(f: F) -> R
Access the thread-local state.
Sourcepub unsafe fn init()
pub unsafe fn init()
Initialize the arena with default capacity (called automatically on first use).
§Safety
Must be called from the R main thread.
Sourcepub unsafe fn init_with_capacity(capacity: usize)
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.
Sourcepub unsafe fn try_unprotect(x: SEXP) -> bool
pub unsafe fn try_unprotect(x: SEXP) -> bool
Sourcepub unsafe fn protect_fast(x: SEXP) -> SEXP
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()orinit_with_capacity().
Sourcepub unsafe fn unprotect_fast(x: SEXP)
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()orinit_with_capacity().
Sourcepub unsafe fn try_unprotect_fast(x: SEXP) -> bool
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()orinit_with_capacity().
Sourcepub fn is_protected(x: SEXP) -> bool
pub fn is_protected(x: SEXP) -> bool
Check if a SEXP is protected.
Auto Trait Implementations§
impl Freeze for ThreadLocalArena
impl RefUnwindSafe for ThreadLocalArena
impl Send for ThreadLocalArena
impl Sync for ThreadLocalArena
impl Unpin for ThreadLocalArena
impl UnsafeUnpin for ThreadLocalArena
impl UnwindSafe for ThreadLocalArena
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreLayout§
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