Compare commits
No commits in common. "ed34009b50d733380d6d7deb5c4bb4e89e243802" and "a1eca479d551482a630a64efae19f12198fb1a3a" have entirely different histories.
ed34009b50
...
a1eca479d5
@ -125,14 +125,8 @@ static Option<HeapBlock*> split(HeapBlock* block, usize size)
|
||||
|
||||
static Result<void> combine_forward(HeapBlock* block)
|
||||
{
|
||||
// This block ends a memory range, cannot be combined with blocks outside its range.
|
||||
if (block->status & BLOCK_END_MEM) return {};
|
||||
|
||||
// The caller needs to ensure there is a next block.
|
||||
HeapBlock* const next = heap.next(block).value();
|
||||
// This block starts a memory range, cannot be combined with blocks outside its range.
|
||||
if (next->status & BLOCK_START_MEM) return {};
|
||||
|
||||
heap.remove(next);
|
||||
next->magic = BLOCK_DEAD;
|
||||
|
||||
@ -140,8 +134,7 @@ static Result<void> combine_forward(HeapBlock* block)
|
||||
{
|
||||
if (next->status & BLOCK_START_MEM)
|
||||
{
|
||||
const usize pages = get_blocks_from_size(next->full_size + sizeof(HeapBlock), ARCH_PAGE_SIZE);
|
||||
TRY(release_pages(next, pages));
|
||||
TRY(release_pages(next, get_blocks_from_size(next->full_size + sizeof(HeapBlock), ARCH_PAGE_SIZE)));
|
||||
return {};
|
||||
}
|
||||
else
|
||||
@ -155,13 +148,8 @@ static Result<void> combine_forward(HeapBlock* block)
|
||||
|
||||
static Result<HeapBlock*> combine_backward(HeapBlock* block)
|
||||
{
|
||||
// This block starts a memory range, cannot be combined with blocks outside its range.
|
||||
if (block->status & BLOCK_START_MEM) return block;
|
||||
|
||||
// The caller needs to ensure there is a last block.
|
||||
HeapBlock* const last = heap.previous(block).value();
|
||||
// This block ends a memory range, cannot be combined with blocks outside its range.
|
||||
if (last->status & BLOCK_END_MEM) return block;
|
||||
heap.remove(block);
|
||||
block->magic = BLOCK_DEAD;
|
||||
|
||||
@ -169,8 +157,7 @@ static Result<HeapBlock*> combine_backward(HeapBlock* block)
|
||||
{
|
||||
if (block->status & BLOCK_START_MEM)
|
||||
{
|
||||
const usize pages = get_blocks_from_size(block->full_size + sizeof(HeapBlock), ARCH_PAGE_SIZE);
|
||||
TRY(release_pages(block, pages));
|
||||
TRY(release_pages(block, get_blocks_from_size(block->full_size + sizeof(HeapBlock), ARCH_PAGE_SIZE)));
|
||||
return last;
|
||||
}
|
||||
else
|
||||
@ -286,8 +273,7 @@ Result<void> kfree(void* ptr)
|
||||
if ((block->status & BLOCK_START_MEM) && (block->status & BLOCK_END_MEM))
|
||||
{
|
||||
heap.remove(block);
|
||||
const usize pages = get_blocks_from_size(block->full_size + sizeof(HeapBlock), ARCH_PAGE_SIZE);
|
||||
TRY(release_pages(block, pages));
|
||||
TRY(release_pages(block, get_blocks_from_size(block->full_size + sizeof(HeapBlock), ARCH_PAGE_SIZE)));
|
||||
}
|
||||
|
||||
return {};
|
||||
@ -366,15 +352,12 @@ void dump_heap_usage()
|
||||
{
|
||||
if (is_block_free(block))
|
||||
{
|
||||
kdbgln("- Available block (%p), of size %zu (%s%s)", (void*)block, block->full_size,
|
||||
block->status & BLOCK_START_MEM ? "b" : "-", block->status & BLOCK_END_MEM ? "e" : "-");
|
||||
kdbgln("- Available block, of size %zu", block->full_size);
|
||||
alloc_total += block->full_size + sizeof(HeapBlock);
|
||||
}
|
||||
else
|
||||
{
|
||||
kdbgln("- Used block (%p), of size %zu, of which %zu bytes are being used (%s%s)", (void*)block,
|
||||
block->full_size, block->req_size, block->status & BLOCK_START_MEM ? "b" : "-",
|
||||
block->status & BLOCK_END_MEM ? "e" : "-");
|
||||
kdbgln("- Used block, of size %zu, of which %zu bytes are being used", block->full_size, block->req_size);
|
||||
alloc_total += block->full_size + sizeof(HeapBlock);
|
||||
alloc_used += block->req_size;
|
||||
}
|
||||
|
@ -49,14 +49,12 @@ template <typename T> class LinkedListNode
|
||||
{
|
||||
end_node->m_next_node = this;
|
||||
this->m_last_node = end_node;
|
||||
this->m_next_node = nullptr;
|
||||
}
|
||||
|
||||
void prepend_to_list(SelfType* start_node)
|
||||
{
|
||||
start_node->m_last_node = this;
|
||||
this->m_next_node = start_node;
|
||||
this->m_last_node = nullptr;
|
||||
}
|
||||
|
||||
friend class LinkedList<T>;
|
||||
@ -106,8 +104,6 @@ template <typename T> class LinkedList
|
||||
|
||||
if (m_end_node == base_node) m_end_node = new_node;
|
||||
|
||||
if (base_node->get_next()) base_node->get_next()->set_last(new_node);
|
||||
|
||||
new_node->set_next(base_node->get_next());
|
||||
base_node->set_next(new_node);
|
||||
new_node->set_last(base_node);
|
||||
|
Loading…
Reference in New Issue
Block a user