1
0

Implemented xsofts suggestion for a saturating counter in the scheduler

This commit is contained in:
Tycho 2014-01-17 10:07:33 -08:00
parent cef2967637
commit ce030bc7c9
2 changed files with 8 additions and 5 deletions

View File

@ -875,10 +875,6 @@ void cWorld::TickScheduledTasks()
Tasks.push_back(m_ScheduledTasks.front());
m_ScheduledTasks.pop_front();
}
for(;itr != m_ScheduledTasks.end(); itr++)
{
(*itr)->Ticks--;
}
}
// Execute and delete each task:
@ -887,6 +883,9 @@ void cWorld::TickScheduledTasks()
(*itr)->Run(*this);
delete *itr;
} // for itr - m_Tasks[]
// Increment TickID
m_TickID = (m_TickID+1) &0xFFFF;
}
@ -2623,10 +2622,11 @@ void cWorld::QueueTask(cTask * a_Task)
void cWorld::ScheduleTask(cScheduledTask * a_Task)
{
a_Task->Ticks = (a_Task->Ticks + m_TickID) & 0xFFFF;
cCSLock Lock(m_CSScheduledTasks);
for(ScheduledTaskList::iterator itr = m_ScheduledTasks.begin(); itr != m_ScheduledTasks.end(); itr++)
{
if((*itr)->Ticks >= a_Task->Ticks)
if((*itr)->Ticks >= a_Task->Ticks && (a_Task->Ticks > m_TickID || (*itr)->Ticks < m_TickID))
{
m_ScheduledTasks.insert(itr, a_Task);
return;

View File

@ -772,6 +772,9 @@ private:
/// the future; guarded by m_CSScheduledTasks
ScheduledTaskList m_ScheduledTasks;
/// Current Tick number for sceduled tasks
int m_TickID;
/// Guards m_Clients
cCriticalSection m_CSClients;