Avoid use of atomic copy ctor in RateCounter

This commit is contained in:
Zach Pomerantz 2016-04-20 13:39:57 -07:00
parent 1fe12e7029
commit 477d6f40e4

View file

@ -21,6 +21,8 @@
template <uint32_t INTERVAL = MSECS_PER_SECOND, uint8_t PRECISION = 2>
class RateCounter {
public:
RateCounter() { _rate = 0; } // avoid use of std::atomic copy ctor
void increment(size_t count = 1) {
auto now = usecTimestampNow();
float currentIntervalMs = (now - _start) / (float) USECS_PER_MSEC;
@ -43,8 +45,8 @@ public:
private:
uint64_t _start { usecTimestampNow() };
size_t _count { 0 };
std::atomic<float> _rate { 0 };
const float _scale { powf(10, PRECISION) };
std::atomic<float> _rate;
};
#endif