]>
git.proxmox.com Git - rustc.git/blob - src/libstd/sys/unix/thread_local.rs
3afe84b25804c3c5d11836da16d80052984b7ec0
1 // Copyright 2014-2015 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.
11 #![allow(dead_code)] // sys isn't exported yet
16 pub type Key
= pthread_key_t
;
19 pub unsafe fn create(dtor
: Option
<unsafe extern fn(*mut u8)>) -> Key
{
21 assert_eq
!(pthread_key_create(&mut key
, dtor
), 0);
26 pub unsafe fn set(key
: Key
, value
: *mut u8) {
27 let r
= pthread_setspecific(key
, value
);
28 debug_assert_eq
!(r
, 0);
32 pub unsafe fn get(key
: Key
) -> *mut u8 {
33 pthread_getspecific(key
)
37 pub unsafe fn destroy(key
: Key
) {
38 let r
= pthread_key_delete(key
);
39 debug_assert_eq
!(r
, 0);
42 #[cfg(any(target_os = "macos",
44 type pthread_key_t
= ::libc
::c_ulong
;
46 #[cfg(any(target_os = "freebsd",
47 target_os
= "dragonfly",
49 target_os
= "openbsd"))]
50 type pthread_key_t
= ::libc
::c_int
;
52 #[cfg(not(any(target_os = "macos",
54 target_os
= "freebsd",
55 target_os
= "dragonfly",
57 target_os
= "openbsd")))]
58 type pthread_key_t
= ::libc
::c_uint
;
61 fn pthread_key_create(key
: *mut pthread_key_t
,
62 dtor
: Option
<unsafe extern fn(*mut u8)>) -> c_int
;
63 fn pthread_key_delete(key
: pthread_key_t
) -> c_int
;
64 fn pthread_getspecific(key
: pthread_key_t
) -> *mut u8;
65 fn pthread_setspecific(key
: pthread_key_t
, value
: *mut u8) -> c_int
;