feat update
Some checks failed
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m24s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m18s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 1m21s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 1m53s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 2m10s
linux-mips64-gcc / linux-gcc-mips64el (push) Has been cancelled
linux-x64-gcc / linux-gcc (push) Has been cancelled
Some checks failed
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m24s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m18s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 1m21s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 1m53s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 2m10s
linux-mips64-gcc / linux-gcc-mips64el (push) Has been cancelled
linux-x64-gcc / linux-gcc (push) Has been cancelled
This commit is contained in:
parent
c1dbc8194e
commit
2e0e00af0c
@ -54,19 +54,19 @@ TimerManager::AddTimerImpl(const Timer::ExpireCallback &cb,
|
||||
uint64_t interval)
|
||||
{
|
||||
MutexGuard guard(timer_inserting_set_lock_);
|
||||
auto *timer =
|
||||
new Timer(TimeNowInMicroSeconds() + run_after_ms * 1000, interval * 1000);
|
||||
auto *timer = new Timer(TimeNowInMicroSeconds() + run_after_ms * 1000,
|
||||
interval * 1000);
|
||||
timer->on_expire() = cb;
|
||||
if (!timer_inserting_set_.insert({timer->when(), timer}).second) {
|
||||
ULOG_ERROR("system.timer_manager", "Add timer failed, already exists timer_id={}", timer->id());
|
||||
ULOG_ERROR("system.timer_manager",
|
||||
"Add timer failed, already exists timer_id={}", timer->id());
|
||||
delete timer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (timers_lock_.TryLock()) {
|
||||
timers_lock_.Lock();
|
||||
timers_cond_.NotifyAll();
|
||||
timers_lock_.Unlock();
|
||||
}
|
||||
return timer->id();
|
||||
}
|
||||
|
||||
@ -75,10 +75,9 @@ TimerManager::CancelTimerImpl(TimerId timer_id)
|
||||
{
|
||||
MutexGuard guard(timer_canceling_set_lock_);
|
||||
timer_canceling_set_.insert(timer_id);
|
||||
if (timers_lock_.TryLock()) {
|
||||
timers_lock_.Lock();
|
||||
timers_cond_.NotifyAll();
|
||||
timers_lock_.Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -102,7 +101,8 @@ TimerManager::Loop()
|
||||
{
|
||||
// TODO imporve
|
||||
MutexGuard cancel_guard(timer_canceling_set_lock_);
|
||||
for (auto iter = timers_.begin(); !timer_canceling_set_.empty() && iter != timers_.end();) {
|
||||
for (auto iter = timers_.begin();
|
||||
!timer_canceling_set_.empty() && iter != timers_.end();) {
|
||||
if (timer_canceling_set_.find(iter->second->id())
|
||||
!= timer_canceling_set_.end()) {
|
||||
delete iter->second;
|
||||
@ -124,9 +124,10 @@ TimerManager::Loop()
|
||||
uint64_t wait_time_ms = (timers_.begin()->first - now) / 1000;
|
||||
timers_cond_.WaitForMilliseconds(timers_guard, wait_time_ms);
|
||||
now = TimeNowInMicroSeconds();
|
||||
} while(timers_.begin()->first > now);
|
||||
} while (timers_.begin()->first > now);
|
||||
} else {
|
||||
ULOG_TRACE("system.timer_manager", "need trigger set size: {}", timers_.size());
|
||||
ULOG_TRACE("system.timer_manager", "need trigger set size: {}",
|
||||
timers_.size());
|
||||
std::set<Entry> expired_timers;
|
||||
while (!timers_.empty() && timers_.begin()->first <= now) {
|
||||
expired_timers.insert(*timers_.begin());
|
||||
@ -136,7 +137,7 @@ TimerManager::Loop()
|
||||
for (auto iter = expired_timers.begin();
|
||||
iter != expired_timers.end(); ++iter) {
|
||||
uint64_t when = iter->first;
|
||||
Timer* timer = iter->second;
|
||||
Timer *timer = iter->second;
|
||||
try {
|
||||
timer->on_expire()();
|
||||
if (timer->auto_reset()) {
|
||||
@ -175,9 +176,7 @@ TimerManager::Instance()
|
||||
{
|
||||
static TimerManager timer_manager;
|
||||
static std::once_flag init_flag;
|
||||
std::call_once(init_flag, [&]{
|
||||
timer_manager.Initialize();
|
||||
});
|
||||
std::call_once(init_flag, [&] { timer_manager.Initialize(); });
|
||||
return timer_manager;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user