use crate::{ctypes, utils::e};
use arceos_posix_api as api;
use core::ffi::{c_int, c_void};
#[no_mangle]
pub unsafe extern "C" fn pthread_self() -> ctypes::pthread_t {
api::sys_pthread_self()
}
#[no_mangle]
pub unsafe extern "C" fn pthread_create(
res: *mut ctypes::pthread_t,
attr: *const ctypes::pthread_attr_t,
start_routine: extern "C" fn(arg: *mut c_void) -> *mut c_void,
arg: *mut c_void,
) -> c_int {
e(api::sys_pthread_create(res, attr, start_routine, arg))
}
#[no_mangle]
pub unsafe extern "C" fn pthread_exit(retval: *mut c_void) -> ! {
api::sys_pthread_exit(retval)
}
#[no_mangle]
pub unsafe extern "C" fn pthread_join(
thread: ctypes::pthread_t,
retval: *mut *mut c_void,
) -> c_int {
e(api::sys_pthread_join(thread, retval))
}
#[no_mangle]
pub unsafe extern "C" fn pthread_mutex_init(
mutex: *mut ctypes::pthread_mutex_t,
attr: *const ctypes::pthread_mutexattr_t,
) -> c_int {
e(api::sys_pthread_mutex_init(mutex, attr))
}
#[no_mangle]
pub unsafe extern "C" fn pthread_mutex_destroy(mutex: *mut ctypes::pthread_mutex_t) -> c_int {
e(api::sys_pthread_mutex_destroy(mutex))
}
#[no_mangle]
pub unsafe extern "C" fn pthread_mutex_lock(mutex: *mut ctypes::pthread_mutex_t) -> c_int {
e(api::sys_pthread_mutex_lock(mutex))
}
#[no_mangle]
pub unsafe extern "C" fn pthread_mutex_trylock(mutex: *mut ctypes::pthread_mutex_t) -> c_int {
e(api::sys_pthread_mutex_trylock(mutex))
}
#[no_mangle]
pub unsafe extern "C" fn pthread_mutex_unlock(mutex: *mut ctypes::pthread_mutex_t) -> c_int {
e(api::sys_pthread_mutex_unlock(mutex))
}
#[no_mangle]
pub unsafe extern "C" fn pthread_cond_init(
condvar: *mut ctypes::pthread_cond_t,
attr: *mut ctypes::pthread_condattr_t,
) -> c_int {
e(api::sys_pthread_cond_init(condvar, attr))
}
#[no_mangle]
pub unsafe extern "C" fn pthread_cond_destroy(condvar: *mut ctypes::pthread_cond_t) -> c_int {
e(api::sys_pthread_cond_destroy(condvar))
}
#[no_mangle]
pub unsafe extern "C" fn pthread_cond_timedwait(
condvar: *mut ctypes::pthread_cond_t,
mutex: *mut ctypes::pthread_mutex_t,
abstime: *const ctypes::timespec,
) -> c_int {
e(api::sys_pthread_cond_timedwait(condvar, mutex, abstime))
}
#[no_mangle]
pub unsafe extern "C" fn pthread_cond_wait(
condvar: *mut ctypes::pthread_cond_t,
mutex: *mut ctypes::pthread_mutex_t,
) -> c_int {
e(api::sys_pthread_cond_wait(condvar, mutex))
}
#[no_mangle]
pub unsafe extern "C" fn pthread_cond_signal(condvar: *mut ctypes::pthread_cond_t) -> c_int {
e(api::sys_pthread_cond_signal(condvar))
}
#[no_mangle]
pub unsafe extern "C" fn pthread_cond_broadcast(condvar: *mut ctypes::pthread_cond_t) -> c_int {
e(api::sys_pthread_cond_broadcast(condvar))
}
#[no_mangle]
pub unsafe extern "C" fn pthread_key_create(
key: *mut ctypes::pthread_key_t,
dtor: Option<unsafe extern "C" fn(*mut c_void)>,
) -> c_int {
e(api::sys_pthread_key_create(key, dtor))
}
#[no_mangle]
pub unsafe extern "C" fn pthread_key_delete(key: ctypes::pthread_key_t) -> c_int {
e(api::sys_pthread_key_delete(key))
}
#[no_mangle]
pub unsafe extern "C" fn pthread_getspecific(key: ctypes::pthread_key_t) -> *mut c_void {
api::sys_pthread_getspecific(key)
}
#[no_mangle]
pub unsafe extern "C" fn pthread_setspecific(
key: ctypes::pthread_key_t,
value: *const c_void,
) -> c_int {
e(api::sys_pthread_setspecific(key, value))
}