about summary refs log tree commit diff
path: root/src/libstd/sys/unix/thread_local_key.rs
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-07-12 11:37:11 +0200
committerRalf Jung <post@ralfj.de>2020-07-12 11:46:42 +0200
commit8082fb988a5915e693f18e6d299deaae64834079 (patch)
treed130a0b12b800c15daf7801429dc3b1e374301f1 /src/libstd/sys/unix/thread_local_key.rs
parentdaecab3a784f28082df90cebb204998051f3557d (diff)
downloadrust-8082fb988a5915e693f18e6d299deaae64834079.tar.gz
rust-8082fb988a5915e693f18e6d299deaae64834079.zip
rename fast_thread_local -> thread_local_dtor; thread_local -> thread_local_key
Diffstat (limited to 'src/libstd/sys/unix/thread_local_key.rs')
-rw-r--r--src/libstd/sys/unix/thread_local_key.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/libstd/sys/unix/thread_local_key.rs b/src/libstd/sys/unix/thread_local_key.rs
new file mode 100644
index 00000000000..2c5b94b1e61
--- /dev/null
+++ b/src/libstd/sys/unix/thread_local_key.rs
@@ -0,0 +1,34 @@
+#![allow(dead_code)] // not used on all platforms
+
+use crate::mem;
+
+pub type Key = libc::pthread_key_t;
+
+#[inline]
+pub unsafe fn create(dtor: Option<unsafe extern "C" fn(*mut u8)>) -> Key {
+    let mut key = 0;
+    assert_eq!(libc::pthread_key_create(&mut key, mem::transmute(dtor)), 0);
+    key
+}
+
+#[inline]
+pub unsafe fn set(key: Key, value: *mut u8) {
+    let r = libc::pthread_setspecific(key, value as *mut _);
+    debug_assert_eq!(r, 0);
+}
+
+#[inline]
+pub unsafe fn get(key: Key) -> *mut u8 {
+    libc::pthread_getspecific(key) as *mut u8
+}
+
+#[inline]
+pub unsafe fn destroy(key: Key) {
+    let r = libc::pthread_key_delete(key);
+    debug_assert_eq!(r, 0);
+}
+
+#[inline]
+pub fn requires_synchronized_create() -> bool {
+    false
+}