refactor nanosleep
This commit is contained in:
@@ -138,27 +138,23 @@ pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int {
|
||||
}
|
||||
|
||||
pub fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int {
|
||||
unsafe {
|
||||
let redox_rqtp = redox_timespec {
|
||||
tv_sec: (*rqtp).tv_sec,
|
||||
tv_nsec: (*rqtp).tv_nsec as i32,
|
||||
};
|
||||
let mut redox_rmtp: redox_timespec;
|
||||
if rmtp.is_null() {
|
||||
redox_rmtp = redox_timespec::default();
|
||||
} else {
|
||||
redox_rmtp = redox_timespec {
|
||||
tv_sec: (*rmtp).tv_sec,
|
||||
tv_nsec: (*rmtp).tv_nsec as i32,
|
||||
};
|
||||
}
|
||||
match e(syscall::nanosleep(&redox_rqtp, &mut redox_rmtp)) as c_int {
|
||||
-1 => -1,
|
||||
_ => {
|
||||
(*rmtp).tv_sec = redox_rmtp.tv_sec;
|
||||
(*rmtp).tv_nsec = redox_rmtp.tv_nsec as i64;
|
||||
0
|
||||
let redox_rqtp = unsafe { redox_timespec::from(&*rqtp) };
|
||||
let mut redox_rmtp: redox_timespec;
|
||||
if rmtp.is_null() {
|
||||
redox_rmtp = redox_timespec::default();
|
||||
} else {
|
||||
redox_rmtp = unsafe { redox_timespec::from(&*rmtp) };
|
||||
}
|
||||
match e(syscall::nanosleep(&redox_rqtp, &mut redox_rmtp)) as c_int {
|
||||
-1 => -1,
|
||||
_ => {
|
||||
unsafe {
|
||||
if !rmtp.is_null() {
|
||||
(*rmtp).tv_sec = redox_rmtp.tv_sec;
|
||||
(*rmtp).tv_nsec = redox_rmtp.tv_nsec as i64;
|
||||
}
|
||||
}
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#[cfg(target_os = "redox")]
|
||||
use syscall::data::TimeSpec as redox_timespec;
|
||||
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
|
||||
// more optimization opportunities around it recognizing things like
|
||||
// malloc/free.
|
||||
@@ -70,3 +72,13 @@ pub struct timespec {
|
||||
pub tv_sec: time_t,
|
||||
pub tv_nsec: c_long,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
impl<'a> From<&'a timespec> for redox_timespec {
|
||||
fn from(tp: ×pec) -> redox_timespec {
|
||||
redox_timespec {
|
||||
tv_sec: tp.tv_sec,
|
||||
tv_nsec: tp.tv_nsec as i32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user