1#![allow(dead_code)] // not used on all platforms
2
3use crate::mem;
4
5pub type Key = libc::pthread_key_t;
6
7#[inline]
8pub unsafe fn create(dtor: Option<unsafe extern "C" fn(*mut u8)>) -> Key {
9 let mut key: i32 = 0;
10 assert_eq!(libc::pthread_key_create(&mut key, mem::transmute(dtor)), 0);
11 key
12}
13
14#[inline]
15pub unsafe fn set(key: Key, value: *mut u8) {
16 let r = libc::pthread_setspecific(key, value as *mut _);
17 debug_assert_eq!(r, 0);
18}
19
20#[inline]
21pub unsafe fn get(key: Key) -> *mut u8 {
22 libc::pthread_getspecific(key) as *mut u8
23}
24
25#[inline]
26pub unsafe fn destroy(key: Key) {
27 let r = libc::pthread_key_delete(key);
28 debug_assert_eq!(r, 0);
29}
30