Document all pthread functions
This commit is contained in:
@@ -34,12 +34,14 @@ impl Default for RlctAttr {
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_destroy.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_destroy(attr: *mut pthread_attr_t) -> c_int {
|
||||
unsafe { ptr::drop_in_place(attr) };
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_getdetachstate.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_getdetachstate(
|
||||
attr: *const pthread_attr_t,
|
||||
@@ -49,6 +51,7 @@ pub unsafe extern "C" fn pthread_attr_getdetachstate(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_getguardsize.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_getguardsize(
|
||||
attr: *const pthread_attr_t,
|
||||
@@ -58,6 +61,7 @@ pub unsafe extern "C" fn pthread_attr_getguardsize(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_getinheritsched.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_getinheritsched(
|
||||
attr: *const pthread_attr_t,
|
||||
@@ -67,6 +71,7 @@ pub unsafe extern "C" fn pthread_attr_getinheritsched(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_getschedparam.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_getschedparam(
|
||||
attr: *const pthread_attr_t,
|
||||
@@ -76,6 +81,7 @@ pub unsafe extern "C" fn pthread_attr_getschedparam(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_getschedpolicy.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_getschedpolicy(
|
||||
attr: *const pthread_attr_t,
|
||||
@@ -85,6 +91,7 @@ pub unsafe extern "C" fn pthread_attr_getschedpolicy(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_getscope.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_getscope(
|
||||
attr: *const pthread_attr_t,
|
||||
@@ -94,6 +101,7 @@ pub unsafe extern "C" fn pthread_attr_getscope(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_getstack.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_getstack(
|
||||
attr: *const pthread_attr_t,
|
||||
@@ -105,6 +113,7 @@ pub unsafe extern "C" fn pthread_attr_getstack(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_getstacksize.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_getstacksize(
|
||||
attr: *const pthread_attr_t,
|
||||
@@ -114,12 +123,14 @@ pub unsafe extern "C" fn pthread_attr_getstacksize(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_init.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_init(attr: *mut pthread_attr_t) -> c_int {
|
||||
unsafe { ptr::write(attr.cast::<RlctAttr>(), RlctAttr::default()) };
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_setdetachstate.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_setdetachstate(
|
||||
attr: *mut pthread_attr_t,
|
||||
@@ -131,6 +142,7 @@ pub unsafe extern "C" fn pthread_attr_setdetachstate(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_setguardsize.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_setguardsize(
|
||||
attr: *mut pthread_attr_t,
|
||||
@@ -142,6 +154,7 @@ pub unsafe extern "C" fn pthread_attr_setguardsize(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_setinheritsched.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_setinheritsched(
|
||||
attr: *mut pthread_attr_t,
|
||||
@@ -153,6 +166,7 @@ pub unsafe extern "C" fn pthread_attr_setinheritsched(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_setschedparam.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_setschedparam(
|
||||
attr: *mut pthread_attr_t,
|
||||
@@ -164,6 +178,7 @@ pub unsafe extern "C" fn pthread_attr_setschedparam(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_setschedpolicy.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_setschedpolicy(
|
||||
attr: *mut pthread_attr_t,
|
||||
@@ -175,6 +190,7 @@ pub unsafe extern "C" fn pthread_attr_setschedpolicy(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_setscope.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_setscope(attr: *mut pthread_attr_t, scope: c_int) -> c_int {
|
||||
unsafe {
|
||||
@@ -183,6 +199,7 @@ pub unsafe extern "C" fn pthread_attr_setscope(attr: *mut pthread_attr_t, scope:
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_setstack.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_setstack(
|
||||
attr: *mut pthread_attr_t,
|
||||
@@ -198,6 +215,7 @@ pub unsafe extern "C" fn pthread_attr_setstack(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_attr_setstacksize.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_setstacksize(
|
||||
attr: *mut pthread_attr_t,
|
||||
|
||||
@@ -22,6 +22,7 @@ impl Default for RlctBarrierAttr {
|
||||
}
|
||||
|
||||
// Not async-signal-safe.
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_barrier_destroy.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_barrier_destroy(barrier: *mut pthread_barrier_t) -> c_int {
|
||||
// Behavior is undefined if any thread is currently waiting when this is called.
|
||||
@@ -33,6 +34,7 @@ pub unsafe extern "C" fn pthread_barrier_destroy(barrier: *mut pthread_barrier_t
|
||||
}
|
||||
|
||||
// Not async-signal-safe.
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_barrier_init.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_barrier_init(
|
||||
barrier: *mut pthread_barrier_t,
|
||||
@@ -56,6 +58,7 @@ fn unlikely(condition: bool) -> bool {
|
||||
}
|
||||
|
||||
// Not async-signal-safe.
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_barrier_wait.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_barrier_wait(barrier: *mut pthread_barrier_t) -> c_int {
|
||||
let barrier = unsafe { &*barrier.cast::<RlctBarrier>() };
|
||||
@@ -67,6 +70,7 @@ pub unsafe extern "C" fn pthread_barrier_wait(barrier: *mut pthread_barrier_t) -
|
||||
}
|
||||
|
||||
// Not async-signal-safe.
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_barrierattr_init.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_barrierattr_init(attr: *mut pthread_barrierattr_t) -> c_int {
|
||||
unsafe { core::ptr::write(attr.cast::<RlctBarrierAttr>(), RlctBarrierAttr::default()) };
|
||||
@@ -75,6 +79,7 @@ pub unsafe extern "C" fn pthread_barrierattr_init(attr: *mut pthread_barrierattr
|
||||
}
|
||||
|
||||
// Not async-signal-safe.
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_barrierattr_setpshared.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_barrierattr_setpshared(
|
||||
attr: *mut pthread_barrierattr_t,
|
||||
@@ -87,6 +92,7 @@ pub unsafe extern "C" fn pthread_barrierattr_setpshared(
|
||||
}
|
||||
|
||||
// Not async-signal-safe.
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_barrierattr_getpshared.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_barrierattr_getpshared(
|
||||
attr: *const pthread_barrierattr_t,
|
||||
@@ -97,6 +103,7 @@ pub unsafe extern "C" fn pthread_barrierattr_getpshared(
|
||||
}
|
||||
|
||||
// Not async-signal-safe.
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_barrierattr_destroy.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_barrierattr_destroy(attr: *mut pthread_barrierattr_t) -> c_int {
|
||||
unsafe { core::ptr::drop_in_place(attr) };
|
||||
|
||||
@@ -6,11 +6,13 @@ use super::*;
|
||||
|
||||
// PTHREAD_COND_INITIALIZER is defined manually in bits_pthread/cbindgen.toml
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_cond_broadcast.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> c_int {
|
||||
e((unsafe { &*cond.cast::<RlctCond>() }).broadcast())
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_cond_destroy.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> c_int {
|
||||
// No-op
|
||||
@@ -18,6 +20,7 @@ pub unsafe extern "C" fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> c_in
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_cond_init.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_cond_init(
|
||||
cond: *mut pthread_cond_t,
|
||||
@@ -37,11 +40,13 @@ pub unsafe extern "C" fn pthread_cond_init(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_cond_signal.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_cond_signal(cond: *mut pthread_cond_t) -> c_int {
|
||||
e((unsafe { &*cond.cast::<RlctCond>() }).signal())
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_cond_timedwait.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_cond_timedwait(
|
||||
cond: *mut pthread_cond_t,
|
||||
@@ -52,6 +57,7 @@ pub unsafe extern "C" fn pthread_cond_timedwait(
|
||||
.timedwait(unsafe { &*mutex.cast::<RlctMutex>() }, unsafe { &*timeout }))
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_cond_clockwait.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_cond_clockwait(
|
||||
cond: *mut pthread_cond_t,
|
||||
@@ -66,6 +72,7 @@ pub unsafe extern "C" fn pthread_cond_clockwait(
|
||||
))
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_cond_wait.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_cond_wait(
|
||||
cond: *mut pthread_cond_t,
|
||||
@@ -74,6 +81,7 @@ pub unsafe extern "C" fn pthread_cond_wait(
|
||||
e((unsafe { &*cond.cast::<RlctCond>() }).wait(unsafe { &*mutex.cast::<RlctMutex>() }))
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_condattr_destroy.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_condattr_destroy(condattr: *mut pthread_condattr_t) -> c_int {
|
||||
unsafe { core::ptr::drop_in_place(condattr.cast::<RlctCondAttr>()) };
|
||||
@@ -81,6 +89,7 @@ pub unsafe extern "C" fn pthread_condattr_destroy(condattr: *mut pthread_condatt
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_condattr_getclock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_condattr_getclock(
|
||||
condattr: *const pthread_condattr_t,
|
||||
@@ -90,6 +99,7 @@ pub unsafe extern "C" fn pthread_condattr_getclock(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_condattr_getpshared.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_condattr_getpshared(
|
||||
condattr: *const pthread_condattr_t,
|
||||
@@ -99,6 +109,7 @@ pub unsafe extern "C" fn pthread_condattr_getpshared(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_condattr_init.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_condattr_init(condattr: *mut pthread_condattr_t) -> c_int {
|
||||
unsafe {
|
||||
@@ -109,6 +120,7 @@ pub unsafe extern "C" fn pthread_condattr_init(condattr: *mut pthread_condattr_t
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_condattr_setclock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_condattr_setclock(
|
||||
condattr: *mut pthread_condattr_t,
|
||||
@@ -118,6 +130,7 @@ pub unsafe extern "C" fn pthread_condattr_setclock(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_condattr_setpshared.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_condattr_setpshared(
|
||||
condattr: *mut pthread_condattr_t,
|
||||
|
||||
@@ -8,10 +8,12 @@ use crate::{error::Errno, header::time::timespec_realtime_to_monotonic};
|
||||
|
||||
// PTHREAD_MUTEX_INITIALIZER is defined in bits_pthread/cbindgen.toml
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutex_consistent.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_consistent(mutex: *mut pthread_mutex_t) -> c_int {
|
||||
e((unsafe { &*mutex.cast::<RlctMutex>() }).make_consistent())
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutex_destroy.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_destroy(mutex: *mut pthread_mutex_t) -> c_int {
|
||||
// No-op
|
||||
@@ -19,6 +21,7 @@ pub unsafe extern "C" fn pthread_mutex_destroy(mutex: *mut pthread_mutex_t) -> c
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutex_getprioceiling.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_getprioceiling(
|
||||
mutex: *const pthread_mutex_t,
|
||||
@@ -33,6 +36,7 @@ pub unsafe extern "C" fn pthread_mutex_getprioceiling(
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutex_init.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_init(
|
||||
mutex: *mut pthread_mutex_t,
|
||||
@@ -51,11 +55,13 @@ pub unsafe extern "C" fn pthread_mutex_init(
|
||||
Err(Errno(errno)) => errno,
|
||||
}
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutex_lock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_lock(mutex: *mut pthread_mutex_t) -> c_int {
|
||||
e((unsafe { &*mutex.cast::<RlctMutex>() }).lock())
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutex_setprioceiling.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_setprioceiling(
|
||||
mutex: *mut pthread_mutex_t,
|
||||
@@ -71,6 +77,7 @@ pub unsafe extern "C" fn pthread_mutex_setprioceiling(
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutex_timedlock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_timedlock(
|
||||
mutex: *mut pthread_mutex_t,
|
||||
@@ -84,15 +91,18 @@ pub unsafe extern "C" fn pthread_mutex_timedlock(
|
||||
e((unsafe { &*mutex.cast::<RlctMutex>() }).lock_with_timeout(&relative))
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutex_trylock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_trylock(mutex: *mut pthread_mutex_t) -> c_int {
|
||||
e((unsafe { &*mutex.cast::<RlctMutex>() }).try_lock())
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutex_unlock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_unlock(mutex: *mut pthread_mutex_t) -> c_int {
|
||||
e((unsafe { &*mutex.cast::<RlctMutex>() }).unlock())
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutexattr_destroy.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> c_int {
|
||||
// No-op
|
||||
@@ -100,6 +110,7 @@ pub unsafe extern "C" fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutexattr_getprioceiling.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_getprioceiling(
|
||||
attr: *const pthread_mutexattr_t,
|
||||
@@ -109,6 +120,7 @@ pub unsafe extern "C" fn pthread_mutexattr_getprioceiling(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutexattr_getprotocol.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_getprotocol(
|
||||
attr: *const pthread_mutexattr_t,
|
||||
@@ -118,6 +130,7 @@ pub unsafe extern "C" fn pthread_mutexattr_getprotocol(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutexattr_getpshared.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_getpshared(
|
||||
attr: *const pthread_mutexattr_t,
|
||||
@@ -127,6 +140,7 @@ pub unsafe extern "C" fn pthread_mutexattr_getpshared(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutexattr_getrobust.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_getrobust(
|
||||
attr: *const pthread_mutexattr_t,
|
||||
@@ -135,6 +149,7 @@ pub unsafe extern "C" fn pthread_mutexattr_getrobust(
|
||||
*robust = unsafe { &*attr.cast::<RlctMutexAttr>() }.robust;
|
||||
0
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutexattr_gettype.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_gettype(
|
||||
attr: *const pthread_mutexattr_t,
|
||||
@@ -143,12 +158,14 @@ pub unsafe extern "C" fn pthread_mutexattr_gettype(
|
||||
*ty = unsafe { &*attr.cast::<RlctMutexAttr>() }.ty;
|
||||
0
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutexattr_init.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> c_int {
|
||||
unsafe { attr.cast::<RlctMutexAttr>().write(RlctMutexAttr::default()) };
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutexattr_setprioceiling.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_setprioceiling(
|
||||
attr: *mut pthread_mutexattr_t,
|
||||
@@ -158,6 +175,7 @@ pub unsafe extern "C" fn pthread_mutexattr_setprioceiling(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutexattr_setprotocol.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_setprotocol(
|
||||
attr: *mut pthread_mutexattr_t,
|
||||
@@ -167,6 +185,7 @@ pub unsafe extern "C" fn pthread_mutexattr_setprotocol(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutexattr_setpshared.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_setpshared(
|
||||
attr: *mut pthread_mutexattr_t,
|
||||
@@ -176,6 +195,7 @@ pub unsafe extern "C" fn pthread_mutexattr_setpshared(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutexattr_setrobust.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_setrobust(
|
||||
attr: *mut pthread_mutexattr_t,
|
||||
@@ -184,6 +204,7 @@ pub unsafe extern "C" fn pthread_mutexattr_setrobust(
|
||||
unsafe { &mut *attr.cast::<RlctMutexAttr>() }.robust = robust;
|
||||
0
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutexattr_settype.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_settype(
|
||||
attr: *mut pthread_mutexattr_t,
|
||||
|
||||
@@ -2,6 +2,7 @@ use super::*;
|
||||
|
||||
// PTHREAD_ONCE_INIT
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_once.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_once(
|
||||
once: *mut pthread_once_t,
|
||||
|
||||
@@ -4,6 +4,7 @@ use crate::header::errno::{EBUSY, EINVAL};
|
||||
|
||||
use crate::{header::time::CLOCK_REALTIME, pthread::Pshared};
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlock_init.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_init(
|
||||
rwlock: *mut pthread_rwlock_t,
|
||||
@@ -21,6 +22,7 @@ pub unsafe extern "C" fn pthread_rwlock_init(
|
||||
|
||||
0
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlock_rdlock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_rdlock(rwlock: *mut pthread_rwlock_t) -> c_int {
|
||||
match unsafe { get(rwlock) }.acquire_read_lock(None) {
|
||||
@@ -28,6 +30,7 @@ pub unsafe extern "C" fn pthread_rwlock_rdlock(rwlock: *mut pthread_rwlock_t) ->
|
||||
Err(e) => e.0,
|
||||
}
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlock_clockrdlock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_clockrdlock(
|
||||
rwlock: *mut pthread_rwlock_t,
|
||||
@@ -39,6 +42,7 @@ pub unsafe extern "C" fn pthread_rwlock_clockrdlock(
|
||||
Err(e) => e.0,
|
||||
}
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlock_timedrdlock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_timedrdlock(
|
||||
rwlock: *mut pthread_rwlock_t,
|
||||
@@ -49,6 +53,7 @@ pub unsafe extern "C" fn pthread_rwlock_timedrdlock(
|
||||
Err(e) => e.0,
|
||||
}
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlock_clockwrlock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_clockwrlock(
|
||||
rwlock: *mut pthread_rwlock_t,
|
||||
@@ -60,6 +65,7 @@ pub unsafe extern "C" fn pthread_rwlock_clockwrlock(
|
||||
Err(e) => e.0,
|
||||
}
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlock_timedwrlock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_timedwrlock(
|
||||
rwlock: *mut pthread_rwlock_t,
|
||||
@@ -70,6 +76,7 @@ pub unsafe extern "C" fn pthread_rwlock_timedwrlock(
|
||||
Err(e) => e.0,
|
||||
}
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlock_tryrdlock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_tryrdlock(rwlock: *mut pthread_rwlock_t) -> c_int {
|
||||
match unsafe { get(rwlock) }.try_acquire_read_lock() {
|
||||
@@ -77,6 +84,7 @@ pub unsafe extern "C" fn pthread_rwlock_tryrdlock(rwlock: *mut pthread_rwlock_t)
|
||||
Err(_) => EBUSY,
|
||||
}
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlock_trywrlock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_trywrlock(rwlock: *mut pthread_rwlock_t) -> c_int {
|
||||
match unsafe { get(rwlock) }.try_acquire_write_lock() {
|
||||
@@ -84,12 +92,14 @@ pub unsafe extern "C" fn pthread_rwlock_trywrlock(rwlock: *mut pthread_rwlock_t)
|
||||
Err(_) => EBUSY,
|
||||
}
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlock_unlock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_unlock(rwlock: *mut pthread_rwlock_t) -> c_int {
|
||||
unsafe { get(rwlock) }.unlock();
|
||||
|
||||
0
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlock_wrlock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_wrlock(rwlock: *mut pthread_rwlock_t) -> c_int {
|
||||
match unsafe { get(rwlock) }.acquire_write_lock(None) {
|
||||
@@ -98,6 +108,7 @@ pub unsafe extern "C" fn pthread_rwlock_wrlock(rwlock: *mut pthread_rwlock_t) ->
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlockattr_init.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlockattr_init(attr: *mut pthread_rwlockattr_t) -> c_int {
|
||||
unsafe {
|
||||
@@ -108,6 +119,7 @@ pub unsafe extern "C" fn pthread_rwlockattr_init(attr: *mut pthread_rwlockattr_t
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlockattr_getpshared.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlockattr_getpshared(
|
||||
attr: *const pthread_rwlockattr_t,
|
||||
@@ -118,6 +130,7 @@ pub unsafe extern "C" fn pthread_rwlockattr_getpshared(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlockattr_setpshared.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlockattr_setpshared(
|
||||
attr: *mut pthread_rwlockattr_t,
|
||||
@@ -131,12 +144,14 @@ pub unsafe extern "C" fn pthread_rwlockattr_setpshared(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlockattr_destroy.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlockattr_destroy(attr: *mut pthread_rwlockattr_t) -> c_int {
|
||||
unsafe { core::ptr::drop_in_place(attr) };
|
||||
|
||||
0
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlock_destroy.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_destroy(rwlock: *mut pthread_rwlock_t) -> c_int {
|
||||
unsafe { core::ptr::drop_in_place(rwlock) };
|
||||
|
||||
@@ -7,6 +7,7 @@ use super::*;
|
||||
const UNLOCKED: c_int = 0;
|
||||
const LOCKED: c_int = 1;
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_spin_destroy.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_spin_destroy(spinlock: *mut pthread_spinlock_t) -> c_int {
|
||||
let _spinlock = unsafe { &mut *spinlock.cast::<RlctSpinlock>() };
|
||||
@@ -14,6 +15,7 @@ pub unsafe extern "C" fn pthread_spin_destroy(spinlock: *mut pthread_spinlock_t)
|
||||
// No-op
|
||||
0
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_spin_init.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_spin_init(
|
||||
spinlock: *mut pthread_spinlock_t,
|
||||
@@ -30,6 +32,7 @@ pub unsafe extern "C" fn pthread_spin_init(
|
||||
|
||||
0
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_spin_lock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_spin_lock(spinlock: *mut pthread_spinlock_t) -> c_int {
|
||||
let spinlock = unsafe { &*spinlock.cast::<RlctSpinlock>() };
|
||||
@@ -48,6 +51,7 @@ pub unsafe extern "C" fn pthread_spin_lock(spinlock: *mut pthread_spinlock_t) ->
|
||||
|
||||
0
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_spin_trylock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_spin_trylock(spinlock: *mut pthread_spinlock_t) -> c_int {
|
||||
let spinlock = unsafe { &*spinlock.cast::<RlctSpinlock>() };
|
||||
@@ -62,6 +66,7 @@ pub unsafe extern "C" fn pthread_spin_trylock(spinlock: *mut pthread_spinlock_t)
|
||||
|
||||
0
|
||||
}
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_spin_unlock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_spin_unlock(spinlock: *mut pthread_spinlock_t) -> c_int {
|
||||
let spinlock = unsafe { &*spinlock.cast::<RlctSpinlock>() };
|
||||
|
||||
@@ -29,6 +29,7 @@ static VALUES: RefCell<BTreeMap<pthread_key_t, Record>> = RefCell::new(BTreeMap:
|
||||
static KEYS: Mutex<BTreeMap<pthread_key_t, Dtor>> = Mutex::new(BTreeMap::new());
|
||||
static NEXTKEY: AtomicUsize = AtomicUsize::new(1);
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_getspecific.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_getspecific(key: pthread_key_t) -> *mut c_void {
|
||||
// According to POSIX (issue 8): Calling [`pthread_getspecific`] with a key
|
||||
@@ -44,6 +45,7 @@ pub unsafe extern "C" fn pthread_getspecific(key: pthread_key_t) -> *mut c_void
|
||||
.unwrap_or(ptr::null_mut())
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_setspecific.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_setspecific(key: pthread_key_t, value: *const c_void) -> c_int {
|
||||
if !KEYS.lock().contains_key(&key) {
|
||||
@@ -63,6 +65,7 @@ pub unsafe extern "C" fn pthread_setspecific(key: pthread_key_t, value: *const c
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_key_create.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_key_create(
|
||||
key_ptr: *mut pthread_key_t,
|
||||
@@ -80,6 +83,7 @@ pub unsafe extern "C" fn pthread_key_create(
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_key_delete.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_key_delete(key: pthread_key_t) -> c_int {
|
||||
if KEYS.lock().remove(&key).is_none() || VALUES.borrow_mut().remove(&key).is_none() {
|
||||
|
||||
Reference in New Issue
Block a user