Skip to content

Commit

Permalink
remove the definition of itimerval in kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
AuYang261 committed Oct 12, 2023
1 parent 372f8e6 commit 25f0f96
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions modules/axruntime/src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,10 @@
use core::sync::atomic::AtomicI64;
use core::{ffi::c_int, time::Duration};

#[allow(non_camel_case_types)]
#[derive(Copy, Clone, Debug)]
struct itimerval {
it_interval: Duration,
it_value: Duration,
}

/// sigset_t in kernel
#[allow(non_camel_case_types)]
#[derive(Copy, Clone, Debug, Default)]
pub struct __sigset_t {
pub struct __k_sigset_t {
__bits: [core::ffi::c_ulong; 16usize],
}

Expand All @@ -33,7 +26,7 @@ pub struct k_sigaction {
/// signal handler
pub sa_handler: Option<unsafe extern "C" fn(c_int)>,
/// signal mask
pub sa_mask: __sigset_t,
pub sa_mask: __k_sigset_t,
/// signal flags
pub sa_flags: i32,
/// signal restorer
Expand All @@ -45,7 +38,8 @@ pub struct Signal {
#[cfg(feature = "irq")]
signal: AtomicI64,
sigaction: [k_sigaction; 32],
timer: [itimerval; 3],
timer_value: [Duration; 3],
timer_interval: [Duration; 3],
}

unsafe extern "C" fn default_handler(signum: c_int) {
Expand All @@ -57,15 +51,13 @@ static mut SIGNAL_IF: Signal = Signal {
signal: AtomicI64::new(0),
sigaction: [k_sigaction {
sa_handler: Some(default_handler),
sa_mask: __sigset_t { __bits: [0; 16] },
sa_mask: __k_sigset_t { __bits: [0; 16] },
sa_flags: 0,
sa_restorer: None,
}; 32],
// Default::default() is not const
timer: [itimerval {
it_interval: Duration::new(0, 0),
it_value: Duration::new(0, 0),
}; 3],
timer_value: [Duration::from_nanos(0); 3],
timer_interval: [Duration::from_nanos(0); 3],
};

impl Signal {
Expand Down Expand Up @@ -131,13 +123,13 @@ impl Signal {
/// new_value: new timer value
/// old_value: old timer value
pub fn timer_deadline(which: usize, new_deadline: Option<u64>) -> Option<u64> {
if which >= unsafe { SIGNAL_IF.timer }.len() {
if which >= unsafe { SIGNAL_IF.timer_value }.len() {
return None;
}
let old = unsafe { SIGNAL_IF.timer }[which].it_value;
let old = unsafe { SIGNAL_IF.timer_value }[which];
if let Some(s) = new_deadline {
unsafe {
SIGNAL_IF.timer[which].it_value = Duration::from_nanos(s);
SIGNAL_IF.timer_value[which] = Duration::from_nanos(s);
}
}
Some(old.as_nanos() as u64)
Expand All @@ -147,13 +139,13 @@ impl Signal {
/// new_interval: new timer interval
/// old_interval: old timer interval
pub fn timer_interval(which: usize, new_interval: Option<u64>) -> Option<u64> {
if which >= unsafe { SIGNAL_IF.timer }.len() {
if which >= unsafe { SIGNAL_IF.timer_interval }.len() {
return None;
}
let old = unsafe { SIGNAL_IF.timer }[which].it_interval;
let old = unsafe { SIGNAL_IF.timer_interval }[which];
if let Some(s) = new_interval {
unsafe {
SIGNAL_IF.timer[which].it_interval = Duration::from_nanos(s);
SIGNAL_IF.timer_interval[which] = Duration::from_nanos(s);
}
}
Some(old.as_nanos() as u64)
Expand Down

0 comments on commit 25f0f96

Please sign in to comment.