1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
14 pub type Key = pthread_key_t;
17 pub unsafe fn create(dtor: Option<unsafe extern fn(*mut u8)>) -> Key {
19 assert_eq!(pthread_key_create(&mut key, dtor), 0);
24 pub unsafe fn set(key: Key, value: *mut u8) {
25 let r = pthread_setspecific(key, value);
26 debug_assert_eq!(r, 0);
30 pub unsafe fn get(key: Key) -> *mut u8 {
31 pthread_getspecific(key)
35 pub unsafe fn destroy(key: Key) {
36 let r = pthread_key_delete(key);
37 debug_assert_eq!(r, 0);
40 #[cfg(target_os = "macos")]
41 type pthread_key_t = ::libc::c_ulong;
43 #[cfg(not(target_os = "macos"))]
44 type pthread_key_t = ::libc::c_uint;
47 fn pthread_key_create(key: *mut pthread_key_t,
48 dtor: Option<unsafe extern fn(*mut u8)>) -> c_int;
49 fn pthread_key_delete(key: pthread_key_t) -> c_int;
50 fn pthread_getspecific(key: pthread_key_t) -> *mut u8;
51 fn pthread_setspecific(key: pthread_key_t, value: *mut u8) -> c_int;