Struct std::sys_common::thread_local_key::StaticKey
source · pub struct StaticKey {
key: AtomicUsize,
dtor: Option<unsafe extern "C" fn(_: *mut u8)>,
}
🔬This is a nightly-only experimental API. (
thread_local_internals
)Expand description
A type for TLS keys that are statically allocated.
This type is entirely unsafe
to use as it does not protect against
use-after-deallocation or use-during-deallocation.
The actual OS-TLS key is lazily allocated when this is used for the first
time. The key is also deallocated when the Rust runtime exits or destroy
is called, whichever comes first.
Examples
Fields§
§key: AtomicUsize
🔬This is a nightly-only experimental API. (
thread_local_internals
)Inner static TLS key (internals).
dtor: Option<unsafe extern "C" fn(_: *mut u8)>
🔬This is a nightly-only experimental API. (
thread_local_internals
)Destructor for the TLS value.
See Key::new
for information about when the destructor runs and how
it runs.
Implementations§
source§impl StaticKey
impl StaticKey
pub fn new(dtor: Option<unsafe extern "C" fn(_: *mut u8)>) -> StaticKey
🔬This is a nightly-only experimental API. (
thread_local_internals
)sourcepub unsafe fn get(&self) -> *mut u8
🔬This is a nightly-only experimental API. (thread_local_internals
)
pub unsafe fn get(&self) -> *mut u8
thread_local_internals
)Gets the value associated with this TLS key
This will lazily allocate a TLS key from the OS if one has not already been allocated.
sourcepub unsafe fn set(&self, val: *mut u8)
🔬This is a nightly-only experimental API. (thread_local_internals
)
pub unsafe fn set(&self, val: *mut u8)
thread_local_internals
)Sets this TLS key to a new value.
This will lazily allocate a TLS key from the OS if one has not already been allocated.
unsafe fn key(&self) -> pthread_key_t
🔬This is a nightly-only experimental API. (
thread_local_internals
)unsafe fn lazy_init(&self) -> usize
🔬This is a nightly-only experimental API. (
thread_local_internals
)Auto Trait Implementations§
impl RefUnwindSafe for StaticKey
impl Send for StaticKey
impl Sync for StaticKey
impl Unpin for StaticKey
impl UnwindSafe for StaticKey
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
Mutably borrows from an owned value. Read more