• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![allow(dead_code)] // not used on all platforms
2 
3 use crate::mem;
4 
5 pub type Key = libc::pthread_key_t;
6 
7 #[inline]
create(dtor: Option<unsafe extern "C" fn(*mut u8)>) -> Key8 pub unsafe fn create(dtor: Option<unsafe extern "C" fn(*mut u8)>) -> Key {
9     let mut key = 0;
10     assert_eq!(libc::pthread_key_create(&mut key, mem::transmute(dtor)), 0);
11     key
12 }
13 
14 #[inline]
set(key: Key, value: *mut u8)15 pub 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]
get(key: Key) -> *mut u821 pub unsafe fn get(key: Key) -> *mut u8 {
22     libc::pthread_getspecific(key) as *mut u8
23 }
24 
25 #[inline]
destroy(key: Key)26 pub unsafe fn destroy(key: Key) {
27     let r = libc::pthread_key_delete(key);
28     debug_assert_eq!(r, 0);
29 }
30