Struct ferroc::heap::ThreadLocal

source ·
pub struct ThreadLocal<'arena, B: BaseAlloc> { /* private fields */ }
Expand description

A collection for thread-local heaps.

This structure serves as a substitute for builtin dynamic TLS support with __tls_get_addr, which uses its slow dlmalloc to allocate TLS variables.

Most of the direct utilities from this structure is unsafe. For usages that are totally safe, see the examples in ThreadData.

Implementations§

source§

impl<'arena, B: BaseAlloc> ThreadLocal<'arena, B>

source

pub const fn new(arena: &'arena Arenas<B>) -> Self

Creates a collection for thread-local heaps.

source

pub const fn empty_heap( &'static self ) -> Pin<&'static Heap<'static, 'static, B>>

The default uninitialized heap, serving as a const initialization thread-local heap references.

This method is safe because uninitialized heaps don’t mutate their inner data at all, thus practically Sync.

source§

impl<'arena, B: BaseAlloc> ThreadLocal<'arena, B>

source

pub unsafe fn get(self: Pin<&Self>, id: NonZeroU64) -> Pin<&Heap<'arena, '_, B>>

Acquire the current thread-local heap with this thread’s initialized id.

§Safety

id must be unique with each live thread regarding only this structure and may or may not be recycled.

source

pub fn assign(self: Pin<&Self>) -> (Pin<&Heap<'arena, '_, B>>, NonZeroU64)

Acquires a new thread id and initialize its associated heap.

§Examples

Users can Store the information in its thread-local variable in 2 ways:

  1. Store the thread ID only, and get access to the heap every time using self.get;
  2. Store both the thread ID and the pinned heap.

Both 2 ways needs to run its corresponding destructor manually. If RAII is preferred, ThreadData can be used instead.

§Panics

Panics if the acquisition failed.

source

pub unsafe fn put(self: Pin<&Self>, id: NonZeroU64)

Release the current thread-local heap with this thread’s id.

This function may be registered as the thread-local destructor when the current thread exits.

§Safety
  • id must be previously assigned.
  • The current thread must not use this id to access its thread-local heap.

Trait Implementations§

source§

impl<'arena, B: BaseAlloc> Drop for ThreadLocal<'arena, B>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'arena, B: BaseAlloc + Sync> Sync for ThreadLocal<'arena, B>

Auto Trait Implementations§

§

impl<'arena, B> !RefUnwindSafe for ThreadLocal<'arena, B>

§

impl<'arena, B> !Send for ThreadLocal<'arena, B>

§

impl<'arena, B> !Unpin for ThreadLocal<'arena, B>

§

impl<'arena, B> !UnwindSafe for ThreadLocal<'arena, B>

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>,

§

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>,

§

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.
source§

impl<T> BaseError for T