diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-20 00:41:51 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-20 09:09:10 +0200 |
commit | 7557f2db905eaf768b54be854d9bf1ce32f0973d (patch) | |
tree | 982055db53f01219b0560f5fe2a4aa7f7a915258 /Kernel/TimerQueue.h | |
parent | 96b75af5d13a177fd259c4099e06690b6c478e5d (diff) | |
download | serenity-7557f2db905eaf768b54be854d9bf1ce32f0973d.zip |
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.
Diffstat (limited to 'Kernel/TimerQueue.h')
-rw-r--r-- | Kernel/TimerQueue.h | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/Kernel/TimerQueue.h b/Kernel/TimerQueue.h index c84f981786..ca0cfaea58 100644 --- a/Kernel/TimerQueue.h +++ b/Kernel/TimerQueue.h @@ -24,12 +24,14 @@ class Timer : public RefCounted<Timer> friend class InlineLinkedListNode<Timer>; public: - Timer(clockid_t clock_id, Time expires, Function<void()>&& callback) - : m_clock_id(clock_id) - , m_expires(expires) - , m_callback(move(callback)) + void setup(clockid_t clock_id, Time expires, Function<void()>&& callback) { + VERIFY(!is_queued()); + m_clock_id = clock_id; + m_expires = expires; + m_callback = move(callback); } + ~Timer() { VERIFY(!is_queued()); @@ -72,7 +74,7 @@ public: static TimerQueue& the(); TimerId add_timer(NonnullRefPtr<Timer>&&); - RefPtr<Timer> add_timer_without_id(clockid_t, const Time&, Function<void()>&&); + bool add_timer_without_id(NonnullRefPtr<Timer>, clockid_t, const Time&, Function<void()>&&); TimerId add_timer(clockid_t, const Time& timeout, Function<void()>&& callback); bool cancel_timer(TimerId id); bool cancel_timer(Timer&); |