mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 10:18:15 +09:00
Kernel: Refactor TimeQueue::add_timer to use timeval
The current API of add_timer makes it hard to use as you are forced to do a bunch of time arithmetic at the caller. Ideally we would have overloads for common time types like timespec or timeval to keep the API as straight forward as possible. This change moves us in that direction. While I'm here, we should really also use the machines actual ticks per second, instead of the OPTIMAL_TICKS_PER_SECOND_RATE.
This commit is contained in:
parent
1a80aa999a
commit
1d68837456
Notes:
sideshowbarker
2024-07-19 07:16:00 +09:00
Author: https://github.com/bgianfo
Commit: 1d68837456
Pull-request: https://github.com/SerenityOS/serenity/pull/1964
Reviewed-by: https://github.com/awesomekling
2 changed files with 16 additions and 10 deletions
|
@ -28,6 +28,7 @@
|
|||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <Kernel/Scheduler.h>
|
||||
#include <Kernel/Time/TimeManagement.h>
|
||||
#include <Kernel/TimerQueue.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
@ -41,9 +42,14 @@ TimerQueue& TimerQueue::the()
|
|||
return *s_the;
|
||||
}
|
||||
|
||||
TimerQueue::TimerQueue()
|
||||
{
|
||||
m_ticks_per_second = TimeManagement::the().ticks_per_second();
|
||||
}
|
||||
|
||||
u64 TimerQueue::add_timer(NonnullOwnPtr<Timer>&& timer)
|
||||
{
|
||||
ASSERT(timer->expires > g_uptime);
|
||||
ASSERT(timer->expires >= g_uptime);
|
||||
|
||||
timer->id = ++m_timer_id_count;
|
||||
|
||||
|
@ -58,10 +64,10 @@ u64 TimerQueue::add_timer(NonnullOwnPtr<Timer>&& timer)
|
|||
return m_timer_id_count;
|
||||
}
|
||||
|
||||
u64 TimerQueue::add_timer(u64 duration, TimeUnit unit, Function<void()>&& callback)
|
||||
u64 TimerQueue::add_timer(timeval& deadline, Function<void()>&& callback)
|
||||
{
|
||||
NonnullOwnPtr timer = make<Timer>();
|
||||
timer->expires = g_uptime + duration * unit;
|
||||
timer->expires = g_uptime + seconds_to_ticks(deadline.tv_sec) + microseconds_to_ticks(deadline.tv_usec);
|
||||
timer->callback = move(callback);
|
||||
return add_timer(move(timer));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue