From: Patrick Donnelly Date: Thu, 27 Jul 2017 19:03:15 +0000 (-0700) Subject: common: use atomic uin64_t for counter X-Git-Tag: v13.0.1~926^2~13 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=59b5931a2f47f90fced779fb89e06868c739c688;p=ceph.git common: use atomic uin64_t for counter Making this interface thread-safe... Signed-off-by: Patrick Donnelly --- diff --git a/src/include/counter.h b/src/include/counter.h index d161c0b7dac61..61ed7409c7e4f 100644 --- a/src/include/counter.h +++ b/src/include/counter.h @@ -15,6 +15,8 @@ #ifndef CEPH_COUNTER_H #define CEPH_COUNTER_H +#include + template class Counter { public: @@ -30,23 +32,23 @@ public: ~Counter() { _count()--; } - static unsigned long count() { + static uint64_t count() { return _count(); } - static unsigned long increments() { + static uint64_t increments() { return _increments(); } - static unsigned long decrements() { + static uint64_t decrements() { return increments()-count(); } private: - static unsigned long &_count() { - static unsigned long c; + static std::atomic &_count() { + static std::atomic c; return c; } - static unsigned long &_increments() { - static unsigned long i; + static std::atomic &_increments() { + static std::atomic i; return i; } };