fix stop timer in callback
All checks were successful
linux-x64-gcc / linux-gcc (Release) (push) Successful in 1m32s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 1m35s

This commit is contained in:
tqcq 2024-03-19 14:12:27 +08:00
parent 46baaf0b8f
commit 7e1a443130

View File

@ -47,6 +47,7 @@ Timer::Stop()
{
if (is_running()) {
timeout_->Stop();
generation_ = TimerGeneration(generation_ + 1);
expiration_count_ = 0;
is_running_ = false;
}
@ -58,6 +59,7 @@ Timer::Trigger(TimerGeneration generation)
if (!is_running_ || generation != generation_) { return; }
++expiration_count_;
is_running_ = false;
// if max_restarts > exppiration_count_ then restart
{
is_running_ = true;
@ -82,12 +84,10 @@ TimerManager::CreateTimer(const std::string &name, Timer::OnExpired on_expired)
next_id_ = TimerID(next_id_ + 1);
TimerID id = next_id_;
std::unique_ptr<Timeout> timeout =
timeout_creator_(sled::TaskQueueBase::DelayPrecision::kHigh);
std::unique_ptr<Timeout> timeout = timeout_creator_(sled::TaskQueueBase::DelayPrecision::kHigh);
auto timer = std::unique_ptr<Timer>(new Timer(
id, name, std::move(on_expired),
/* ungrgister_handler=*/[this, id]() { timers_.erase(id); },
std::move(timeout)));
/* ungrgister_handler=*/[this, id]() { timers_.erase(id); }, std::move(timeout)));
timers_[id] = timer.get();
return timer;
}