2015-11-02 16:23:22 -08:00
|
|
|
#![allow(dead_code)] // not used on all platforms
|
2015-05-27 11:18:36 +03:00
|
|
|
|
2019-02-11 04:23:21 +09:00
|
|
|
use crate::mem;
|
2014-11-14 14:20:57 -08:00
|
|
|
|
2015-11-02 16:23:22 -08:00
|
|
|
pub type Key = libc::pthread_key_t;
|
2014-11-14 14:20:57 -08:00
|
|
|
|
|
|
|
|
#[inline]
|
2019-11-27 10:28:39 -08:00
|
|
|
pub unsafe fn create(dtor: Option<unsafe extern "C" fn(*mut u8)>) -> Key {
|
2014-11-14 14:20:57 -08:00
|
|
|
let mut key = 0;
|
2015-11-02 16:23:22 -08:00
|
|
|
assert_eq!(libc::pthread_key_create(&mut key, mem::transmute(dtor)), 0);
|
2015-09-08 00:36:29 +02:00
|
|
|
key
|
2014-11-14 14:20:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub unsafe fn set(key: Key, value: *mut u8) {
|
2015-11-02 16:23:22 -08:00
|
|
|
let r = libc::pthread_setspecific(key, value as *mut _);
|
2014-11-14 14:20:57 -08:00
|
|
|
debug_assert_eq!(r, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub unsafe fn get(key: Key) -> *mut u8 {
|
2015-11-02 16:23:22 -08:00
|
|
|
libc::pthread_getspecific(key) as *mut u8
|
2014-11-14 14:20:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub unsafe fn destroy(key: Key) {
|
2015-11-02 16:23:22 -08:00
|
|
|
let r = libc::pthread_key_delete(key);
|
2014-11-14 14:20:57 -08:00
|
|
|
debug_assert_eq!(r, 0);
|
|
|
|
|
}
|
2017-04-24 11:34:16 -07:00
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn requires_synchronized_create() -> bool {
|
|
|
|
|
false
|
|
|
|
|
}
|