#include #include "EpochCounter.h" volatile EpochCounter::Epoch EpochCounter::_currentEpoch = 0; EpochCounter::Epoch EpochCounter::getNextEpoch() { return __sync_add_and_fetch(&_currentEpoch, 1); } time_t EpochCounter::restartAt(Epoch epoch) const { std::map< Epoch, time_t >::const_iterator it = _startAfter.upper_bound(epoch); if (it == _startAfter.end()) return std::numeric_limits< time_t >::max(); else return it->second; } void EpochCounter::addEpoch(time_t time) { while (true) { std::map< Epoch, time_t >::reverse_iterator it = _startAfter.rbegin(); if (it == _startAfter.rend()) break; if (it->second < time) break; it++; _startAfter.erase(it.base()); } _startAfter[getNextEpoch()] = time; } EpochCounter::Epoch EpochCounter::getEpoch() { return _currentEpoch; }