time unmodified
This commit is contained in:
parent
cc1a9a4751
commit
58fa67414e
7 changed files with 89 additions and 12 deletions
|
@ -20,6 +20,19 @@ fn main() -> i32 {
|
|||
panic!("Cannot find main!");
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct TimeVal {
|
||||
pub sec: usize,
|
||||
pub usec: usize,
|
||||
}
|
||||
|
||||
impl TimeVal {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
use syscall::*;
|
||||
|
||||
pub fn write(fd: usize, buf: &[u8]) -> isize {
|
||||
|
@ -32,7 +45,11 @@ pub fn yield_() -> isize {
|
|||
sys_yield()
|
||||
}
|
||||
pub fn get_time() -> isize {
|
||||
sys_get_time()
|
||||
let time = TimeVal::new();
|
||||
match sys_get_time(&time, 0) {
|
||||
0 => ((time.sec & 0xffff) * 1000 + time.usec / 1000) as isize,
|
||||
_ => -1,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sbrk(size: i32) -> isize {
|
||||
|
@ -46,3 +63,10 @@ pub fn munmap(start: usize, len: usize) -> isize {
|
|||
pub fn mmap(start: usize, len: usize, prot: usize) -> isize {
|
||||
sys_mmap(start, len, prot)
|
||||
}
|
||||
|
||||
pub fn sleep(period_ms: usize) {
|
||||
let start = get_time();
|
||||
while get_time() < start + period_ms as isize {
|
||||
sys_yield();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue