Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/new/bionic_libc/pthread.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
//! Header: `unistd.h`
pub use crate::new::common::linux_like::pthread::pthread_setname_np;
pub use crate::new::common::linux_like::pthread::{
pthread_getattr_np,
pthread_setname_np,
};
pub use crate::new::common::posix::pthread::{
pthread_atfork,
pthread_attr_getguardsize,
pthread_attr_getinheritsched,
pthread_attr_getstack,
pthread_attr_setguardsize,
pthread_attr_setinheritsched,
pthread_attr_setstack,
pthread_barrier_destroy,
pthread_barrier_init,
pthread_barrier_wait,
pthread_barrierattr_destroy,
pthread_barrierattr_getpshared,
pthread_barrierattr_init,
pthread_barrierattr_setpshared,
pthread_condattr_getclock,
pthread_condattr_getpshared,
pthread_condattr_setclock,
pthread_condattr_setpshared,
pthread_create,
pthread_getcpuclockid,
pthread_getschedparam,
pthread_kill,
pthread_mutex_timedlock,
pthread_mutexattr_getpshared,
pthread_mutexattr_setpshared,
pthread_rwlockattr_getpshared,
pthread_rwlockattr_setpshared,
pthread_setschedparam,
pthread_sigmask,
pthread_spin_destroy,
Expand Down
7 changes: 6 additions & 1 deletion src/new/common/linux_like/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
//! API that primarily comes from Linux but is also used other platforms (e.g. Android).

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "l4re",
target_os = "linux"
))]
pub(crate) mod pthread;
2 changes: 2 additions & 0 deletions src/new/common/linux_like/pthread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ extern "C" {
cpuset: *mut crate::cpu_set_t,
) -> c_int;

pub fn pthread_getattr_np(native: crate::pthread_t, attr: *mut crate::pthread_attr_t) -> c_int;

#[cfg(target_os = "linux")]
pub fn pthread_getname_np(thread: crate::pthread_t, name: *mut c_char, len: size_t) -> c_int;

Expand Down
7 changes: 6 additions & 1 deletion src/new/common/posix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
//! These can be found at: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/contents.html>.

// FIXME(pthread): eventually all platforms should use this module
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))]
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "l4re",
target_os = "linux"
))]
pub(crate) mod pthread;
pub(crate) mod unistd;
153 changes: 124 additions & 29 deletions src/new/common/posix/pthread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,86 @@ extern "C" {
child: Option<unsafe extern "C" fn()>,
) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_attr_getguardsize(
attr: *const crate::pthread_attr_t,
guardsize: *mut size_t,
) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_attr_getinheritsched(
attr: *const crate::pthread_attr_t,
inheritsched: *mut c_int,
) -> c_int;

#[cfg(target_os = "linux")]
#[cfg(any(target_os = "l4re", target_os = "linux"))]
pub fn pthread_attr_getschedparam(
attr: *const crate::pthread_attr_t,
param: *mut crate::sched_param,
) -> c_int;

#[cfg(target_os = "linux")]
#[cfg(any(target_os = "l4re", target_os = "linux"))]
pub fn pthread_attr_getschedpolicy(
attr: *const crate::pthread_attr_t,
policy: *mut c_int,
) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "linux",
target_os = "l4re"
))]
pub fn pthread_attr_getstack(
attr: *const crate::pthread_attr_t,
stackaddr: *mut *mut c_void,
stacksize: *mut size_t,
) -> c_int;

#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_attr_setguardsize(attr: *mut crate::pthread_attr_t, guardsize: size_t) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_attr_setinheritsched(
attr: *mut crate::pthread_attr_t,
inheritsched: c_int,
) -> c_int;

#[cfg(target_os = "linux")]
#[cfg(any(target_os = "l4re", target_os = "linux"))]
pub fn pthread_attr_setschedparam(
attr: *mut crate::pthread_attr_t,
param: *const crate::sched_param,
) -> c_int;

#[cfg(target_os = "linux")]
#[cfg(any(target_os = "l4re", target_os = "linux"))]
pub fn pthread_attr_setschedpolicy(attr: *mut crate::pthread_attr_t, policy: c_int) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "linux",
target_os = "l4re"
))]
pub fn pthread_attr_setstack(
attr: *mut crate::pthread_attr_t,
stackaddr: *mut c_void,
stacksize: size_t,
) -> c_int;

#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_barrier_destroy(barrier: *mut crate::pthread_barrier_t) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_barrier_init(
barrier: *mut crate::pthread_barrier_t,
attr: *const crate::pthread_barrierattr_t,
count: c_uint,
) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_barrier_wait(barrier: *mut crate::pthread_barrier_t) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_barrierattr_destroy(attr: *mut crate::pthread_barrierattr_t) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
Expand All @@ -76,25 +100,63 @@ extern "C" {
shared: *mut c_int,
) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_barrierattr_init(attr: *mut crate::pthread_barrierattr_t) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_barrierattr_setpshared(
attr: *mut crate::pthread_barrierattr_t,
shared: c_int,
) -> c_int;

#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
#[cfg(any(target_os = "l4re", all(target_os = "linux", not(target_env = "ohos"))))]
pub fn pthread_cancel(thread: crate::pthread_t) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "linux",
target_os = "l4re"
))]
pub fn pthread_condattr_getclock(
attr: *const crate::pthread_condattr_t,
clock_id: *mut crate::clockid_t,
) -> c_int;

#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_condattr_getpshared(
attr: *const crate::pthread_condattr_t,
pshared: *mut c_int,
) -> c_int;

#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))]
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "linux",
target_os = "l4re"
))]
pub fn pthread_condattr_setclock(
attr: *mut crate::pthread_condattr_t,
clock_id: crate::clockid_t,
) -> c_int;

#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "linux",
target_os = "l4re"
))]
pub fn pthread_condattr_setpshared(
attr: *mut crate::pthread_condattr_t,
pshared: c_int,
) -> c_int;

#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "l4re",
target_os = "linux"
))]
pub fn pthread_create(
native: *mut crate::pthread_t,
attr: *const crate::pthread_attr_t,
Expand All @@ -105,7 +167,7 @@ extern "C" {
#[cfg(any(target_os = "android", target_os = "linux"))]
pub fn pthread_getcpuclockid(thread: crate::pthread_t, clk_id: *mut crate::clockid_t) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_getschedparam(
native: crate::pthread_t,
policy: *mut c_int,
Expand All @@ -114,13 +176,13 @@ extern "C" {

// FIXME(reorg): In recent POSIX versions, this is a signal.h function and not required
// in pthread.
#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int;

#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
pub fn pthread_mutex_consistent(mutex: *mut crate::pthread_mutex_t) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
#[cfg_attr(gnu_time_bits64, link_name = "__pthread_mutex_timedlock64")]
pub fn pthread_mutex_timedlock(
lock: *mut crate::pthread_mutex_t,
Expand All @@ -133,7 +195,7 @@ extern "C" {
protocol: *mut c_int,
) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_mutexattr_getpshared(
attr: *const crate::pthread_mutexattr_t,
pshared: *mut c_int,
Expand All @@ -151,16 +213,49 @@ extern "C" {
protocol: c_int,
) -> c_int;

#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "linux",
target_os = "l4re"
))]
pub fn pthread_mutexattr_setpshared(
attr: *mut crate::pthread_mutexattr_t,
pshared: c_int,
) -> c_int;

#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
pub fn pthread_mutexattr_setrobust(
attr: *mut crate::pthread_mutexattr_t,
robustness: c_int,
) -> c_int;

#[cfg(target_os = "linux")]
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "linux",
target_os = "l4re"
))]
pub fn pthread_rwlockattr_getpshared(
attr: *const crate::pthread_rwlockattr_t,
val: *mut c_int,
) -> c_int;

#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "linux",
target_os = "l4re"
))]
pub fn pthread_rwlockattr_setpshared(
attr: *mut crate::pthread_rwlockattr_t,
val: c_int,
) -> c_int;

#[cfg(any(target_os = "l4re", target_os = "linux"))]
pub fn pthread_once(control: *mut crate::pthread_once_t, routine: extern "C" fn()) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_setschedparam(
native: crate::pthread_t,
policy: c_int,
Expand All @@ -172,25 +267,25 @@ extern "C" {

// FIXME(reorg): In recent POSIX versions, this is a signal.h function and not required
// in pthread.
#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_sigmask(
how: c_int,
set: *const crate::sigset_t,
oldset: *mut crate::sigset_t,
) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_spin_destroy(lock: *mut crate::pthread_spinlock_t) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_spin_init(lock: *mut crate::pthread_spinlock_t, pshared: c_int) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_spin_lock(lock: *mut crate::pthread_spinlock_t) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_spin_trylock(lock: *mut crate::pthread_spinlock_t) -> c_int;

#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_spin_unlock(lock: *mut crate::pthread_spinlock_t) -> c_int;
}
13 changes: 12 additions & 1 deletion src/new/emscripten/pthread.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
//! Header: `pthread.h`

pub use crate::new::common::posix::pthread::pthread_create;
pub use crate::new::common::linux_like::pthread::pthread_getattr_np;
pub use crate::new::common::posix::pthread::{
pthread_attr_getstack,
pthread_attr_setstack,
pthread_condattr_getclock,
pthread_condattr_setclock,
pthread_condattr_setpshared,
pthread_create,
pthread_mutexattr_setpshared,
pthread_rwlockattr_getpshared,
pthread_rwlockattr_setpshared,
};
Loading