Merge pull request #551 from worktycho/schedular
Implemented xoft's suggestion for a saturating counter in the scheduler
This commit is contained in:
commit
6976735a53
@ -871,16 +871,11 @@ void cWorld::TickScheduledTasks()
|
|||||||
// Make a copy of the tasks to avoid deadlocks on accessing m_Tasks
|
// Make a copy of the tasks to avoid deadlocks on accessing m_Tasks
|
||||||
{
|
{
|
||||||
cCSLock Lock(m_CSScheduledTasks);
|
cCSLock Lock(m_CSScheduledTasks);
|
||||||
ScheduledTaskList::iterator itr = m_ScheduledTasks.begin();
|
while (!m_ScheduledTasks.empty() && m_ScheduledTasks.front()->Ticks < m_WorldAge)
|
||||||
while (itr != m_ScheduledTasks.end() && (*itr)->Ticks > 0)
|
|
||||||
{
|
{
|
||||||
Tasks.push_back(m_ScheduledTasks.front());
|
Tasks.push_back(m_ScheduledTasks.front());
|
||||||
m_ScheduledTasks.pop_front();
|
m_ScheduledTasks.pop_front();
|
||||||
}
|
}
|
||||||
for(;itr != m_ScheduledTasks.end(); itr++)
|
|
||||||
{
|
|
||||||
(*itr)->Ticks--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute and delete each task:
|
// Execute and delete each task:
|
||||||
@ -2634,6 +2629,7 @@ void cWorld::QueueTask(cTask * a_Task)
|
|||||||
|
|
||||||
void cWorld::ScheduleTask(cScheduledTask * a_Task)
|
void cWorld::ScheduleTask(cScheduledTask * a_Task)
|
||||||
{
|
{
|
||||||
|
a_Task->Ticks = a_Task->Ticks + m_WorldAge;
|
||||||
cCSLock Lock(m_CSScheduledTasks);
|
cCSLock Lock(m_CSScheduledTasks);
|
||||||
for(ScheduledTaskList::iterator itr = m_ScheduledTasks.begin(); itr != m_ScheduledTasks.end(); itr++)
|
for(ScheduledTaskList::iterator itr = m_ScheduledTasks.begin(); itr != m_ScheduledTasks.end(); itr++)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user