eventloop: avoid duplicate timers
This commit is contained in:
parent
d84699d8e5
commit
3b04131259
1 changed files with 7 additions and 2 deletions
|
|
@ -100,7 +100,8 @@ void CEventLoopManager::enterLoop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CEventLoopManager::onTimerFire() {
|
void CEventLoopManager::onTimerFire() {
|
||||||
for (auto const& t : m_timers.timers) {
|
const auto CPY = m_timers.timers;
|
||||||
|
for (auto const& t : CPY) {
|
||||||
if (t.strongRef() > 1 /* if it's 1, it was lost. Don't call it. */ && t->passed() && !t->cancelled())
|
if (t.strongRef() > 1 /* if it's 1, it was lost. Don't call it. */ && t->passed() && !t->cancelled())
|
||||||
t->call(t);
|
t->call(t);
|
||||||
}
|
}
|
||||||
|
|
@ -109,11 +110,15 @@ void CEventLoopManager::onTimerFire() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CEventLoopManager::addTimer(SP<CEventLoopTimer> timer) {
|
void CEventLoopManager::addTimer(SP<CEventLoopTimer> timer) {
|
||||||
m_timers.timers.push_back(timer);
|
if (std::ranges::contains(m_timers.timers, timer))
|
||||||
|
return;
|
||||||
|
m_timers.timers.emplace_back(timer);
|
||||||
nudgeTimers();
|
nudgeTimers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CEventLoopManager::removeTimer(SP<CEventLoopTimer> timer) {
|
void CEventLoopManager::removeTimer(SP<CEventLoopTimer> timer) {
|
||||||
|
if (!std::ranges::contains(m_timers.timers, timer))
|
||||||
|
return;
|
||||||
std::erase_if(m_timers.timers, [timer](const auto& t) { return timer == t; });
|
std::erase_if(m_timers.timers, [timer](const auto& t) { return timer == t; });
|
||||||
nudgeTimers();
|
nudgeTimers();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue