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.
15 pub use self::os::{PTHREAD_MUTEX_INITIALIZER, pthread_mutex_t};
16 pub use self::os::{PTHREAD_COND_INITIALIZER, pthread_cond_t};
17 pub use self::os::{PTHREAD_RWLOCK_INITIALIZER, pthread_rwlock_t};
21 pub fn pthread_mutex_destroy(lock: *mut pthread_mutex_t) -> libc::c_int;
22 pub fn pthread_mutex_lock(lock: *mut pthread_mutex_t) -> libc::c_int;
23 pub fn pthread_mutex_trylock(lock: *mut pthread_mutex_t) -> libc::c_int;
24 pub fn pthread_mutex_unlock(lock: *mut pthread_mutex_t) -> libc::c_int;
27 pub fn pthread_cond_wait(cond: *mut pthread_cond_t,
28 lock: *mut pthread_mutex_t) -> libc::c_int;
29 pub fn pthread_cond_timedwait(cond: *mut pthread_cond_t,
30 lock: *mut pthread_mutex_t,
31 abstime: *const libc::timespec) -> libc::c_int;
32 pub fn pthread_cond_signal(cond: *mut pthread_cond_t) -> libc::c_int;
33 pub fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> libc::c_int;
34 pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> libc::c_int;
35 pub fn gettimeofday(tp: *mut libc::timeval,
36 tz: *mut libc::c_void) -> libc::c_int;
39 pub fn pthread_rwlock_destroy(lock: *mut pthread_rwlock_t) -> libc::c_int;
40 pub fn pthread_rwlock_rdlock(lock: *mut pthread_rwlock_t) -> libc::c_int;
41 pub fn pthread_rwlock_tryrdlock(lock: *mut pthread_rwlock_t) -> libc::c_int;
42 pub fn pthread_rwlock_wrlock(lock: *mut pthread_rwlock_t) -> libc::c_int;
43 pub fn pthread_rwlock_trywrlock(lock: *mut pthread_rwlock_t) -> libc::c_int;
44 pub fn pthread_rwlock_unlock(lock: *mut pthread_rwlock_t) -> libc::c_int;
47 #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
51 pub type pthread_mutex_t = *mut libc::c_void;
52 pub type pthread_cond_t = *mut libc::c_void;
53 pub type pthread_rwlock_t = *mut libc::c_void;
55 pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = 0 as *mut _;
56 pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = 0 as *mut _;
57 pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = 0 as *mut _;
60 #[cfg(any(target_os = "macos", target_os = "ios"))]
64 #[cfg(any(target_arch = "x86_64",
65 target_arch = "aarch64"))]
66 const __PTHREAD_MUTEX_SIZE__: uint = 56;
67 #[cfg(any(target_arch = "x86",
68 target_arch = "arm"))]
69 const __PTHREAD_MUTEX_SIZE__: uint = 40;
71 #[cfg(any(target_arch = "x86_64",
72 target_arch = "aarch64"))]
73 const __PTHREAD_COND_SIZE__: uint = 40;
74 #[cfg(any(target_arch = "x86",
75 target_arch = "arm"))]
76 const __PTHREAD_COND_SIZE__: uint = 24;
78 #[cfg(any(target_arch = "x86_64",
79 target_arch = "aarch64"))]
80 const __PTHREAD_RWLOCK_SIZE__: uint = 192;
81 #[cfg(any(target_arch = "x86",
82 target_arch = "arm"))]
83 const __PTHREAD_RWLOCK_SIZE__: uint = 124;
85 const _PTHREAD_MUTEX_SIG_INIT: libc::c_long = 0x32AAABA7;
86 const _PTHREAD_COND_SIG_INIT: libc::c_long = 0x3CB0B1BB;
87 const _PTHREAD_RWLOCK_SIG_INIT: libc::c_long = 0x2DA8B3B4;
90 pub struct pthread_mutex_t {
92 __opaque: [u8; __PTHREAD_MUTEX_SIZE__],
95 pub struct pthread_cond_t {
97 __opaque: [u8; __PTHREAD_COND_SIZE__],
100 pub struct pthread_rwlock_t {
102 __opaque: [u8; __PTHREAD_RWLOCK_SIZE__],
105 pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
106 __sig: _PTHREAD_MUTEX_SIG_INIT,
107 __opaque: [0; __PTHREAD_MUTEX_SIZE__],
109 pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
110 __sig: _PTHREAD_COND_SIG_INIT,
111 __opaque: [0; __PTHREAD_COND_SIZE__],
113 pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
114 __sig: _PTHREAD_RWLOCK_SIG_INIT,
115 __opaque: [0; __PTHREAD_RWLOCK_SIZE__],
119 #[cfg(target_os = "linux")]
123 // minus 8 because we have an 'align' field
124 #[cfg(target_arch = "x86_64")]
125 const __SIZEOF_PTHREAD_MUTEX_T: uint = 40 - 8;
126 #[cfg(any(target_arch = "x86",
128 target_arch = "mips",
129 target_arch = "mipsel"))]
130 const __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8;
131 #[cfg(target_arch = "aarch64")]
132 const __SIZEOF_PTHREAD_MUTEX_T: uint = 48 - 8;
134 #[cfg(any(target_arch = "x86_64",
137 target_arch = "aarch64",
138 target_arch = "mips",
139 target_arch = "mipsel"))]
140 const __SIZEOF_PTHREAD_COND_T: uint = 48 - 8;
142 #[cfg(any(target_arch = "x86_64",
143 target_arch = "aarch64"))]
144 const __SIZEOF_PTHREAD_RWLOCK_T: uint = 56 - 8;
146 #[cfg(any(target_arch = "x86",
148 target_arch = "mips",
149 target_arch = "mipsel"))]
150 const __SIZEOF_PTHREAD_RWLOCK_T: uint = 32 - 8;
153 pub struct pthread_mutex_t {
154 __align: libc::c_longlong,
155 size: [u8; __SIZEOF_PTHREAD_MUTEX_T],
158 pub struct pthread_cond_t {
159 __align: libc::c_longlong,
160 size: [u8; __SIZEOF_PTHREAD_COND_T],
163 pub struct pthread_rwlock_t {
164 __align: libc::c_longlong,
165 size: [u8; __SIZEOF_PTHREAD_RWLOCK_T],
168 pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
170 size: [0; __SIZEOF_PTHREAD_MUTEX_T],
172 pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
174 size: [0; __SIZEOF_PTHREAD_COND_T],
176 pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
178 size: [0; __SIZEOF_PTHREAD_RWLOCK_T],
181 #[cfg(target_os = "android")]
186 pub struct pthread_mutex_t { value: libc::c_int }
188 pub struct pthread_cond_t { value: libc::c_int }
190 pub struct pthread_rwlock_t {
191 lock: pthread_mutex_t,
192 cond: pthread_cond_t,
193 numLocks: libc::c_int,
194 writerThreadId: libc::c_int,
195 pendingReaders: libc::c_int,
196 pendingWriters: libc::c_int,
197 reserved: [*mut libc::c_void; 4],
200 pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
203 pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
206 pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
207 lock: PTHREAD_MUTEX_INITIALIZER,
208 cond: PTHREAD_COND_INITIALIZER,
213 reserved: [0 as *mut _; 4],