1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

chore(compilation): static analyser flag went mad.

This commit is contained in:
drrtuy
2025-03-26 07:05:43 +00:00
parent d1de121476
commit 3fd90d3270

View File

@ -102,6 +102,7 @@ class CountingAllocator
, memoryLimitLowerBound_(other.memoryLimitLowerBound_) , memoryLimitLowerBound_(other.memoryLimitLowerBound_)
, checkPointStepSize_(other.checkPointStepSize_) , checkPointStepSize_(other.checkPointStepSize_)
{ {
} }
// Allocate memory for n objects of type T // Allocate memory for n objects of type T
@ -131,15 +132,17 @@ class CountingAllocator
// Deallocate memory for n objects of type T // Deallocate memory for n objects of type T
void deallocate(T* ptr, std::size_t n) noexcept void deallocate(T* ptr, std::size_t n) noexcept
{ {
::operator delete(ptr); // Calculate all size-related values before deletion
int64_t sizeToDeallocate = n * sizeof(T); int64_t sizeToDeallocate = n * sizeof(T);
int64_t sizeChangeWDirection = int64_t sizeChangeWDirection =
(currentLocalMemoryUsage_ >= lastMemoryLimitCheckpoint_) ? -sizeToDeallocate : sizeToDeallocate; (currentLocalMemoryUsage_ >= lastMemoryLimitCheckpoint_) ? -sizeToDeallocate : sizeToDeallocate;
int64_t diffSinceLastCheckPoint = int_distance(currentLocalMemoryUsage_, lastMemoryLimitCheckpoint_); int64_t diffSinceLastCheckPoint = int_distance(currentLocalMemoryUsage_, lastMemoryLimitCheckpoint_);
bool needsCheckpoint = needCheckPoint(sizeChangeWDirection, diffSinceLastCheckPoint, checkPointStepSize_);
if (needCheckPoint(sizeChangeWDirection, diffSinceLastCheckPoint, checkPointStepSize_)) // Now safe to delete
::operator delete(ptr);
if (needsCheckpoint)
{ {
// Invariant is lastMemoryLimitCheckpoint_ >= currentLocalMemoryUsage_ - sizeToDeallocate // Invariant is lastMemoryLimitCheckpoint_ >= currentLocalMemoryUsage_ - sizeToDeallocate
int64_t lastMemoryLimitCheckpointDiff = int64_t lastMemoryLimitCheckpointDiff =
@ -148,11 +151,14 @@ class CountingAllocator
: diffSinceLastCheckPoint + sizeToDeallocate; : diffSinceLastCheckPoint + sizeToDeallocate;
assert(lastMemoryLimitCheckpointDiff > 0); assert(lastMemoryLimitCheckpointDiff > 0);
atomicops::atomicAddRef(*memoryLimit_, lastMemoryLimitCheckpointDiff); atomicops::atomicAddRef(*memoryLimit_, lastMemoryLimitCheckpointDiff);
lastMemoryLimitCheckpoint_ -= (lastMemoryLimitCheckpoint_ == 0) ? 0 : lastMemoryLimitCheckpointDiff; lastMemoryLimitCheckpoint_ -= (lastMemoryLimitCheckpoint_ == 0) ? 0 : lastMemoryLimitCheckpointDiff;
} }
currentLocalMemoryUsage_ = currentLocalMemoryUsage_ - sizeToDeallocate; currentLocalMemoryUsage_ = currentLocalMemoryUsage_ - sizeToDeallocate;
} }
// Equality operators (allocators are equal if they share the same counter) // Equality operators (allocators are equal if they share the same counter)