mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 17:33:23 +00:00
29 lines
762 B
Rust
29 lines
762 B
Rust
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
use core::time::Duration;
|
|
|
|
use super::SyscallReturn;
|
|
use crate::{prelude::*, process::posix_thread::PosixThreadExt};
|
|
|
|
pub fn sys_alarm(seconds: u32) -> Result<SyscallReturn> {
|
|
debug!("seconds = {}", seconds);
|
|
|
|
let current_thread = current_thread!();
|
|
let mut real_timer = {
|
|
let posix_thread = current_thread.as_posix_thread().unwrap();
|
|
posix_thread.real_timer().lock()
|
|
};
|
|
|
|
let remaining_secs = real_timer.remain().as_secs();
|
|
|
|
if seconds == 0 {
|
|
// Clear previous timer
|
|
real_timer.clear();
|
|
return Ok(SyscallReturn::Return(remaining_secs as _));
|
|
}
|
|
|
|
real_timer.set(Duration::from_secs(seconds as u64))?;
|
|
|
|
Ok(SyscallReturn::Return(remaining_secs as _))
|
|
}
|