summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/inspircd.cpp1
-rw-r--r--src/timer.cpp116
2 files changed, 22 insertions, 95 deletions
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index e52aa8fc2..4ca4c50d6 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -642,7 +642,6 @@ int InspIRCd::Run()
if ((TIME % 5) == 0)
{
FOREACH_MOD_I(this,I_OnBackgroundTimer,OnBackgroundTimer(TIME));
- Timers->TickMissedTimers(TIME);
SNO->FlushSnotices();
}
#ifndef WIN32
diff --git a/src/timer.cpp b/src/timer.cpp
index d9b1b6414..ca7534a7c 100644
--- a/src/timer.cpp
+++ b/src/timer.cpp
@@ -16,122 +16,50 @@
#include "inspircd.h"
#include "timer.h"
-TimerManager::TimerManager(InspIRCd* Instance) : CantDeleteHere(false), ServerInstance(Instance)
+TimerManager::TimerManager(InspIRCd* Instance) : ServerInstance(Instance)
{
}
void TimerManager::TickTimers(time_t TIME)
{
- this->CantDeleteHere = true;
- timerlist::iterator found = Timers.find(TIME);
-
- if (found != Timers.end())
+ while ((Timers.size()) && (TIME > (*Timers.begin())->GetTimer()))
{
- timergroup* x = found->second;
- /* There are pending timers to trigger.
- * WARNING: Timers may delete themselves from within
- * their own Tick methods! see the comment below in
- * the DelTimer method.
- */
- for (timergroup::iterator y = x->begin(); y != x->end(); y++)
+ std::vector<Timer *>::iterator i = Timers.begin();
+ Timer *t = (*i);
+
+ t->Tick(TIME);
+ if (t->GetRepeat())
{
- Timer* n = *y;
- n->Tick(TIME);
- if (n->GetRepeat())
- {
- AddTimer(n, n->GetSecs());
- }
- else
- {
- delete n;
- }
+ t->SetTimer(TIME + t->GetSecs());
+ AddTimer(t);
}
+ else
+ delete t;
- Timers.erase(found);
- delete x;
+ Timers.erase(i);
}
-
- this->CantDeleteHere = false;
}
void TimerManager::DelTimer(Timer* T)
{
- if (this->CantDeleteHere)
- {
- /* If a developer tries to delete a timer from within its own Tick method,
- * then chances are this is just going to totally fuck over the timergroup
- * and timerlist iterators and cause a crash. Thanks to peavey and Bricker
- * for noticing this bug.
- * If we're within the tick loop when the DelTimer is called (signified
- * by the var 'CantDeleteHere') then we simply return for non-repeating
- * timers, and cancel the repeat on repeating timers. We can do this because
- * we know that the timer tick loop will safely delete the timer for us
- * anyway and therefore we avoid stack corruption.
- */
- if (T->GetRepeat())
- T->CancelRepeat();
- else
- return;
- }
-
- timerlist::iterator found = Timers.find(T->GetTimer());
+ std::vector<Timer *>::iterator i = std::find(Timers.begin(), Timers.end(), T);
- if (found != Timers.end())
+ if (i != Timers.end())
{
- timergroup* x = found->second;
- for (timergroup::iterator y = x->begin(); y != x->end(); y++)
- {
- Timer* n = *y;
- if (n == T)
- {
- delete n;
- x->erase(y);
- if (!x->size())
- {
- Timers.erase(found);
- delete x;
- }
- return;
- }
- }
+ delete (*i);
+ Timers.erase(i);
}
}
-/** Because some muppets may do odd things, and their ircd may lock up due
- * to crappy 3rd party modules, or they may change their system time a bit,
- * this accounts for shifts of up to 120 secs by looking behind for missed
- * timers and executing them. This is only executed once every 5 secs.
- * If you move your clock BACK, and your timers move further ahead as a result,
- * then tough titty you'll just have to wait.
- */
-void TimerManager::TickMissedTimers(time_t TIME)
+void TimerManager::AddTimer(Timer* T)
{
- for (time_t n = TIME-1; n > TIME-120; n--)
- this->TickTimers(TIME);
+ Timers.push_back(T);
+ sort(Timers.begin(), Timers.end(), TimerManager::TimerComparison);
}
-void TimerManager::AddTimer(Timer* T, long secs_from_now)
+bool TimerManager::TimerComparison( Timer *one, Timer *two)
{
- timergroup* x = NULL;
-
- int time_to_trigger = 0;
- if (!secs_from_now)
- time_to_trigger = T->GetTimer();
- else
- time_to_trigger = secs_from_now + ServerInstance->Time();
-
- timerlist::iterator found = Timers.find(time_to_trigger);
-
- if (found != Timers.end())
- {
- x = found->second;
- }
- else
- {
- x = new timergroup;
- Timers[time_to_trigger] = x;
- }
-
- x->push_back(T);
+ return (one->GetTimer()) < (two->GetTimer());
}
+