mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 12:27:35 +00:00
Kernel: Replace TimerQueue InlinedLinkedList usage with IntrusiveList
Note that there are a few minor differences between the InlineLinekdList and IntrusiveList API, so this isn't just a pure data structure change. - first()/last() instead of head()/tail() - There is no need for a for_each(..) implementation, as it already exposes the ability to do range based for loops.
This commit is contained in:
parent
b4aaa99968
commit
2b819ff181
2 changed files with 59 additions and 54 deletions
|
@ -7,7 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <AK/InlineLinkedList.h>
|
||||
#include <AK/IntrusiveList.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/RefCounted.h>
|
||||
|
@ -18,10 +18,8 @@ namespace Kernel {
|
|||
|
||||
TYPEDEF_DISTINCT_ORDERED_ID(u64, TimerId);
|
||||
|
||||
class Timer : public RefCounted<Timer>
|
||||
, public InlineLinkedListNode<Timer> {
|
||||
class Timer : public RefCounted<Timer> {
|
||||
friend class TimerQueue;
|
||||
friend class InlineLinkedListNode<Timer>;
|
||||
|
||||
public:
|
||||
void setup(clockid_t clock_id, Time expires, Function<void()>&& callback)
|
||||
|
@ -45,8 +43,6 @@ private:
|
|||
Time m_expires;
|
||||
Time m_remaining {};
|
||||
Function<void()> m_callback;
|
||||
Timer* m_next { nullptr };
|
||||
Timer* m_prev { nullptr };
|
||||
Atomic<bool, AK::MemoryOrder::memory_order_relaxed> m_queued { false };
|
||||
|
||||
bool operator<(const Timer& rhs) const
|
||||
|
@ -64,6 +60,10 @@ private:
|
|||
bool is_queued() const { return m_queued; }
|
||||
void set_queued(bool queued) { m_queued = queued; }
|
||||
Time now(bool) const;
|
||||
|
||||
public:
|
||||
IntrusiveListNode<Timer> m_list_node;
|
||||
using List = IntrusiveList<Timer, RawPtr<Timer>, &Timer::m_list_node>;
|
||||
};
|
||||
|
||||
class TimerQueue {
|
||||
|
@ -86,7 +86,7 @@ public:
|
|||
|
||||
private:
|
||||
struct Queue {
|
||||
InlineLinkedList<Timer> list;
|
||||
Timer::List list;
|
||||
Time next_timer_due {};
|
||||
};
|
||||
void remove_timer_locked(Queue&, Timer&);
|
||||
|
@ -112,7 +112,7 @@ private:
|
|||
u64 m_ticks_per_second { 0 };
|
||||
Queue m_timer_queue_monotonic;
|
||||
Queue m_timer_queue_realtime;
|
||||
InlineLinkedList<Timer> m_timers_executing;
|
||||
Timer::List m_timers_executing;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue