Struct ThreadLocalStorage

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

Provider for thread local storage. For non-test usage, there should generally be a single process-wide instance.

Implementations§

Source§

impl ThreadLocalStorage

Source

pub const unsafe fn new(preferred_mode: Mode) -> Self

§Safety

See Mode for detailed safety requirements. No matter the preferred mode, we fall back to Mode::Gettid if native thread local storage isn’t set up for a given thread, so that mode’s requirements must always be met: each thread using this thread local storage must call Self::unregister_current_thread before exiting.

Source

pub unsafe fn unregister_current_thread(&self)

Release this thread’s thread local storage and exit the thread.

Should be called by every thread that accesses thread local storage. This is a no-op when using native thread-local storage, but is required for correctness otherwise, since thread IDs can be reused.

Panics if there are still any live references to this thread’s ShimTlsVars.

§Safety

The calling thread must not access this ThreadLocalStorage again before exiting.

Source

pub fn current_key(&self) -> Option<ThreadLocalStorageKey>

An opaque key referencing this thread’s thread-local-storage.

None if the current thread uses native TLS.

Source

pub unsafe fn fork_from(&self, prev_key: Option<ThreadLocalStorageKey>)

Reassigns storage from prev_id to the current thread, and drops storage for all other threads.

Meant to be called after forking a new process from a thread with ID prev_id.

§Safety

self must not be shared with any other threads. Typically this is ensured by calling this function after fork (but not vfork), and before any additional threads are created from the new process.

Current thread must have the same native thread local storage as the parent; It is sufficient for parent to not have used CLONE_SETTLS when creating the current 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> NoTypeInference for T

Source§

type This = T

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.