Implement sleep using blocking & BinaryHeap.

This commit is contained in:
Yifan Wu 2021-10-08 12:55:39 -07:00
parent db6a93e60d
commit c951c1781e
6 changed files with 79 additions and 7 deletions

View file

@ -100,11 +100,8 @@ pub fn waitpid(pid: usize, exit_code: &mut i32) -> isize {
}
}
}
pub fn sleep(period_ms: usize) {
let start = sys_get_time();
while sys_get_time() < start + period_ms as isize {
sys_yield();
}
pub fn sleep(sleep_ms: usize) {
sys_sleep(sleep_ms);
}
pub fn thread_create(entry: usize) -> isize { sys_thread_create(entry) }

View file

@ -5,6 +5,7 @@ const SYSCALL_PIPE: usize = 59;
const SYSCALL_READ: usize = 63;
const SYSCALL_WRITE: usize = 64;
const SYSCALL_EXIT: usize = 93;
const SYSCALL_SLEEP: usize = 101;
const SYSCALL_YIELD: usize = 124;
const SYSCALL_GET_TIME: usize = 169;
const SYSCALL_GETPID: usize = 172;
@ -61,6 +62,10 @@ pub fn sys_exit(exit_code: i32) -> ! {
panic!("sys_exit never returns!");
}
pub fn sys_sleep(sleep_ms: usize) -> isize {
syscall(SYSCALL_SLEEP, [sleep_ms, 0, 0])
}
pub fn sys_yield() -> isize {
syscall(SYSCALL_YIELD, [0, 0, 0])
}