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(any(target_os = "macos",
42 type pthread_key_t = ::libc::c_ulong;
44 #[cfg(any(target_os = "freebsd",
45 target_os = "dragonfly"))]
46 type pthread_key_t = ::libc::c_int;
48 #[cfg(not(any(target_os = "macos",
50 target_os = "freebsd",
51 target_os = "dragonfly")))]
52 type pthread_key_t = ::libc::c_uint;
55 fn pthread_key_create(key: *mut pthread_key_t,
56 dtor: Option<unsafe extern fn(*mut u8)>) -> c_int;
57 fn pthread_key_delete(key: pthread_key_t) -> c_int;
58 fn pthread_getspecific(key: pthread_key_t) -> *mut u8;
59 fn pthread_setspecific(key: pthread_key_t, value: *mut u8) -> c_int;