open_coroutine_hooks/unix/
sleep.rs1use libc::timespec;
2use once_cell::sync::Lazy;
3use std::ffi::{c_int, c_uint};
4
5static SLEEP: Lazy<extern "C" fn(c_uint) -> c_uint> = init_hook!("sleep");
6
7#[no_mangle]
8pub extern "C" fn sleep(secs: c_uint) -> c_uint {
9 open_coroutine_core::syscall::sleep(Some(Lazy::force(&SLEEP)), secs)
10}
11
12static USLEEP: Lazy<extern "C" fn(c_uint) -> c_int> = init_hook!("usleep");
13
14#[no_mangle]
15pub extern "C" fn usleep(secs: c_uint) -> c_int {
16 open_coroutine_core::syscall::usleep(Some(Lazy::force(&USLEEP)), secs)
17}
18
19static NANOSLEEP: Lazy<extern "C" fn(*const timespec, *mut timespec) -> c_int> =
20 init_hook!("nanosleep");
21
22#[no_mangle]
23#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
24pub extern "C" fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int {
25 open_coroutine_core::syscall::nanosleep(Some(Lazy::force(&NANOSLEEP)), rqtp, rmtp)
26}