31 lines
795 B
Rust
31 lines
795 B
Rust
//! Waits: `sleep <seconds>`. Mostly something to stop with Ctrl+C.
|
|
|
|
#![no_std]
|
|
#![forbid(unsafe_code)]
|
|
#![no_main]
|
|
|
|
extern crate libkos;
|
|
|
|
use libkos::{println, syscall};
|
|
use types::time::Ticks;
|
|
|
|
/// QEMU virt's timebase.
|
|
const TICKS_PER_SECOND: u64 = 10_000_000;
|
|
|
|
libkos::entry!(main);
|
|
|
|
fn main() {
|
|
let Some(seconds) = libkos::start::args().nth(1).and_then(|s| s.parse::<u64>().ok()) else {
|
|
println!("usage: sleep <seconds>");
|
|
return;
|
|
};
|
|
let Ok(alarm) = syscall::create_notification() else {
|
|
println!("sleep: no notification");
|
|
return;
|
|
};
|
|
let at = syscall::get_time().raw().saturating_add(seconds.saturating_mul(TICKS_PER_SECOND));
|
|
if syscall::set_timer(alarm, Ticks::from_raw(at)).is_ok() {
|
|
let _ = syscall::wait(alarm);
|
|
}
|
|
}
|