Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish darwin os/lock.h bindings #2940

Merged
merged 1 commit into from Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions libc-test/build.rs
Expand Up @@ -231,6 +231,7 @@ fn test_apple(target: &str) {
"netinet/ip.h",
"netinet/tcp.h",
"netinet/udp.h",
"os/lock.h",
"poll.h",
"pthread.h",
"pthread_spis.h",
Expand Down Expand Up @@ -2442,6 +2443,8 @@ fn test_emscripten(target: &str) {
// Just pass all these through, no need for a "struct" prefix
"FILE" | "fd_set" | "Dl_info" | "DIR" => ty.to_string(),

"os_unfair_lock" => "struct os_unfair_lock_s".to_string(),

t if is_union => format!("union {}", t),

t if t.ends_with("_t") => t.to_string(),
Expand Down
9 changes: 9 additions & 0 deletions libc-test/semver/apple.txt
Expand Up @@ -1003,6 +1003,7 @@ OFDEL
OFILL
OLD_TIME
ONOEOT
OS_UNFAIR_LOCK_INIT
OXTABS
O_ASYNC
O_DSYNC
Expand Down Expand Up @@ -1993,6 +1994,14 @@ open_memstream
open_wmemstream
openat
openpty
os_unfair_lock
os_unfair_lock_s
os_unfair_lock_t
os_unfair_lock_lock
os_unfair_lock_trylock
os_unfair_lock_unlock
os_unfair_lock_assert_owner
os_unfair_lock_assert_not_owner
pause
policy_t
popen
Expand Down
38 changes: 38 additions & 0 deletions src/unix/bsd/apple/mod.rs
Expand Up @@ -121,6 +121,9 @@ pub type pthread_introspection_hook_t =
extern "C" fn(event: ::c_uint, thread: ::pthread_t, addr: *mut ::c_void, size: ::size_t);
pub type pthread_jit_write_callback_t = ::Option<extern "C" fn(ctx: *mut ::c_void) -> ::c_int>;

pub type os_unfair_lock = os_unfair_lock_s;
pub type os_unfair_lock_t = *mut os_unfair_lock;

pub type vm_statistics_t = *mut vm_statistics;
pub type vm_statistics_data_t = vm_statistics;
pub type vm_statistics64_t = *mut vm_statistics64;
Expand Down Expand Up @@ -1295,6 +1298,10 @@ s_no_extra_traits! {
pub l2p_contigbytes: ::off_t,
pub l2p_devoffset: ::off_t,
}

pub struct os_unfair_lock_s {
_os_unfair_lock_opaque: u32,
}
}

impl siginfo_t {
Expand Down Expand Up @@ -2576,6 +2583,27 @@ cfg_if! {
l2p_devoffset.hash(state);
}
}
impl PartialEq for os_unfair_lock {
fn eq(&self, other: &os_unfair_lock) -> bool {
self._os_unfair_lock_opaque == other._os_unfair_lock_opaque
}
}

impl Eq for os_unfair_lock {}

impl ::fmt::Debug for os_unfair_lock {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("os_unfair_lock")
.field("_os_unfair_lock_opaque", &self._os_unfair_lock_opaque)
.finish()
}
}

impl ::hash::Hash for os_unfair_lock {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self._os_unfair_lock_opaque.hash(state);
}
}
}
}

Expand Down Expand Up @@ -3863,6 +3891,10 @@ pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
__opaque: [0; __PTHREAD_RWLOCK_SIZE__],
};

pub const OS_UNFAIR_LOCK_INIT: os_unfair_lock = os_unfair_lock {
_os_unfair_lock_opaque: 0,
};

pub const MINSIGSTKSZ: ::size_t = 32768;
pub const SIGSTKSZ: ::size_t = 131072;

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

pub fn os_unfair_lock_lock(lock: os_unfair_lock_t);
pub fn os_unfair_lock_trylock(lock: os_unfair_lock_t) -> bool;
pub fn os_unfair_lock_unlock(lock: os_unfair_lock_t);
pub fn os_unfair_lock_assert_owner(lock: os_unfair_lock_t);
pub fn os_unfair_lock_assert_not_owner(lock: os_unfair_lock_t);

pub fn thread_policy_set(
thread: thread_t,
flavor: thread_policy_flavor_t,
Expand Down