feat update
All checks were successful
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 1m4s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 1m10s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m21s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m28s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 1m27s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 1m29s
linux-x64-gcc / linux-gcc (push) Successful in 1m36s

This commit is contained in:
tqcq 2024-02-27 14:20:01 +08:00
parent 2e0e00af0c
commit 47b64af7a8

View File

@ -52,32 +52,40 @@ TimerId
TimerManager::AddTimerImpl(const Timer::ExpireCallback &cb, TimerManager::AddTimerImpl(const Timer::ExpireCallback &cb,
uint64_t run_after_ms, uint64_t run_after_ms,
uint64_t interval) uint64_t interval)
{
Timer *timer = nullptr;
{ {
MutexGuard guard(timer_inserting_set_lock_); MutexGuard guard(timer_inserting_set_lock_);
auto *timer = new Timer(TimeNowInMicroSeconds() + run_after_ms * 1000, timer = new Timer(TimeNowInMicroSeconds() + run_after_ms * 1000,
interval * 1000); interval * 1000);
timer->on_expire() = cb; timer->on_expire() = cb;
if (!timer_inserting_set_.insert({timer->when(), timer}).second) { if (!timer_inserting_set_.insert({timer->when(), timer}).second) {
ULOG_ERROR("system.timer_manager", ULOG_ERROR("system.timer_manager",
"Add timer failed, already exists timer_id={}", timer->id()); "Add timer failed, already exists timer_id={}",
timer->id());
delete timer; delete timer;
return 0; return 0;
} }
}
timers_lock_.Lock(); {
MutexGuard timers_guard(timers_lock_);
timers_cond_.NotifyAll(); timers_cond_.NotifyAll();
timers_lock_.Unlock(); }
return timer->id(); return timer->id();
} }
void void
TimerManager::CancelTimerImpl(TimerId timer_id) TimerManager::CancelTimerImpl(TimerId timer_id)
{
{ {
MutexGuard guard(timer_canceling_set_lock_); MutexGuard guard(timer_canceling_set_lock_);
timer_canceling_set_.insert(timer_id); timer_canceling_set_.insert(timer_id);
timers_lock_.Lock(); }
{
MutexGuard timers_guard(timers_lock_);
timers_cond_.NotifyAll(); timers_cond_.NotifyAll();
timers_lock_.Unlock(); }
} }
void void