mirror of
https://github.com/anope/anope.git
synced 2026-06-26 21:16:39 +02:00
Properly remove old callbacks from modules internal list of callbacks list, and cleaned up some of the timers code
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2524 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
+9
-2
@@ -99,11 +99,18 @@ class CoreExport TimerManager : public Extensible
|
||||
static void AddTimer(Timer *T);
|
||||
|
||||
/** Deletes a timer
|
||||
* @param T A Timer derived class to delete */
|
||||
* @param T A Timer derived class to delete
|
||||
*/
|
||||
static void DelTimer(Timer *T);
|
||||
|
||||
/** Check if something is a timer
|
||||
* @param T A pointer
|
||||
* @return true or false
|
||||
*/
|
||||
static bool IsTimer(Timer *T);
|
||||
|
||||
/** Tick all pending timers
|
||||
* @param time The current time
|
||||
* @param ctime The current time
|
||||
*/
|
||||
static void TickTimers(time_t ctime = time(NULL));
|
||||
|
||||
|
||||
@@ -479,14 +479,10 @@ bool ModuleManager::SetPriority(Module* mod, Implementation i, Priority s, Modul
|
||||
void ModuleManager::ClearTimers(Module *m)
|
||||
{
|
||||
std::list<Timer *>::iterator it;
|
||||
Timer *t2;
|
||||
|
||||
for (it = m->CallBacks.begin(); it != m->CallBacks.end(); ++it)
|
||||
{
|
||||
t2 = *it;
|
||||
|
||||
TimerManager::DelTimer(t2);
|
||||
TimerManager::DelTimer(*it);
|
||||
}
|
||||
|
||||
m->CallBacks.clear();
|
||||
}
|
||||
|
||||
+18
-11
@@ -625,6 +625,19 @@ int destroyMessage(Message * m)
|
||||
*/
|
||||
void Module::AddCallBack(Timer *t)
|
||||
{
|
||||
/* Remove no longer valid Timers from the modules internal list */
|
||||
std::list<Timer *>::iterator it, it2;
|
||||
for (it = this->CallBacks.begin(); it != this->CallBacks.end(); it = it2)
|
||||
{
|
||||
it2 = it;
|
||||
++it2;
|
||||
|
||||
if (!TimerManager::IsTimer(*it))
|
||||
{
|
||||
this->CallBacks.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
this->CallBacks.push_back(t);
|
||||
}
|
||||
|
||||
@@ -634,19 +647,13 @@ void Module::AddCallBack(Timer *t)
|
||||
*/
|
||||
bool Module::DelCallBack(Timer *t)
|
||||
{
|
||||
std::list<Timer *>::iterator it;
|
||||
Timer *t2;
|
||||
std::list<Timer *>::iterator it = std::find(this->CallBacks.begin(), this->CallBacks.end(), t);
|
||||
|
||||
for (it = this->CallBacks.begin(); it != this->CallBacks.end(); ++it)
|
||||
if (it != this->CallBacks.end())
|
||||
{
|
||||
t2 = *it;
|
||||
|
||||
if (t == t2)
|
||||
{
|
||||
TimerManager::DelTimer(t2);
|
||||
this->CallBacks.erase(it);
|
||||
return true;
|
||||
}
|
||||
TimerManager::DelTimer(*it);
|
||||
this->CallBacks.erase(it);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
+19
-6
@@ -99,8 +99,24 @@ void TimerManager::DelTimer(Timer *T)
|
||||
}
|
||||
}
|
||||
|
||||
/** Check if something is a timer
|
||||
* @param T A pointer
|
||||
* @return true or false
|
||||
*/
|
||||
bool TimerManager::IsTimer(Timer *T)
|
||||
{
|
||||
std::vector<Timer *>::iterator i = std::find(Timers.begin(), Timers.end(), T);
|
||||
|
||||
if (i != Timers.end())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Tick all pending timers
|
||||
* @param time The current time
|
||||
* @param ctime The current time
|
||||
*/
|
||||
void TimerManager::TickTimers(time_t ctime)
|
||||
{
|
||||
@@ -110,20 +126,17 @@ void TimerManager::TickTimers(time_t ctime)
|
||||
while ((Timers.size()) && (ctime > (*Timers.begin())->GetTimer()))
|
||||
{
|
||||
i = Timers.begin();
|
||||
|
||||
t = *i;
|
||||
|
||||
t->Tick(ctime);
|
||||
|
||||
Timers.erase(i);
|
||||
|
||||
if (t->GetRepeat())
|
||||
{
|
||||
t->SetTimer(ctime + t->GetSecs());
|
||||
AddTimer(t);
|
||||
sort(Timers.begin(), Timers.end(), TimerManager::TimerComparison);
|
||||
}
|
||||
else
|
||||
delete t;
|
||||
TimerManager::DelTimer(t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user