Skip to content

Commit 14f31db

Browse files
committed
Auto merge of #2940 - thomcc:unfair_lock_finish, r=JohnTitor
Finish darwin os/lock.h bindings This takes over for #2918, whose author indicated they won't be able to finish for a while: #2918 (comment). Fixes #2917 Closes #2918
2 parents dc3084a + cf1738a commit 14f31db

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

libc-test/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ fn test_apple(target: &str) {
231231
"netinet/ip.h",
232232
"netinet/tcp.h",
233233
"netinet/udp.h",
234+
"os/lock.h",
234235
"poll.h",
235236
"pthread.h",
236237
"pthread_spis.h",
@@ -2442,6 +2443,8 @@ fn test_emscripten(target: &str) {
24422443
// Just pass all these through, no need for a "struct" prefix
24432444
"FILE" | "fd_set" | "Dl_info" | "DIR" => ty.to_string(),
24442445

2446+
"os_unfair_lock" => "struct os_unfair_lock_s".to_string(),
2447+
24452448
t if is_union => format!("union {}", t),
24462449

24472450
t if t.ends_with("_t") => t.to_string(),

libc-test/semver/apple.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ OFDEL
10031003
OFILL
10041004
OLD_TIME
10051005
ONOEOT
1006+
OS_UNFAIR_LOCK_INIT
10061007
OXTABS
10071008
O_ASYNC
10081009
O_DSYNC
@@ -1993,6 +1994,14 @@ open_memstream
19931994
open_wmemstream
19941995
openat
19951996
openpty
1997+
os_unfair_lock
1998+
os_unfair_lock_s
1999+
os_unfair_lock_t
2000+
os_unfair_lock_lock
2001+
os_unfair_lock_trylock
2002+
os_unfair_lock_unlock
2003+
os_unfair_lock_assert_owner
2004+
os_unfair_lock_assert_not_owner
19962005
pause
19972006
policy_t
19982007
popen

src/unix/bsd/apple/mod.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ pub type pthread_introspection_hook_t =
121121
extern "C" fn(event: ::c_uint, thread: ::pthread_t, addr: *mut ::c_void, size: ::size_t);
122122
pub type pthread_jit_write_callback_t = ::Option<extern "C" fn(ctx: *mut ::c_void) -> ::c_int>;
123123

124+
pub type os_unfair_lock = os_unfair_lock_s;
125+
pub type os_unfair_lock_t = *mut os_unfair_lock;
126+
124127
pub type vm_statistics_t = *mut vm_statistics;
125128
pub type vm_statistics_data_t = vm_statistics;
126129
pub type vm_statistics64_t = *mut vm_statistics64;
@@ -1295,6 +1298,10 @@ s_no_extra_traits! {
12951298
pub l2p_contigbytes: ::off_t,
12961299
pub l2p_devoffset: ::off_t,
12971300
}
1301+
1302+
pub struct os_unfair_lock_s {
1303+
_os_unfair_lock_opaque: u32,
1304+
}
12981305
}
12991306

13001307
impl siginfo_t {
@@ -2576,6 +2583,27 @@ cfg_if! {
25762583
l2p_devoffset.hash(state);
25772584
}
25782585
}
2586+
impl PartialEq for os_unfair_lock {
2587+
fn eq(&self, other: &os_unfair_lock) -> bool {
2588+
self._os_unfair_lock_opaque == other._os_unfair_lock_opaque
2589+
}
2590+
}
2591+
2592+
impl Eq for os_unfair_lock {}
2593+
2594+
impl ::fmt::Debug for os_unfair_lock {
2595+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
2596+
f.debug_struct("os_unfair_lock")
2597+
.field("_os_unfair_lock_opaque", &self._os_unfair_lock_opaque)
2598+
.finish()
2599+
}
2600+
}
2601+
2602+
impl ::hash::Hash for os_unfair_lock {
2603+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
2604+
self._os_unfair_lock_opaque.hash(state);
2605+
}
2606+
}
25792607
}
25802608
}
25812609

@@ -3863,6 +3891,10 @@ pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
38633891
__opaque: [0; __PTHREAD_RWLOCK_SIZE__],
38643892
};
38653893

3894+
pub const OS_UNFAIR_LOCK_INIT: os_unfair_lock = os_unfair_lock {
3895+
_os_unfair_lock_opaque: 0,
3896+
};
3897+
38663898
pub const MINSIGSTKSZ: ::size_t = 32768;
38673899
pub const SIGSTKSZ: ::size_t = 131072;
38683900

@@ -5221,6 +5253,12 @@ extern "C" {
52215253
pub fn pthread_jit_write_freeze_callbacks_np();
52225254
pub fn pthread_cpu_number_np(cpu_number_out: *mut ::size_t) -> ::c_int;
52235255

5256+
pub fn os_unfair_lock_lock(lock: os_unfair_lock_t);
5257+
pub fn os_unfair_lock_trylock(lock: os_unfair_lock_t) -> bool;
5258+
pub fn os_unfair_lock_unlock(lock: os_unfair_lock_t);
5259+
pub fn os_unfair_lock_assert_owner(lock: os_unfair_lock_t);
5260+
pub fn os_unfair_lock_assert_not_owner(lock: os_unfair_lock_t);
5261+
52245262
pub fn thread_policy_set(
52255263
thread: thread_t,
52265264
flavor: thread_policy_flavor_t,

0 commit comments

Comments
 (0)