From cf9d160602e35c1dcc37ddf4b47cf8ba133b8905 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Fri, 15 Apr 2016 11:10:36 -0700 Subject: [PATCH] Add sub to Debug Counter --- libraries/shared/src/Debug.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/libraries/shared/src/Debug.h b/libraries/shared/src/Debug.h index d5568749d4..55d6d7975d 100644 --- a/libraries/shared/src/Debug.h +++ b/libraries/shared/src/Debug.h @@ -55,8 +55,11 @@ public: } ~Counter() { log(); } - // Increase the count for key. - void add(const K& key); + // Increase the count for key (by inc). + void add(const K& key, size_t inc = 1); + + // Decrease the count for key (by dec). + void sub(const K& key, size_t dec = 1); // Log current counts (called on destruction). void log(); @@ -123,20 +126,25 @@ private: }; template -void Counter::add(const K& k) { +void Counter::add(const K& k, size_t inc) { std::lock_guard lock(_mutex); auto& it = _map.find(k); if (it == _map.end()) { // No entry for k; add it - _map.insert(std::pair(k, 1)); + _map.insert(std::pair(k, inc)); } else { // Entry for k; update it - it->second++; + it->second += inc; } } +template +void Counter::sub(const K& k, size_t dec) { + add(k, -dec); +} + template void Counter::log() { // Avoid logging nothing