DoublyLinkedList -> LinkedList
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2022-12-19 12:43:23 +01:00
parent 1269a045bd
commit a11a5dec1f
Signed by: apio
GPG Key ID: B8A7D06E42258954
6 changed files with 21 additions and 21 deletions

View File

@ -26,7 +26,7 @@ static constexpr usize BLOCK_DEAD = 0xdeaddeaddeaddead;
static constexpr usize MINIMUM_PAGES_PER_ALLOCATION = 4; static constexpr usize MINIMUM_PAGES_PER_ALLOCATION = 4;
struct HeapBlock : DoublyLinkedListNode<HeapBlock> struct HeapBlock : LinkedListNode<HeapBlock>
{ {
usize req_size; usize req_size;
usize full_size; usize full_size;
@ -38,7 +38,7 @@ static_assert(sizeof(HeapBlock) == 48UL);
static const isize HEAP_BLOCK_SIZE = 48; static const isize HEAP_BLOCK_SIZE = 48;
static DoublyLinkedList<HeapBlock> heap; static LinkedList<HeapBlock> heap;
static Result<HeapBlock*> allocate_pages(usize count) static Result<HeapBlock*> allocate_pages(usize count)
{ {

View File

@ -178,9 +178,9 @@ namespace Scheduler
if (!g_current->ticks_left) switch_task(regs); if (!g_current->ticks_left) switch_task(regs);
} }
DoublyLinkedList<Thread> check_for_dying_threads() LinkedList<Thread> check_for_dying_threads()
{ {
DoublyLinkedList<Thread> result; LinkedList<Thread> result;
g_threads.delayed_for_each([&](Thread* thread) { g_threads.delayed_for_each([&](Thread* thread) {
if (thread->state == ThreadState::Dying) if (thread->state == ThreadState::Dying)

View File

@ -20,7 +20,7 @@ namespace Scheduler
void invoke(Registers* regs); void invoke(Registers* regs);
DoublyLinkedList<Thread> check_for_dying_threads(); LinkedList<Thread> check_for_dying_threads();
} }
extern "C" void kernel_yield(); extern "C" void kernel_yield();

View File

@ -4,7 +4,7 @@
static Atomic<u64> g_next_id; static Atomic<u64> g_next_id;
DoublyLinkedList<Thread> g_threads; LinkedList<Thread> g_threads;
void Thread::init() void Thread::init()
{ {

View File

@ -18,7 +18,7 @@ enum class ThreadState
Dying Dying
}; };
struct Thread : public DoublyLinkedListNode<Thread> struct Thread : public LinkedListNode<Thread>
{ {
Registers regs; Registers regs;
@ -60,4 +60,4 @@ bool is_in_kernel(Registers* regs);
Result<Thread*> new_thread(); Result<Thread*> new_thread();
extern DoublyLinkedList<Thread> g_threads; extern LinkedList<Thread> g_threads;

View File

@ -9,11 +9,11 @@ template <typename T> inline Option<T*> nonnull_or_error(T* ptr)
return ptr; return ptr;
} }
template <typename T> class DoublyLinkedList; template <typename T> class LinkedList;
template <typename T> class DoublyLinkedListNode template <typename T> class LinkedListNode
{ {
using SelfType = DoublyLinkedListNode<T>; using SelfType = LinkedListNode<T>;
private: private:
SelfType* m_next_node; SelfType* m_next_node;
@ -57,14 +57,14 @@ template <typename T> class DoublyLinkedListNode
this->m_next_node = start_node; this->m_next_node = start_node;
} }
friend class DoublyLinkedList<T>; friend class LinkedList<T>;
}; };
template <typename T> class DoublyLinkedList template <typename T> class LinkedList
{ {
using Node = DoublyLinkedListNode<T>; using Node = LinkedListNode<T>;
static_assert(IsBaseOf<DoublyLinkedListNode<T>, T>); static_assert(IsBaseOf<LinkedListNode<T>, T>);
public: public:
void append(T* ptr) void append(T* ptr)
@ -155,13 +155,13 @@ template <typename T> class DoublyLinkedList
return nonnull_or_error((T*)extract_node(item)->get_last()); return nonnull_or_error((T*)extract_node(item)->get_last());
} }
// Iterates over the elements of the DoublyLinkedList from start to end, calling callback for every element. // Iterates over the elements of the LinkedList from start to end, calling callback for every element.
template <typename Callback> void for_each(Callback callback) template <typename Callback> void for_each(Callback callback)
{ {
for (Node* node = m_start_node; node; node = node->get_next()) { callback((T*)node); } for (Node* node = m_start_node; node; node = node->get_next()) { callback((T*)node); }
} }
// Iterates over the elements of the DoublyLinkedList from start to end, calling callback for every element. This // Iterates over the elements of the LinkedList from start to end, calling callback for every element. This
// for_each is implemented in such a way that elements can be removed while iterating over it. // for_each is implemented in such a way that elements can be removed while iterating over it.
template <typename Callback> void delayed_for_each(Callback callback) template <typename Callback> void delayed_for_each(Callback callback)
{ {
@ -173,27 +173,27 @@ template <typename T> class DoublyLinkedList
} }
} }
// Iterates over the elements of the DoublyLinkedList from end to start, calling callback for every element. // Iterates over the elements of the LinkedList from end to start, calling callback for every element.
template <typename Callback> void for_each_reversed(Callback callback) template <typename Callback> void for_each_reversed(Callback callback)
{ {
for (Node* node = m_end_node; node; node = node->get_last()) { callback((T*)node); } for (Node* node = m_end_node; node; node = node->get_last()) { callback((T*)node); }
} }
// Iterates over the elements of the DoublyLinkedList from the element after 'start' to end, calling callback for // Iterates over the elements of the LinkedList from the element after 'start' to end, calling callback for
// every element. // every element.
template <typename Callback> void for_each_after(T* start, Callback callback) template <typename Callback> void for_each_after(T* start, Callback callback)
{ {
for (Node* node = extract_node(start)->m_next_node; node; node = node->get_next()) { callback((T*)node); } for (Node* node = extract_node(start)->m_next_node; node; node = node->get_next()) { callback((T*)node); }
} }
// Iterates over the elements of the DoublyLinkedList from the element before 'end' to start, calling callback for // Iterates over the elements of the LinkedList from the element before 'end' to start, calling callback for
// every element. // every element.
template <typename Callback> void for_each_before(T* end, Callback callback) template <typename Callback> void for_each_before(T* end, Callback callback)
{ {
for (Node* node = extract_node(end)->m_last_node; node; node = node->get_last()) { callback((T*)node); } for (Node* node = extract_node(end)->m_last_node; node; node = node->get_last()) { callback((T*)node); }
} }
// Iterates over the elements of the DoublyLinkedList from start to end, removing each element before passing it to // Iterates over the elements of the LinkedList from start to end, removing each element before passing it to
// the callback. // the callback.
template <typename Callback> void consume(Callback callback) template <typename Callback> void consume(Callback callback)
{ {