Add accessors for when you're sure a linked list is not empty
This commit is contained in:
parent
70497c37fb
commit
757cee4693
@ -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))
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
@ -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());
|
||||||
|
Loading…
Reference in New Issue
Block a user