Hardware Reference
In-Depth Information
new
head index
p
q
NIL
first
last
NIL
Figure 10.12
Inserting a TCB in a queue.
/*-----------------------------------------------------------*/
/* insert -- a task in a queue based on its deadline */
/*-----------------------------------------------------------*/
void
insert (proc i, queue *que)
long
dl;
/* deadline of the task to be inserted */
int
p;
/* pointer to the previous TCB
*/
int
q;
/* pointer to the next TCB
*/
p = NIL;
q = *que;
dl = vdes[i].dline;
/* find the element before the insertion point */
while ((q != NIL) && (dl >= vdes[q].dline)) {
p=q;
q = vdes[q].next;
if (p != NIL) vdes[p].next = i;
else *que = i;
if (q != NIL) vdes[q].prev = i;
vdes[i].next = q;
vdes[i].prev = p;
}
 
Search WWH ::




Custom Search