Commit 752138de authored by Jeremy Soller's avatar Jeremy Soller

Merge branch 'nanosleep' into 'master'

implement remainder for nanosleep

See merge request !110
parents af93866c f75e1c48
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment