@@ -145,31 +145,18 @@ int Scheduler::run()
145145 {
146146 processQueue ();
147147
148- Process *tmp = _pLevels[pLevel].head ;
148+ // Resume looking where we left off in the list
149+ Process *torun = getRunnable (start, _pLevels[pLevel].next , NULL );
149150
150- // No processes at this priority level
151- if (!tmp)
152- continue ;
153-
154- // find the highest priority process that needs to run
155- Process *torun = NULL ;
156-
157- // Search for the best process
158- while (tmp) {
159- if (tmp->needsServicing (start)) {
160- if (torun) { // Compare which one needs to run more
161- torun = Process::runWhich (torun, tmp);
162- } else { // torun is NULL so this is the best one to run
163- torun = tmp;
164- }
165- }
166- tmp = tmp->getNext ();
167- }
151+ if (!torun && _pLevels[pLevel].next != _pLevels[pLevel].head )
152+ torun = getRunnable (start, _pLevels[pLevel].head , _pLevels[pLevel].next );
168153
169154 // No ready process found at this priority level
170155 if (!torun)
171156 continue ;
172157
158+ _pLevels[pLevel].next = torun->hasNext () ? torun->getNext () : _pLevels[pLevel].head ;
159+
173160 // ///////// Run the correct process /////////
174161 _active = torun;
175162 start = getCurrTS (); // update
@@ -226,6 +213,32 @@ int Scheduler::run()
226213}
227214
228215
216+ // end is exclusive, end=NULL means go to entire end of list
217+ Process *Scheduler::getRunnable (uint32_t start, Process *begin, Process *end)
218+ {
219+ if (!start)
220+ return NULL ;
221+
222+ Process *torun = NULL ;
223+ Process *tmp = begin;
224+
225+ // Search for the best process
226+ while (tmp != end) {
227+ if (tmp->needsServicing (start)) {
228+ if (torun) { // Compare which one needs to run more
229+ torun = Process::runWhich (torun, tmp);
230+ } else { // torun is NULL so this is the best one to run
231+ torun = tmp;
232+ }
233+ }
234+
235+ tmp = tmp->getNext ();
236+ }
237+
238+ return torun;
239+ }
240+
241+
229242/* *********** PROTECTED ***************/
230243void Scheduler::procDisable (Process &process)
231244{
0 commit comments