]>
Commit | Line | Data |
---|---|---|
85aaf69f | 1 | // Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT |
1a4d82fc JJ |
2 | // file at the top-level directory of this distribution and at |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
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. | |
10 | ||
62682a34 SL |
11 | #![allow(dead_code)] // sys isn't exported yet |
12 | ||
1a4d82fc JJ |
13 | use prelude::v1::*; |
14 | use libc::c_int; | |
15 | ||
16 | pub type Key = pthread_key_t; | |
17 | ||
18 | #[inline] | |
19 | pub unsafe fn create(dtor: Option<unsafe extern fn(*mut u8)>) -> Key { | |
20 | let mut key = 0; | |
21 | assert_eq!(pthread_key_create(&mut key, dtor), 0); | |
22 | return key; | |
23 | } | |
24 | ||
25 | #[inline] | |
26 | pub unsafe fn set(key: Key, value: *mut u8) { | |
27 | let r = pthread_setspecific(key, value); | |
28 | debug_assert_eq!(r, 0); | |
29 | } | |
30 | ||
31 | #[inline] | |
32 | pub unsafe fn get(key: Key) -> *mut u8 { | |
33 | pthread_getspecific(key) | |
34 | } | |
35 | ||
36 | #[inline] | |
37 | pub unsafe fn destroy(key: Key) { | |
38 | let r = pthread_key_delete(key); | |
39 | debug_assert_eq!(r, 0); | |
40 | } | |
41 | ||
42 | #[cfg(any(target_os = "macos", | |
43 | target_os = "ios"))] | |
44 | type pthread_key_t = ::libc::c_ulong; | |
45 | ||
46 | #[cfg(any(target_os = "freebsd", | |
85aaf69f | 47 | target_os = "dragonfly", |
c34b1796 | 48 | target_os = "bitrig", |
c1a9b12d | 49 | target_os = "netbsd", |
85aaf69f | 50 | target_os = "openbsd"))] |
1a4d82fc JJ |
51 | type pthread_key_t = ::libc::c_int; |
52 | ||
53 | #[cfg(not(any(target_os = "macos", | |
54 | target_os = "ios", | |
55 | target_os = "freebsd", | |
85aaf69f | 56 | target_os = "dragonfly", |
c34b1796 | 57 | target_os = "bitrig", |
c1a9b12d | 58 | target_os = "netbsd", |
85aaf69f | 59 | target_os = "openbsd")))] |
1a4d82fc JJ |
60 | type pthread_key_t = ::libc::c_uint; |
61 | ||
62 | extern { | |
63 | fn pthread_key_create(key: *mut pthread_key_t, | |
64 | dtor: Option<unsafe extern fn(*mut u8)>) -> c_int; | |
65 | fn pthread_key_delete(key: pthread_key_t) -> c_int; | |
66 | fn pthread_getspecific(key: pthread_key_t) -> *mut u8; | |
67 | fn pthread_setspecific(key: pthread_key_t, value: *mut u8) -> c_int; | |
68 | } |