Skip to content

Commit a3cbf5f

Browse files
nathaniel-bennetttgross35
authored andcommitted
Apple: Add additional pthread APIs
(backport <#3846>) (cherry picked from commit 7b0b1a8)
1 parent f0422d5 commit a3cbf5f

File tree

4 files changed

+143
-0
lines changed

4 files changed

+143
-0
lines changed

libc-test/semver/apple.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,16 +1116,29 @@ PROC_CSM_TECS
11161116
PROC_PIDTASKALLINFO
11171117
PROC_PIDTASKINFO
11181118
PROC_PIDTHREADINFO
1119+
PTHREAD_CANCEL_ASYNCHRONOUS
1120+
PTHREAD_CANCEL_DEFERRED
1121+
PTHREAD_CANCEL_DISABLE
1122+
PTHREAD_CANCEL_ENABLE
1123+
PTHREAD_CANCELED
11191124
PTHREAD_CREATE_DETACHED
11201125
PTHREAD_CREATE_JOINABLE
1126+
PTHREAD_EXPLICIT_SCHED
1127+
PTHREAD_INHERIT_SCHED
11211128
PTHREAD_INTROSPECTION_THREAD_CREATE
11221129
PTHREAD_INTROSPECTION_THREAD_DESTROY
11231130
PTHREAD_INTROSPECTION_THREAD_START
11241131
PTHREAD_INTROSPECTION_THREAD_TERMINATE
11251132
PTHREAD_MUTEX_DEFAULT
11261133
PTHREAD_MUTEX_ERRORCHECK
1134+
PTHREAD_ONCE_INIT
1135+
PTHREAD_PRIO_INHERIT
1136+
PTHREAD_PRIO_NONE
1137+
PTHREAD_PRIO_PROTECT
11271138
PTHREAD_PROCESS_PRIVATE
11281139
PTHREAD_PROCESS_SHARED
1140+
PTHREAD_SCOPE_PROCESS
1141+
PTHREAD_SCOPE_SYSTEM
11291142
PTHREAD_STACK_MIN
11301143
PT_ATTACH
11311144
PT_ATTACHEXC
@@ -1832,6 +1845,7 @@ _WSTOPPED
18321845
__PTHREAD_CONDATTR_SIZE__
18331846
__PTHREAD_COND_SIZE__
18341847
__PTHREAD_MUTEX_SIZE__
1848+
__PTHREAD_ONCE_SIZE__
18351849
__PTHREAD_RWLOCKATTR_SIZE__
18361850
__PTHREAD_RWLOCK_SIZE__
18371851
__darwin_mcontext64
@@ -2142,8 +2156,18 @@ pseudo_AF_KEY
21422156
pseudo_AF_PIP
21432157
pseudo_AF_RTIP
21442158
pseudo_AF_XTP
2159+
pthread_atfork
2160+
pthread_attr_getdetachstate
2161+
pthread_attr_getinheritsched
21452162
pthread_attr_getschedparam
2163+
pthread_attr_getschedpolicy
2164+
pthread_attr_getscope
2165+
pthread_attr_getstackaddr
2166+
pthread_attr_setinheritsched
21462167
pthread_attr_setschedparam
2168+
pthread_attr_setschedpolicy
2169+
pthread_attr_setscope
2170+
pthread_attr_setstackaddr
21472171
pthread_cancel
21482172
pthread_condattr_getpshared
21492173
pthread_condattr_setpshared
@@ -2167,6 +2191,8 @@ pthread_kill
21672191
pthread_main_np
21682192
pthread_mutexattr_getpshared
21692193
pthread_mutexattr_setpshared
2194+
pthread_once
2195+
pthread_once_t
21702196
pthread_rwlockattr_getpshared
21712197
pthread_rwlockattr_setpshared
21722198
pthread_setname_np

src/unix/bsd/apple/b32/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ s_no_extra_traits! {
5454
__sig: c_long,
5555
__opaque: [::c_char; 36]
5656
}
57+
58+
pub struct pthread_once_t {
59+
__sig: c_long,
60+
__opaque: [::c_char; ::__PTHREAD_ONCE_SIZE__],
61+
}
5762
}
5863

5964
cfg_if! {
@@ -82,6 +87,29 @@ cfg_if! {
8287
self.__opaque.hash(state);
8388
}
8489
}
90+
impl PartialEq for pthread_once_t {
91+
fn eq(&self, other: &pthread_once_t) -> bool {
92+
self.__sig == other.__sig
93+
&& self.__opaque
94+
.iter()
95+
.zip(other.__opaque.iter())
96+
.all(|(a,b)| a == b)
97+
}
98+
}
99+
impl Eq for pthread_once_t {}
100+
impl ::fmt::Debug for pthread_once_t {
101+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
102+
f.debug_struct("pthread_once_t")
103+
.field("__sig", &self.__sig)
104+
.finish()
105+
}
106+
}
107+
impl ::hash::Hash for pthread_once_t {
108+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
109+
self.__sig.hash(state);
110+
self.__opaque.hash(state);
111+
}
112+
}
85113
}
86114
}
87115

@@ -92,6 +120,7 @@ pub const NET_RT_MAXID: ::c_int = 10;
92120
pub const __PTHREAD_MUTEX_SIZE__: usize = 40;
93121
pub const __PTHREAD_COND_SIZE__: usize = 24;
94122
pub const __PTHREAD_CONDATTR_SIZE__: usize = 4;
123+
pub const __PTHREAD_ONCE_SIZE__: usize = 4;
95124
pub const __PTHREAD_RWLOCK_SIZE__: usize = 124;
96125
pub const __PTHREAD_RWLOCKATTR_SIZE__: usize = 12;
97126

@@ -103,6 +132,12 @@ pub const BIOCSRTIMEOUT: ::c_ulong = 0x8008426d;
103132
pub const BIOCGRTIMEOUT: ::c_ulong = 0x4008426e;
104133
pub const BIOCSETFNR: ::c_ulong = 0x8008427e;
105134

135+
const _PTHREAD_ONCE_SIG_INIT: c_long = 0x30B1BCBA;
136+
pub const PTHREAD_ONCE_INIT: ::pthread_once_t = ::pthread_once_t {
137+
__sig: _PTHREAD_ONCE_SIG_INIT,
138+
__opaque: [0; 4],
139+
};
140+
106141
extern "C" {
107142
pub fn exchangedata(
108143
path1: *const ::c_char,

src/unix/bsd/apple/b64/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ s_no_extra_traits! {
5454
__sig: c_long,
5555
__opaque: [::c_char; 56]
5656
}
57+
58+
pub struct pthread_once_t {
59+
__sig: c_long,
60+
__opaque: [::c_char; __PTHREAD_ONCE_SIZE__],
61+
}
5762
}
5863

5964
cfg_if! {
@@ -82,6 +87,29 @@ cfg_if! {
8287
self.__opaque.hash(state);
8388
}
8489
}
90+
impl PartialEq for pthread_once_t {
91+
fn eq(&self, other: &pthread_once_t) -> bool {
92+
self.__sig == other.__sig
93+
&& self.__opaque
94+
.iter()
95+
.zip(other.__opaque.iter())
96+
.all(|(a,b)| a == b)
97+
}
98+
}
99+
impl Eq for pthread_once_t {}
100+
impl ::fmt::Debug for pthread_once_t {
101+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
102+
f.debug_struct("pthread_once_t")
103+
.field("__sig", &self.__sig)
104+
.finish()
105+
}
106+
}
107+
impl ::hash::Hash for pthread_once_t {
108+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
109+
self.__sig.hash(state);
110+
self.__opaque.hash(state);
111+
}
112+
}
85113
}
86114
}
87115

@@ -92,6 +120,7 @@ pub const NET_RT_MAXID: ::c_int = 11;
92120
pub const __PTHREAD_MUTEX_SIZE__: usize = 56;
93121
pub const __PTHREAD_COND_SIZE__: usize = 40;
94122
pub const __PTHREAD_CONDATTR_SIZE__: usize = 8;
123+
pub const __PTHREAD_ONCE_SIZE__: usize = 8;
95124
pub const __PTHREAD_RWLOCK_SIZE__: usize = 192;
96125
pub const __PTHREAD_RWLOCKATTR_SIZE__: usize = 16;
97126

@@ -103,6 +132,12 @@ pub const BIOCSRTIMEOUT: ::c_ulong = 0x8010426d;
103132
pub const BIOCGRTIMEOUT: ::c_ulong = 0x4010426e;
104133
pub const BIOCSETFNR: ::c_ulong = 0x8010427e;
105134

135+
const _PTHREAD_ONCE_SIG_INIT: c_long = 0x30B1BCBA;
136+
pub const PTHREAD_ONCE_INIT: ::pthread_once_t = ::pthread_once_t {
137+
__sig: _PTHREAD_ONCE_SIG_INIT,
138+
__opaque: [0; 8],
139+
};
140+
106141
extern "C" {
107142
pub fn exchangedata(
108143
path1: *const ::c_char,

src/unix/bsd/apple/mod.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3787,6 +3787,19 @@ pub const PTHREAD_PROCESS_PRIVATE: ::c_int = 2;
37873787
pub const PTHREAD_PROCESS_SHARED: ::c_int = 1;
37883788
pub const PTHREAD_CREATE_JOINABLE: ::c_int = 1;
37893789
pub const PTHREAD_CREATE_DETACHED: ::c_int = 2;
3790+
pub const PTHREAD_INHERIT_SCHED: ::c_int = 1;
3791+
pub const PTHREAD_EXPLICIT_SCHED: ::c_int = 2;
3792+
pub const PTHREAD_CANCEL_ENABLE: ::c_int = 0x01;
3793+
pub const PTHREAD_CANCEL_DISABLE: ::c_int = 0x00;
3794+
pub const PTHREAD_CANCEL_DEFERRED: ::c_int = 0x02;
3795+
pub const PTHREAD_CANCEL_ASYNCHRONOUS: ::c_int = 0x00;
3796+
pub const PTHREAD_CANCELED: *mut ::c_void = 1 as *mut ::c_void;
3797+
pub const PTHREAD_SCOPE_SYSTEM: ::c_int = 1;
3798+
pub const PTHREAD_SCOPE_PROCESS: ::c_int = 2;
3799+
pub const PTHREAD_PRIO_NONE: ::c_int = 0;
3800+
pub const PTHREAD_PRIO_INHERIT: ::c_int = 1;
3801+
pub const PTHREAD_PRIO_PROTECT: ::c_int = 2;
3802+
37903803
#[cfg(target_arch = "aarch64")]
37913804
pub const PTHREAD_STACK_MIN: ::size_t = 16384;
37923805
#[cfg(not(target_arch = "aarch64"))]
@@ -5757,6 +5770,40 @@ extern "C" {
57575770
pub fn mach_timebase_info(info: *mut ::mach_timebase_info) -> ::c_int;
57585771
pub fn mach_host_self() -> mach_port_t;
57595772
pub fn mach_thread_self() -> mach_port_t;
5773+
pub fn pthread_once(
5774+
once_control: *mut ::pthread_once_t,
5775+
init_routine: ::Option<unsafe extern "C" fn()>,
5776+
) -> ::c_int;
5777+
pub fn pthread_attr_getinheritsched(
5778+
attr: *const ::pthread_attr_t,
5779+
inheritsched: *mut ::c_int,
5780+
) -> ::c_int;
5781+
pub fn pthread_attr_getschedpolicy(
5782+
attr: *const ::pthread_attr_t,
5783+
policy: *mut ::c_int,
5784+
) -> ::c_int;
5785+
pub fn pthread_attr_getscope(
5786+
attr: *const ::pthread_attr_t,
5787+
contentionscope: *mut ::c_int,
5788+
) -> ::c_int;
5789+
pub fn pthread_attr_getstackaddr(
5790+
attr: *const ::pthread_attr_t,
5791+
stackaddr: *mut *mut ::c_void,
5792+
) -> ::c_int;
5793+
pub fn pthread_attr_getdetachstate(
5794+
attr: *const ::pthread_attr_t,
5795+
detachstate: *mut ::c_int,
5796+
) -> ::c_int;
5797+
pub fn pthread_attr_setinheritsched(
5798+
attr: *mut ::pthread_attr_t,
5799+
inheritsched: ::c_int,
5800+
) -> ::c_int;
5801+
pub fn pthread_attr_setschedpolicy(attr: *mut ::pthread_attr_t, policy: ::c_int) -> ::c_int;
5802+
pub fn pthread_attr_setscope(attr: *mut ::pthread_attr_t, contentionscope: ::c_int) -> ::c_int;
5803+
pub fn pthread_attr_setstackaddr(
5804+
attr: *mut ::pthread_attr_t,
5805+
stackaddr: *mut ::c_void,
5806+
) -> ::c_int;
57605807
pub fn pthread_setname_np(name: *const ::c_char) -> ::c_int;
57615808
pub fn pthread_getname_np(thread: ::pthread_t, name: *mut ::c_char, len: ::size_t) -> ::c_int;
57625809
pub fn pthread_mach_thread_np(thread: ::pthread_t) -> ::mach_port_t;

0 commit comments

Comments
 (0)