1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-08 14:22:09 +03:00

feat(RM,allocators): use atomic counters math abstraction

This commit is contained in:
drrtuy
2025-03-17 14:32:50 +00:00
parent b14613a66b
commit 729db829a2
4 changed files with 25 additions and 13 deletions

View File

@@ -22,6 +22,7 @@
#include <atomic>
#include <cstddef>
#include <cstdlib>
#include "atomicops.h"
namespace allocators
{
@@ -74,10 +75,10 @@ class CountingAllocator
assert(lastMemoryLimitCheckpointDiff > 0);
auto currentGlobalMemoryLimit =
memoryLimit_->fetch_sub(lastMemoryLimitCheckpointDiff, std::memory_order_relaxed);
atomicops::atomicSubRef(*memoryLimit_, lastMemoryLimitCheckpointDiff);
if (currentGlobalMemoryLimit < memoryLimitLowerBound_)
{
memoryLimit_->fetch_add(lastMemoryLimitCheckpointDiff, std::memory_order_relaxed);
atomicops::atomicAddRef(*memoryLimit_, lastMemoryLimitCheckpointDiff);
throw std::bad_alloc();
}
lastMemoryLimitCheckpoint_ += lastMemoryLimitCheckpointDiff;
@@ -147,7 +148,7 @@ class CountingAllocator
: diffSinceLastCheckPoint + sizeToDeallocate;
assert(lastMemoryLimitCheckpointDiff > 0);
memoryLimit_->fetch_add(lastMemoryLimitCheckpointDiff, std::memory_order_relaxed);
atomicops::atomicAddRef(*memoryLimit_, lastMemoryLimitCheckpointDiff);
lastMemoryLimitCheckpoint_ -= (lastMemoryLimitCheckpoint_ == 0) ? 0 : lastMemoryLimitCheckpointDiff;
}