L 7.4:  The scheduler function get_next_thread

(Revision 0 - 21 November 2000)

 

tcb_t *get_next_thread (kernel_vars *k)

overview    system call #2

parameter           k	 address of kerne_vars
return value	    address of the tcb of the highest priority READY thread

overview    get_next_thread  returns the tcb of  the highest priority runnable thread. Starting with the highest priority circular list it looks, starting at the head of the list, for the first READY thread. If a list does not have any READY members, it searches the next lower priority list. Along the way it removes any non-READY thread tcbs.

0-2 signature definition
3-7 if this thread was preempted by an interrupt, return it
8 for each  priority list starting with the highest do lines 9-25
9-11 if the list is empty, look at the next lower priority list
12 else starting with the head of each list do lines 13-18 (note the list header, k-->prio_busy_list, points to the tail of the circular list which points to the head of the circular list - see L7.3)
13-18
while the list isn't empty and the next thread isn't READY
	remove the non-READY thread
	and look at the next one
19-22 if a list is empty, put a 0 in it's list header and go back to step 9 and look at the next highest priority list
23-28
if a READY thread is found
	place its tcb at the tail of the list
	and return it
(this is like round robin except the thread is placed at the tail of the list
before it's dispatched)