From dcd83b71c833e86c7e00e2b8f75ab6208b5d360d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 2 Dec 2024 13:51:58 +0000 Subject: WIP thread safe linked list --- arch/x86_64/src/memory/heap/linked_list_allocator.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'arch/x86_64/src') 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 f596f27..22b5757 100644 --- a/arch/x86_64/src/memory/heap/linked_list_allocator.cpp +++ b/arch/x86_64/src/memory/heap/linked_list_allocator.cpp @@ -28,7 +28,7 @@ namespace teachos::arch::memory::heap "[Linked List Allocator] Allocated memory cannot be smaller than 16 bytes"); memory_block * previous = nullptr; - auto current = first; + auto current = first.load(std::memory_order::relaxed); while (current != nullptr) { @@ -52,7 +52,7 @@ namespace teachos::arch::memory::heap auto const end_address = start_address + size; memory_block * previous = nullptr; - auto current = first; + auto current = first.load(std::memory_order::relaxed); while (current != nullptr) { @@ -81,11 +81,11 @@ namespace teachos::arch::memory::heap // free block (nullptr). Therefore we have to overwrite the first block instead of overwriting its next value. if (previous_block == nullptr) { - first = new_block; + first.compare_exchange_weak(previous_block, new_block, std::memory_order::relaxed); } else { - previous_block->next = new_block; + previous_block->next.compare_exchange_weak(current_block, new_block, std::memory_order::relaxed); } clear_memory_block_header(current_block); return reinterpret_cast(start_address); -- cgit v1.2.3