aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory/heap
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2024-11-26 11:09:59 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2024-11-26 11:09:59 +0000
commita4268440d5c77f39032bb9f003aafd7fef2ca997 (patch)
treec5c070f62cd9c05996e5c91dcf0faf5a5c38bdaa /arch/x86_64/src/memory/heap
parentd2aa4fbf948a56df5328e0f1b8ec3dfd52b16e13 (diff)
downloadteachos-a4268440d5c77f39032bb9f003aafd7fef2ca997.tar.xz
teachos-a4268440d5c77f39032bb9f003aafd7fef2ca997.zip
Replace strong with weak compare_exchange
Diffstat (limited to 'arch/x86_64/src/memory/heap')
-rw-r--r--arch/x86_64/src/memory/heap/bump_allocator.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/arch/x86_64/src/memory/heap/bump_allocator.cpp b/arch/x86_64/src/memory/heap/bump_allocator.cpp
index 19ced47..8807645 100644
--- a/arch/x86_64/src/memory/heap/bump_allocator.cpp
+++ b/arch/x86_64/src/memory/heap/bump_allocator.cpp
@@ -32,8 +32,9 @@ namespace teachos::arch::memory::heap
auto const alloc_end = saturating_add(alloc_start, size);
arch::exception_handling::assert(alloc_end <= heap_end, "[Heap Allocator] Out of memory");
// Check if the atomic value is still the one initally loaded, if it isn't we have been overtaken by another
- // thread and need to redo the calculation.
- auto const updated = next.compare_exchange_strong(alloc_start, alloc_end, std::memory_order::relaxed);
+ // thread and need to redo the calculation. Spurious failure by weak can be ignored, because the whole allocation
+ // is wrapped in an infinite for loop so a failure that wasn't actually one will simply be retried until it works.
+ auto const updated = next.compare_exchange_weak(alloc_start, alloc_end, std::memory_order::relaxed);
if (updated)
{
return reinterpret_cast<void *>(alloc_start);