mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-29 04:13:24 +00:00
Fix the logics for the coarse resolution clock id in VDSO.
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
ff3ff0a598
commit
c3d0c59041
@ -9,13 +9,17 @@ use crate::prelude::*;
|
||||
|
||||
mod system_time;
|
||||
|
||||
pub use system_time::SystemTime;
|
||||
pub use system_time::{SystemTime, START_TIME};
|
||||
|
||||
pub type clockid_t = i32;
|
||||
pub type time_t = i64;
|
||||
pub type suseconds_t = i64;
|
||||
pub type clock_t = i64;
|
||||
|
||||
pub(super) fn init() {
|
||||
system_time::init_start_time();
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, TryFromInt, PartialEq)]
|
||||
#[repr(i32)]
|
||||
pub enum ClockID {
|
||||
|
@ -3,6 +3,7 @@
|
||||
use core::time::Duration;
|
||||
|
||||
use aster_time::{read_monotonic_time, read_start_time};
|
||||
use spin::Once;
|
||||
use time::{Date, Month, PrimitiveDateTime, Time};
|
||||
|
||||
use crate::prelude::*;
|
||||
@ -11,6 +12,13 @@ use crate::prelude::*;
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct SystemTime(PrimitiveDateTime);
|
||||
|
||||
pub static START_TIME: Once<SystemTime> = Once::new();
|
||||
|
||||
pub(super) fn init_start_time() {
|
||||
let start_time = convert_system_time(read_start_time()).unwrap();
|
||||
START_TIME.call_once(|| start_time);
|
||||
}
|
||||
|
||||
impl SystemTime {
|
||||
/// The unix epoch, which represents 1970-01-01 00:00:00
|
||||
pub const UNIX_EPOCH: SystemTime = SystemTime::unix_epoch();
|
||||
@ -29,10 +37,8 @@ impl SystemTime {
|
||||
|
||||
/// Returns the current system time
|
||||
pub fn now() -> Self {
|
||||
let start = read_start_time();
|
||||
|
||||
// The get real time result should always be valid
|
||||
convert_system_time(start)
|
||||
START_TIME
|
||||
.get()
|
||||
.unwrap()
|
||||
.checked_add(read_monotonic_time())
|
||||
.unwrap()
|
||||
|
Reference in New Issue
Block a user