Unify alarm implementation
This commit is contained in:
@@ -783,7 +783,7 @@ impl Pal for Sys {
|
||||
syscall!(
|
||||
TIMER_CREATE,
|
||||
clock_id,
|
||||
ptr::addr_of!(evp),
|
||||
evp as *const _,
|
||||
timerid.as_mut_ptr()
|
||||
)
|
||||
})
|
||||
@@ -809,7 +809,7 @@ impl Pal for Sys {
|
||||
TIMER_SETTIME,
|
||||
timerid,
|
||||
flags,
|
||||
ptr::addr_of!(value),
|
||||
value as *const _,
|
||||
match ovalue {
|
||||
None => ptr::null_mut(),
|
||||
Some(mut o) => o.as_mut_ptr(),
|
||||
|
||||
@@ -6,7 +6,7 @@ use core::{
|
||||
use super::{
|
||||
super::{
|
||||
PalSignal,
|
||||
types::{c_int, c_uint, pid_t},
|
||||
types::{c_int, pid_t},
|
||||
},
|
||||
Sys, e_raw,
|
||||
};
|
||||
@@ -16,14 +16,9 @@ use crate::{
|
||||
error::{Errno, Result},
|
||||
header::{
|
||||
bits_sigset_t::sigset_t,
|
||||
signal::{
|
||||
SA_RESTORER, SI_QUEUE, SIGALRM, SIGEV_SIGNAL, sigaction, sigevent, siginfo_t, sigval,
|
||||
stack_t,
|
||||
},
|
||||
time::{self, timespec},
|
||||
bits_timespec::timespec,
|
||||
signal::{SA_RESTORER, SI_QUEUE, sigaction, siginfo_t, sigval, stack_t},
|
||||
},
|
||||
out::Out,
|
||||
platform::{self, Pal, types::timer_t},
|
||||
};
|
||||
|
||||
impl PalSignal for Sys {
|
||||
@@ -77,44 +72,6 @@ impl PalSignal for Sys {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/alarm.html>.
|
||||
fn alarm(seconds: c_uint) -> c_uint {
|
||||
let mut signal_event = sigevent {
|
||||
sigev_value: sigval { sival_int: 0 },
|
||||
sigev_signo: SIGALRM as c_int,
|
||||
sigev_notify: SIGEV_SIGNAL,
|
||||
sigev_notify_attributes: ptr::null_mut(),
|
||||
sigev_notify_function: None,
|
||||
};
|
||||
let mut timerid: timer_t = Default::default();
|
||||
let timer = unsafe {
|
||||
time::timer_create(
|
||||
time::CLOCK_REALTIME,
|
||||
ptr::from_mut(&mut signal_event),
|
||||
ptr::from_mut(&mut timerid),
|
||||
)
|
||||
};
|
||||
let value = time::itimerspec {
|
||||
it_value: timespec {
|
||||
tv_sec: i64::from(seconds),
|
||||
tv_nsec: 0,
|
||||
},
|
||||
it_interval: timespec {
|
||||
tv_sec: 0,
|
||||
tv_nsec: 0,
|
||||
},
|
||||
};
|
||||
let mut ovalue = Default::default();
|
||||
|
||||
let errno_backup = platform::ERRNO.get();
|
||||
if Sys::timer_settime(timerid, 0, &value, Some(Out::from_mut(&mut ovalue))).is_err() {
|
||||
platform::ERRNO.set(errno_backup);
|
||||
0
|
||||
} else {
|
||||
ovalue.it_value.tv_sec as c_uint + if ovalue.it_value.tv_nsec > 0 { 1 } else { 0 }
|
||||
}
|
||||
}
|
||||
|
||||
fn sigaction(
|
||||
sig: c_int,
|
||||
act: Option<&sigaction>,
|
||||
|
||||
Reference in New Issue
Block a user