1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:57:35 +00:00

Kernel: Add CLOCK_REALTIME support to the TimerQueue

This allows us to use blocking timeouts with either monotonic or
real time for all blockers. Which means that clock_nanosleep()
now also supports CLOCK_REALTIME.

Also, switch alarm() to use CLOCK_REALTIME as per specification.
This commit is contained in:
Tom 2020-12-01 16:53:47 -07:00 committed by Andreas Kling
parent 4c1e27ec65
commit 12cf6f8650
9 changed files with 182 additions and 97 deletions

View file

@ -52,6 +52,18 @@ TimeManagement& TimeManagement::the()
return *s_the;
}
KResultOr<timespec> TimeManagement::current_time(clockid_t clock_id) const
{
switch (clock_id) {
case CLOCK_MONOTONIC:
return monotonic_time();
case CLOCK_REALTIME:
return epoch_time();
default:
return KResult(EINVAL);
}
}
bool TimeManagement::is_system_timer(const HardwareTimerBase& timer) const
{
return &timer == m_system_timer.ptr();

View file

@ -29,6 +29,7 @@
#include <AK/NonnullRefPtrVector.h>
#include <AK/RefPtr.h>
#include <AK/Types.h>
#include <Kernel/KResult.h>
#include <Kernel/UnixTypes.h>
namespace Kernel {
@ -49,6 +50,7 @@ public:
static timespec ticks_to_time(u64 ticks, time_t ticks_per_second);
static u64 time_to_ticks(const timespec& tspec, time_t ticks_per_second);
KResultOr<timespec> current_time(clockid_t clock_id) const;
timespec monotonic_time() const;
timespec epoch_time() const;
void set_epoch_time(timespec);