| Index: src/base/accounting-allocator.cc
|
| diff --git a/src/base/accounting-allocator.cc b/src/base/accounting-allocator.cc
|
| index 2269c60680c0e1d13b542ebbc9a56451382560b5..72a9deeb6553f4b0cd6705128b334422e4d8f795 100644
|
| --- a/src/base/accounting-allocator.cc
|
| +++ b/src/base/accounting-allocator.cc
|
| @@ -15,18 +15,31 @@ namespace base {
|
|
|
| void* AccountingAllocator::Allocate(size_t bytes) {
|
| void* memory = malloc(bytes);
|
| - if (memory) NoBarrier_AtomicIncrement(¤t_memory_usage_, bytes);
|
| + if (memory) {
|
| + LockGuard<Mutex> guard(&mutex_);
|
| + current_memory_usage_ += bytes;
|
| + if (peak_memory_usage_ < current_memory_usage_)
|
| + peak_memory_usage_ = current_memory_usage_;
|
| + }
|
| return memory;
|
| }
|
|
|
| void AccountingAllocator::Free(void* memory, size_t bytes) {
|
| free(memory);
|
| - NoBarrier_AtomicIncrement(¤t_memory_usage_,
|
| - -static_cast<AtomicWord>(bytes));
|
| + {
|
| + LockGuard<Mutex> guard(&mutex_);
|
| + current_memory_usage_ -= bytes;
|
| + }
|
| }
|
|
|
| size_t AccountingAllocator::GetCurrentMemoryUsage() const {
|
| - return NoBarrier_Load(¤t_memory_usage_);
|
| + LockGuard<Mutex> guard(const_cast<Mutex*>(&mutex_));
|
| + return current_memory_usage_;
|
| +}
|
| +
|
| +size_t AccountingAllocator::GetPeakMemoryUsage() const {
|
| + LockGuard<Mutex> guard(const_cast<Mutex*>(&mutex_));
|
| + return peak_memory_usage_;
|
| }
|
|
|
| } // namespace base
|
|
|