Add accessors for when you're sure a linked list is not empty

This commit is contained in:
apio 2022-12-07 15:21:50 +01:00 committed by Gitea
parent 70497c37fb
commit 757cee4693
3 changed files with 13 additions and 3 deletions

View File

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

View File

@ -98,7 +98,7 @@ namespace Scheduler
do {
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
g_current = maybe_next.value();

View File

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