2015-01-29 08:19:28 +01:00
|
|
|
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
|
2014-11-14 14:20:57 -08:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
2015-05-27 11:18:36 +03:00
|
|
|
#![allow(dead_code)] // sys isn't exported yet
|
|
|
|
|
|
2014-11-14 14:20:57 -08:00
|
|
|
use libc::c_int;
|
|
|
|
|
|
|
|
|
|
pub type Key = pthread_key_t;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub unsafe fn create(dtor: Option<unsafe extern fn(*mut u8)>) -> Key {
|
|
|
|
|
let mut key = 0;
|
|
|
|
|
assert_eq!(pthread_key_create(&mut key, dtor), 0);
|
2015-09-08 00:36:29 +02:00
|
|
|
key
|
2014-11-14 14:20:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub unsafe fn set(key: Key, value: *mut u8) {
|
|
|
|
|
let r = pthread_setspecific(key, value);
|
|
|
|
|
debug_assert_eq!(r, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub unsafe fn get(key: Key) -> *mut u8 {
|
|
|
|
|
pthread_getspecific(key)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub unsafe fn destroy(key: Key) {
|
|
|
|
|
let r = pthread_key_delete(key);
|
|
|
|
|
debug_assert_eq!(r, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-06 10:53:32 +01:00
|
|
|
#[cfg(any(target_os = "macos",
|
|
|
|
|
target_os = "ios"))]
|
2014-11-14 14:20:57 -08:00
|
|
|
type pthread_key_t = ::libc::c_ulong;
|
|
|
|
|
|
2015-01-06 10:53:32 +01:00
|
|
|
#[cfg(any(target_os = "freebsd",
|
2015-01-29 08:19:28 +01:00
|
|
|
target_os = "dragonfly",
|
2015-01-16 23:51:04 -08:00
|
|
|
target_os = "bitrig",
|
2015-06-30 20:37:11 -07:00
|
|
|
target_os = "netbsd",
|
2015-10-24 20:51:34 -05:00
|
|
|
target_os = "openbsd",
|
|
|
|
|
target_os = "nacl"))]
|
2015-01-06 10:53:32 +01:00
|
|
|
type pthread_key_t = ::libc::c_int;
|
|
|
|
|
|
|
|
|
|
#[cfg(not(any(target_os = "macos",
|
|
|
|
|
target_os = "ios",
|
|
|
|
|
target_os = "freebsd",
|
2015-01-29 08:19:28 +01:00
|
|
|
target_os = "dragonfly",
|
2015-01-16 23:51:04 -08:00
|
|
|
target_os = "bitrig",
|
2015-06-30 20:37:11 -07:00
|
|
|
target_os = "netbsd",
|
2015-10-24 20:51:34 -05:00
|
|
|
target_os = "openbsd",
|
|
|
|
|
target_os = "nacl")))]
|
2014-11-14 14:20:57 -08:00
|
|
|
type pthread_key_t = ::libc::c_uint;
|
|
|
|
|
|
|
|
|
|
extern {
|
|
|
|
|
fn pthread_key_create(key: *mut pthread_key_t,
|
|
|
|
|
dtor: Option<unsafe extern fn(*mut u8)>) -> c_int;
|
|
|
|
|
fn pthread_key_delete(key: pthread_key_t) -> c_int;
|
|
|
|
|
fn pthread_getspecific(key: pthread_key_t) -> *mut u8;
|
|
|
|
|
fn pthread_setspecific(key: pthread_key_t, value: *mut u8) -> c_int;
|
|
|
|
|
}
|