diff options
author | Martin Bligh <mbligh@mongodb.com> | 2015-08-27 17:45:54 -0400 |
---|---|---|
committer | Martin Bligh <mbligh@mongodb.com> | 2015-08-27 17:45:54 -0400 |
commit | c9d635404d514336a5f6ca50bf0a13f385e92bfc (patch) | |
tree | d514a2e9afe718057e4e8338e64aa61f885cf3d4 /src/mongo/db/stats | |
parent | e8f3ef4844210a474f24cb5038403917d518f554 (diff) | |
download | mongo-c9d635404d514336a5f6ca50bf0a13f385e92bfc.tar.gz |
SERVER-20167: use atomics for TimerStats
Diffstat (limited to 'src/mongo/db/stats')
-rw-r--r-- | src/mongo/db/stats/timer_stats.cpp | 10 | ||||
-rw-r--r-- | src/mongo/db/stats/timer_stats.h | 6 |
2 files changed, 6 insertions, 10 deletions
diff --git a/src/mongo/db/stats/timer_stats.cpp b/src/mongo/db/stats/timer_stats.cpp index 1030d296eb4..1fc957cf8b6 100644 --- a/src/mongo/db/stats/timer_stats.cpp +++ b/src/mongo/db/stats/timer_stats.cpp @@ -48,9 +48,8 @@ int TimerHolder::recordMillis() { } void TimerStats::recordMillis(int millis) { - scoped_spinlock lk(_lock); - _num++; - _totalMillis += millis; + _num.fetchAndAdd(1); + _totalMillis.fetchAndAdd(millis); } int TimerStats::record(const Timer& timer) { @@ -62,9 +61,8 @@ int TimerStats::record(const Timer& timer) { BSONObj TimerStats::getReport() const { long long n, t; { - scoped_spinlock lk(_lock); - n = _num; - t = _totalMillis; + n = _num.loadRelaxed(); + t = _totalMillis.loadRelaxed(); } BSONObjBuilder b(64); b.appendNumber("num", n); diff --git a/src/mongo/db/stats/timer_stats.h b/src/mongo/db/stats/timer_stats.h index cd444bee9aa..6873cab5afc 100644 --- a/src/mongo/db/stats/timer_stats.h +++ b/src/mongo/db/stats/timer_stats.h @@ -30,7 +30,6 @@ #pragma once #include "mongo/db/jsobj.h" -#include "mongo/util/concurrency/spin_lock.h" #include "mongo/util/timer.h" namespace mongo { @@ -56,9 +55,8 @@ public: } private: - mutable SpinLock _lock; - long long _num = 0; - long long _totalMillis = 0; + AtomicUInt64 _num; + AtomicUInt64 _totalMillis; }; /** |