#include "thread.h"
#include "tqueue.h"
Go to the source code of this file.
Functions | |
void | init_scheduler () |
void | runnable (struct thread_struct *t) |
void | disabled (struct thread_struct *t) |
void | context_switch (struct thread_struct *t) |
void | schedule (void) |
Scheduling function Function wake up runnable threads(by timer checking), remove from system zombies, that could be removed, choose next thread from the ready to run list and switch context to this thread. Note: In the system is still at least one runnable thread (system thread). Note: zombie can not be removed (freed()), when this schedule rutine is runninin its context. | |
Variables | |
thread_queue_t | runnable_threads |
thread_queue_t | sleeping_threads |
thread_queue_t | zombies_to_kill_threads |
thread_queue_t | valid_threads |
Scheduler is implemented as simple round robin (no priorities). Scheduler holds all the time two queues of threads. One for runnable threads (unsorted fifo) and one for to_remove_zombie threads (), that are finished, somebody join them or they were detached and can be removed from system. Threse zombie threads are removed from system in function schedule(). Sleeping threads dont need any special queue, all the thread has internal timer, and rutine called from this timer wake up thread to be set as runnable. running thread is on the head of runnable threads in the time of execution code of it. Scheduler at first try to wake up sleeping threads (, check timers,so move them in queue of ready to run threads), Than remove zombies, that could be removed (thread can not free memory of itself), and than switch context for the first ready to run thread. In system is all the time at least one runnable thread, system thread with ID == 0.
This file is based on Kalisto, Development Kernel copyrighted (c) to Distributed Systems Research Group MFF UK, Czech republic.
void context_switch | ( | struct thread_struct * | t | ) |
Switch procesor context from the current thread to context of thread t
t | - thread to be switched context to |
A list of ready-to-run threads. This serves as a round-robin queue -- the thread at the head will be activated by a schedule() call. Struture is organized as fifo, uses pointers prev, next of thread_t structure. (cyclic fifo, uses prev next items of thread_t structure)
A list of all valid threads int the system thread are enqued to it by thread_create() and remoded by thread_remove() (cyclic fifo, uses vprev vnext items of thread_t structure)
thread_create()
thread
A list of zombies, that can be romoved from the system (were detached or joined by some ohter thread). thread are enqued to this thread in thread_kill() function and are removed in schedule() call. (cyclic fifo, uses prev next items of thread_t structure)
__thread_wrapper()