mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:17:44 +00:00
AK: Introduce MonotonicTime
This class takes on the duties of CLOCK_MONOTONIC, a time without a defined reference point that always increases. This informs some important design decisions about the class API: MonotonicTime cannot be constructed from external time data, except as a computation based on other monotonic time, or the current monotonic time. Importantly, there is no default constructor, since the reference point of monotonic time is unspecified and therefore without meaning as a default. The current use of monotonic time (via Duration) includes some potential problems that may be caught when we move most to all code to MonotonicTime in the next commit. The API restrictions have one important relaxation: Kernel::TimeManagement is allowed to exchange raw time data within MonotonicTime freely. This is required for the clock-agnostic time accessors for timeouts and syscalls, as well as creating monotonic time data from hardware in the first place.
This commit is contained in:
parent
69e27169c4
commit
b2e7b8cdff
2 changed files with 79 additions and 0 deletions
10
AK/Time.cpp
10
AK/Time.cpp
|
@ -227,6 +227,16 @@ Duration Duration::now_monotonic_coarse()
|
|||
return now_time_from_clock(CLOCK_MONOTONIC_COARSE);
|
||||
}
|
||||
|
||||
MonotonicTime MonotonicTime::now()
|
||||
{
|
||||
return MonotonicTime { now_time_from_clock(CLOCK_MONOTONIC) };
|
||||
}
|
||||
|
||||
MonotonicTime MonotonicTime::now_coarse()
|
||||
{
|
||||
return MonotonicTime { now_time_from_clock(CLOCK_MONOTONIC_COARSE) };
|
||||
}
|
||||
|
||||
UnixDateTime UnixDateTime::now()
|
||||
{
|
||||
return UnixDateTime { now_time_from_clock(CLOCK_REALTIME) };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue