Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed May 28, 2024
1 parent c514039 commit 5df7ba6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/porting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,11 +928,14 @@ constexpr size_t MEMORY_TRIM_THRESHOLD = 128 * 1024 * 1024;

void TrackFreedMemory(size_t amount)
{
size_t sum = memory_freed.fetch_add(amount, std::memory_order_relaxed);
constexpr auto MO = std::memory_order_relaxed;
size_t sum = memory_freed.fetch_add(amount, MO);
if (sum > MEMORY_TRIM_THRESHOLD) {
// Synchronize call
if (memory_freed.exchange(0, MO) <= MEMORY_TRIM_THRESHOLD)
return;
// Leave some headroom for future allocations
malloc_trim(1 * 1024 * 1024);
memory_freed.store(0);
}
}

Expand Down

0 comments on commit 5df7ba6

Please sign in to comment.