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

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