feat fix miss std::atomic_uint64_t
Some checks failed
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Waiting to run
linux-mips64-gcc / linux-gcc-mips64el (push) Waiting to run
linux-x64-gcc / linux-gcc (push) Failing after 49s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Failing after 59s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Failing after 1m19s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Failing after 1m0s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Failing after 1m34s

This commit is contained in:
tqcq 2023-12-28 12:24:54 +08:00
parent 90e10881d3
commit 8e35843d04
2 changed files with 13 additions and 3 deletions

View File

@ -18,16 +18,24 @@ TimeNowInMicroSeconds()
return tv.tv_sec * 1000000ULL + tv.tv_usec; return tv.tv_sec * 1000000ULL + tv.tv_usec;
} }
std::atomic_uint64_t Timer::next_timer_id_(1); std::atomic<uint64_t> Timer::next_timer_id_(0);
Timer::Timer(uint64_t when, uint64_t interval) Timer::Timer(uint64_t when, uint64_t interval)
: timer_id_(next_timer_id_.fetch_add(1)), : timer_id_(NextTimerId()),
when_(when), when_(when),
interval_(interval), interval_(interval),
auto_reset_(interval_ > 0), auto_reset_(interval_ > 0),
expire_callback_() expire_callback_()
{} {}
uint64_t
Timer::NextTimerId()
{
uint64_t id = 0;
while (id == 0) { id = next_timer_id_.fetch_add(1); }
return id;
}
TimerManager::TimerManager() TimerManager::TimerManager()
: stopped_(false), : stopped_(false),
thread_(std::bind(&TimerManager::Loop, this), "timer_manager_thread"), thread_(std::bind(&TimerManager::Loop, this), "timer_manager_thread"),

View File

@ -16,6 +16,7 @@ using TimerId = uint64_t;
class Timer { class Timer {
public: public:
const uint64_t INVALID_TIMER_ID = 0;
using ExpireCallback = std::function<void()>; using ExpireCallback = std::function<void()>;
Timer(uint64_t when, uint64_t intarval); Timer(uint64_t when, uint64_t intarval);
// void Start(); // void Start();
@ -29,6 +30,7 @@ public:
bool operator == (const Timer& rhs) const { return timer_id_ == rhs.timer_id_; } bool operator == (const Timer& rhs) const { return timer_id_ == rhs.timer_id_; }
private: private:
static uint64_t NextTimerId();
const TimerId timer_id_; const TimerId timer_id_;
// micro seconds // micro seconds
uint64_t when_; uint64_t when_;
@ -36,7 +38,7 @@ private:
uint64_t interval_; uint64_t interval_;
bool auto_reset_; bool auto_reset_;
ExpireCallback expire_callback_; ExpireCallback expire_callback_;
static std::atomic_uint64_t next_timer_id_; static std::atomic<uint64_t> next_timer_id_;
}; };