Add accessors for when you're sure a linked list is not empty
All checks were successful
continuous-integration/drone/pr Build is passing

This commit is contained in:
apio 2022-12-07 15:21:50 +01:00
parent 6cd25fb9b1
commit 71d2b492ea
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 13 additions and 3 deletions

View File

@ -178,7 +178,7 @@ Result<void*> kmalloc(usize size)
heap.append(block); heap.append(block);
} }
HeapBlock* block = heap.first().value(); HeapBlock* block = heap.expect_first();
while (block) while (block)
{ {
// Trying to find a free block... // Trying to find a free block...
@ -330,7 +330,7 @@ void dump_heap_usage()
} }
usize alloc_total = 0; usize alloc_total = 0;
usize alloc_used = 0; usize alloc_used = 0;
HeapBlock* block = heap.first().value(); HeapBlock* block = heap.expect_first();
while (block) while (block)
{ {
if (is_block_free(block)) if (is_block_free(block))

View File

@ -98,7 +98,7 @@ namespace Scheduler
do { do {
auto maybe_next = g_threads.next(g_current); auto maybe_next = g_threads.next(g_current);
if (maybe_next.has_error()) g_current = g_threads.first().value(); if (maybe_next.has_error()) g_current = g_threads.expect_first();
else else
g_current = maybe_next.value(); g_current = maybe_next.value();

View File

@ -106,11 +106,21 @@ template <typename T> class DoublyLinkedList
return nonnull_or_error((T*)m_start_node); return nonnull_or_error((T*)m_start_node);
} }
T* expect_first()
{
return first().value();
}
Result<T*> last() Result<T*> last()
{ {
return nonnull_or_error((T*)m_end_node); return nonnull_or_error((T*)m_end_node);
} }
T* expect_last()
{
return last().value();
}
Result<T*> next(T* item) Result<T*> next(T* item)
{ {
return nonnull_or_error((T*)extract_node(item)->get_next()); return nonnull_or_error((T*)extract_node(item)->get_next());