1 // Kernel.cpp: implementation of the CKernel class.
\r
3 //////////////////////////////////////////////////////////////////////
\r
8 //////////////////////////////////////////////////////////////////////
\r
9 // Construction/Destruction
\r
10 //////////////////////////////////////////////////////////////////////
\r
26 int CKernel::Execute()
\r
29 while(taskList.size())
\r
32 PROFILE("Kernel task loop");
\r
34 DWORD starting_point = GetTickCount();
\r
36 std::list< CMMPointer<ITask> >::iterator it, thisIt;
\r
37 for(it=taskList.begin();it!=taskList.end();)
\r
41 if(!t->canKill)t->Update();
\r
43 //loop again to remove dead tasks
\r
44 for(it=taskList.begin();it!=taskList.end();)
\r
51 // 25-07-03 - updated this to use erase() rather than remove()
\r
52 taskList.erase(thisIt);
\r
56 IMMObject::CollectGarbage();
\r
57 DWORD end_point = GetTickCount();
\r
58 /* Sleep if we didn't use up too much time already */
\r
59 if (starting_point + 250 > end_point)
\r
60 Sleep(250 - (end_point-starting_point));
\r
63 CProfileSample::Output();
\r
70 bool CKernel::AddTask(const CMMPointer<ITask> &t)
\r
72 if(!t->Start())return false;
\r
74 //keep the order of priorities straight
\r
75 std::list< CMMPointer<ITask> >::iterator it;
\r
76 for(it=taskList.begin();it!=taskList.end();it++)
\r
78 CMMPointer<ITask> &comp=(*it);
\r
79 if(comp->priority>t->priority)break;
\r
81 taskList.insert(it,t);
\r
85 void CKernel::SuspendTask(const CMMPointer<ITask> &t)
\r
87 //check that this task is in our list - we don't want to suspend a task that isn't running
\r
88 if(std::find(taskList.begin(),taskList.end(),t)!=taskList.end())
\r
92 pausedTaskList.push_back(t);
\r
96 void CKernel::ResumeTask(const CMMPointer<ITask> &t)
\r
98 if(std::find(pausedTaskList.begin(),pausedTaskList.end(),t)!=pausedTaskList.end())
\r
101 pausedTaskList.remove(t);
\r
102 //keep the order of priorities straight
\r
103 std::list< CMMPointer<ITask> >::iterator it;
\r
104 for(it=taskList.begin();it!=taskList.end();it++)
\r
106 CMMPointer<ITask> &comp=(*it);
\r
107 if(comp->priority>t->priority)break;
\r
109 taskList.insert(it,t);
\r
113 void CKernel::RemoveTask(const CMMPointer<ITask> &t)
\r
115 if(std::find(taskList.begin(),taskList.end(),t)!=taskList.end())
\r
121 void CKernel::KillAllTasks()
\r
123 for(std::list< CMMPointer<ITask> >::iterator it=taskList.begin();it!=taskList.end();it++)
\r
125 (*it)->canKill=true;
\r