diff options
| author | Vaxry <vaxry@vaxry.net> | 2025-07-19 13:31:31 +0200 |
|---|---|---|
| committer | Vaxry <vaxry@vaxry.net> | 2025-07-19 13:31:37 +0200 |
| commit | 3b04131259bad140183a3825b981ebe30b61e524 (patch) | |
| tree | 2eaefc03166881728d39f6fcef82fdaea43ea4ab /src/managers/eventLoop/EventLoopManager.cpp | |
| parent | d84699d8e5e984422da37595ee41fc0d8d93fef5 (diff) | |
eventloop: avoid duplicate timers
Diffstat (limited to 'src/managers/eventLoop/EventLoopManager.cpp')
| -rw-r--r-- | src/managers/eventLoop/EventLoopManager.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/managers/eventLoop/EventLoopManager.cpp b/src/managers/eventLoop/EventLoopManager.cpp index 357c2fff..0389e7b8 100644 --- a/src/managers/eventLoop/EventLoopManager.cpp +++ b/src/managers/eventLoop/EventLoopManager.cpp @@ -100,7 +100,8 @@ void CEventLoopManager::enterLoop() { } 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()) t->call(t); } @@ -109,11 +110,15 @@ void CEventLoopManager::onTimerFire() { } 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(); } 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; }); nudgeTimers(); } |
