Implement sleep using blocking & BinaryHeap.
This commit is contained in:
parent
db6a93e60d
commit
c951c1781e
6 changed files with 79 additions and 7 deletions
|
@ -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) }
|
||||
|
|
|
@ -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])
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue