diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-12-03 08:41:59 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-12-03 08:41:59 +0000 |
| commit | 23526b8d10cf41ad5598928bf2bf3264539d497f (patch) | |
| tree | d0f294ee83b39b946027a4850e1c98d61f4d26b2 /arch/x86_64/src/memory | |
| parent | e6da0a1b12a3e777bd54e4b22b6a873a4c5fe195 (diff) | |
| download | teachos-23526b8d10cf41ad5598928bf2bf3264539d497f.tar.xz teachos-23526b8d10cf41ad5598928bf2bf3264539d497f.zip | |
Add missing comments
Diffstat (limited to 'arch/x86_64/src/memory')
| -rw-r--r-- | arch/x86_64/src/memory/heap/linked_list_allocator.cpp | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/arch/x86_64/src/memory/heap/linked_list_allocator.cpp b/arch/x86_64/src/memory/heap/linked_list_allocator.cpp index d922dc8..6600c6e 100644 --- a/arch/x86_64/src/memory/heap/linked_list_allocator.cpp +++ b/arch/x86_64/src/memory/heap/linked_list_allocator.cpp @@ -36,7 +36,7 @@ namespace teachos::arch::memory::heap { if (current->size == size) { - return remove_free_memory_block(previous, current, size); + return remove_free_memory_block(previous, current); } else if (current->size >= size + min_allocatable_size()) { @@ -81,31 +81,25 @@ namespace teachos::arch::memory::heap mutex.unlock(); } - auto linked_list_allocator::remove_free_memory_block(memory_block * previous_block, memory_block * current_block, - std::size_t size) -> void * + auto linked_list_allocator::remove_free_memory_block(memory_block * previous_block, + memory_block * current_block) -> void * { - auto const start_address = reinterpret_cast<std::size_t>(current_block); - // If we want to allocate into the first block that is before any other free block, then there exists no previous - // free block (nullptr). Therefore we have to overwrite the first block instead of overwriting its next value. - if (previous_block == nullptr) - { - first = nullptr; - } - else - { - previous_block->next = current_block->next; - } - clear_memory_block_header(current_block); - return reinterpret_cast<void *>(start_address); + return replace_free_memory_block(previous_block, current_block, current_block->next); } auto linked_list_allocator::split_free_memory_block(memory_block * previous_block, memory_block * current_block, std::size_t size) -> void * { - auto const start_address = reinterpret_cast<std::size_t>(current_block); - auto const end_address = start_address + size; + auto const end_address = reinterpret_cast<std::size_t>(current_block) + size; auto const new_block = new (reinterpret_cast<void *>(end_address)) memory_block(current_block->size - size, current_block->next); + return replace_free_memory_block(previous_block, current_block, new_block); + } + + auto linked_list_allocator::replace_free_memory_block(memory_block * previous_block, memory_block * current_block, + memory_block * new_block) -> void * + { + auto const start_address = reinterpret_cast<std::size_t>(current_block); // If we want to allocate into the first block that is before any other free block, then there exists no previous // free block (nullptr). Therefore we have to overwrite the first block instead of overwriting its next value. if (previous_block == nullptr) |
