Skip to content

Commit 92014a0

Browse files
committed
Processes in same priority level can't block others from running
1 parent e54eaf2 commit 92014a0

2 files changed

Lines changed: 35 additions & 19 deletions

File tree

src/ProcessScheduler/Scheduler.cpp

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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 ***************/
230243
void Scheduler::procDisable(Process &process)
231244
{

src/ProcessScheduler/Scheduler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ class Scheduler
238238
void procRestart(Process &process);
239239
void procHalt();
240240

241+
// Get runnable process in process linked list chain
242+
Process *getRunnable(uint32_t start, Process *begin, Process *end=NULL);
243+
241244
// Process the scheduler job queue
242245
void processQueue();
243246

0 commit comments

Comments
 (0)