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 target_arch = "powerpc"))]
131 const __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8;
132 #[cfg(target_arch = "aarch64")]
133 const __SIZEOF_PTHREAD_MUTEX_T: uint = 48 - 8;
135 #[cfg(any(target_arch = "x86_64",
138 target_arch = "aarch64",
139 target_arch = "mips",
140 target_arch = "mipsel",
141 target_arch = "powerpc"))]
142 const __SIZEOF_PTHREAD_COND_T: uint = 48 - 8;
144 #[cfg(any(target_arch = "x86_64",
145 target_arch = "aarch64"))]
146 const __SIZEOF_PTHREAD_RWLOCK_T: uint = 56 - 8;
148 #[cfg(any(target_arch = "x86",
150 target_arch = "mips",
151 target_arch = "mipsel",
152 target_arch = "powerpc"))]
153 const __SIZEOF_PTHREAD_RWLOCK_T: uint = 32 - 8;
156 pub struct pthread_mutex_t {
157 __align: libc::c_longlong,
158 size: [u8; __SIZEOF_PTHREAD_MUTEX_T],
161 pub struct pthread_cond_t {
162 __align: libc::c_longlong,
163 size: [u8; __SIZEOF_PTHREAD_COND_T],
166 pub struct pthread_rwlock_t {
167 __align: libc::c_longlong,
168 size: [u8; __SIZEOF_PTHREAD_RWLOCK_T],
171 pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
173 size: [0; __SIZEOF_PTHREAD_MUTEX_T],
175 pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
177 size: [0; __SIZEOF_PTHREAD_COND_T],
179 pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
181 size: [0; __SIZEOF_PTHREAD_RWLOCK_T],
184 #[cfg(target_os = "android")]
189 pub struct pthread_mutex_t { value: libc::c_int }
191 pub struct pthread_cond_t { value: libc::c_int }
193 pub struct pthread_rwlock_t {
194 lock: pthread_mutex_t,
195 cond: pthread_cond_t,
196 numLocks: libc::c_int,
197 writerThreadId: libc::c_int,
198 pendingReaders: libc::c_int,
199 pendingWriters: libc::c_int,
200 reserved: [*mut libc::c_void; 4],
203 pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
206 pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
209 pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
210 lock: PTHREAD_MUTEX_INITIALIZER,
211 cond: PTHREAD_COND_INITIALIZER,
216 reserved: [0 as *mut _; 4],