Index: src/base/accounting-allocator.cc |
diff --git a/src/base/accounting-allocator.cc b/src/base/accounting-allocator.cc |
index c56f037c04c00a9e6ec97976a6b0fb614e7cd091..7313209577a0921e537746e991d789374dcb00a6 100644 |
--- a/src/base/accounting-allocator.cc |
+++ b/src/base/accounting-allocator.cc |
@@ -16,20 +16,24 @@ namespace base { |
void* AccountingAllocator::Allocate(size_t bytes) { |
void* memory = malloc(bytes); |
if (memory) { |
- AtomicWord current = |
- NoBarrier_AtomicIncrement(¤t_memory_usage_, bytes); |
- AtomicWord max = NoBarrier_Load(&max_memory_usage_); |
- while (current > max) { |
- max = NoBarrier_CompareAndSwap(&max_memory_usage_, max, current); |
- } |
+ ChangeCurrentMemoryUsage(bytes); |
} |
return memory; |
} |
void AccountingAllocator::Free(void* memory, size_t bytes) { |
free(memory); |
- NoBarrier_AtomicIncrement(¤t_memory_usage_, |
- -static_cast<AtomicWord>(bytes)); |
+ ChangeCurrentMemoryUsage(-static_cast<int64_t>(bytes)); |
+} |
+ |
+void AccountingAllocator::ChangeCurrentMemoryUsage(const int64_t bytes) { |
+ AtomicWord current = NoBarrier_AtomicIncrement(¤t_memory_usage_, bytes); |
+ AtomicWord max = NoBarrier_Load(&max_memory_usage_); |
+ if (bytes > 0) { |
+ while (current > max) { |
+ max = NoBarrier_CompareAndSwap(&max_memory_usage_, max, current); |
+ } |
+ } |
} |
size_t AccountingAllocator::GetCurrentMemoryUsage() const { |