Skip to content
Snippets Groups Projects
Commit 752138de authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Merge branch 'nanosleep' into 'master'

implement remainder for nanosleep

See merge request redox-os/kernel!110
parents af93866c f75e1c48
No related branches found
No related tags found
1 merge request!110implement remainder for nanosleep
...@@ -21,7 +21,7 @@ pub fn nanosleep(req: &TimeSpec, rem_opt: Option<&mut TimeSpec>) -> Result<usize ...@@ -21,7 +21,7 @@ pub fn nanosleep(req: &TimeSpec, rem_opt: Option<&mut TimeSpec>) -> Result<usize
//start is a tuple of (seconds, nanoseconds) //start is a tuple of (seconds, nanoseconds)
let start = time::monotonic(); let start = time::monotonic();
let sum = start.1 + req.tv_nsec as u64; 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(); let contexts = context::contexts();
...@@ -35,9 +35,20 @@ pub fn nanosleep(req: &TimeSpec, rem_opt: Option<&mut TimeSpec>) -> Result<usize ...@@ -35,9 +35,20 @@ pub fn nanosleep(req: &TimeSpec, rem_opt: Option<&mut TimeSpec>) -> Result<usize
unsafe { context::switch(); } unsafe { context::switch(); }
if let Some(rem) = rem_opt { if let Some(rem) = rem_opt {
//TODO let current = time::monotonic(); let current = time::monotonic();
rem.tv_sec = 0;
rem.tv_nsec = 0; 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) Ok(0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment