mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 10:01:13 +09:00
Kernel: Remove an allocation when blocking a thread
When blocking a thread with a timeout we would previously allocate a Timer object. This removes the allocation for that Timer object.
This commit is contained in:
parent
96b75af5d1
commit
7557f2db90
Notes:
sideshowbarker
2024-07-18 17:43:28 +09:00
Author: https://github.com/gunnarbeutner
Commit: 7557f2db90
Pull-request: https://github.com/SerenityOS/serenity/pull/7301
Reviewed-by: https://github.com/bgianfo ✅
5 changed files with 42 additions and 23 deletions
|
@ -57,22 +57,22 @@ UNMAP_AFTER_INIT TimerQueue::TimerQueue()
|
|||
m_ticks_per_second = TimeManagement::the().ticks_per_second();
|
||||
}
|
||||
|
||||
RefPtr<Timer> TimerQueue::add_timer_without_id(clockid_t clock_id, const Time& deadline, Function<void()>&& callback)
|
||||
bool TimerQueue::add_timer_without_id(NonnullRefPtr<Timer> timer, clockid_t clock_id, const Time& deadline, Function<void()>&& callback)
|
||||
{
|
||||
if (deadline <= TimeManagement::the().current_time(clock_id))
|
||||
return {};
|
||||
return false;
|
||||
|
||||
// Because timer handlers can execute on any processor and there is
|
||||
// a race between executing a timer handler and cancel_timer() this
|
||||
// *must* be a RefPtr<Timer>. Otherwise calling cancel_timer() could
|
||||
// inadvertently cancel another timer that has been created between
|
||||
// returning from the timer handler and a call to cancel_timer().
|
||||
auto timer = adopt_ref(*new Timer(clock_id, deadline, move(callback)));
|
||||
timer->setup(clock_id, deadline, move(callback));
|
||||
|
||||
ScopedSpinLock lock(g_timerqueue_lock);
|
||||
timer->m_id = 0; // Don't generate a timer id
|
||||
add_timer_locked(timer);
|
||||
return timer;
|
||||
add_timer_locked(move(timer));
|
||||
return true;
|
||||
}
|
||||
|
||||
TimerId TimerQueue::add_timer(NonnullRefPtr<Timer>&& timer)
|
||||
|
@ -119,7 +119,10 @@ TimerId TimerQueue::add_timer(clockid_t clock_id, const Time& deadline, Function
|
|||
{
|
||||
auto expires = TimeManagement::the().current_time(clock_id);
|
||||
expires = expires + deadline;
|
||||
return add_timer(adopt_ref(*new Timer(clock_id, expires, move(callback))));
|
||||
auto timer = new Timer();
|
||||
VERIFY(timer);
|
||||
timer->setup(clock_id, expires, move(callback));
|
||||
return add_timer(adopt_ref(*timer));
|
||||
}
|
||||
|
||||
bool TimerQueue::cancel_timer(TimerId id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue