Skip to content
Snippets Groups Projects

implement remainder for nanosleep

Merged Timothy DeHerrera requested to merge nrdxp/kernel:nanosleep into master
All threads resolved!
+ 15
4
@@ -21,7 +21,7 @@ pub fn nanosleep(req: &TimeSpec, rem_opt: Option<&mut TimeSpec>) -> Result<usize
//start is a tuple of (seconds, nanoseconds)
let start = time::monotonic();
let sum = start.1 + req.tv_nsec as u64;
let end = (start.0 + req.tv_sec as u64 + sum / 1_000_000_000, sum % 1_000_000_000);
let mut end = (start.0 + req.tv_sec as u64 + sum / 1_000_000_000, sum % 1_000_000_000);
{
let contexts = context::contexts();
@@ -35,9 +35,20 @@ pub fn nanosleep(req: &TimeSpec, rem_opt: Option<&mut TimeSpec>) -> Result<usize
unsafe { context::switch(); }
if let Some(rem) = rem_opt {
//TODO let current = time::monotonic();
rem.tv_sec = 0;
rem.tv_nsec = 0;
let current = time::monotonic();
if current.0 < end.0 || (current.0 == end.0 && current.1 < end.1) {
if end.1 < current.1 {
end.0 -= 1;
end.1 += 1_000_000_000;
}
rem.tv_sec = (end.0 - current.0) as i64;
rem.tv_nsec = (end.1 - current.1) as i32;
} else {
rem.tv_sec = 0;
rem.tv_nsec = 0;
}
}
Ok(0)
Loading