Main Page | Data Structures | File List | Globals | Related Pages

thread.h

Go to the documentation of this file.
00001 
00011 #ifndef __KERN_THREAD_H__
00012 #define __KERN_THREAD_H__
00013 
00014 #include <list.h>
00015 #include <task.h>
00016 #include <register.h>
00017 #include <timer.h>
00018 
00019 /* the run states a thread may be in */
00020 typedef enum
00021 {
00022         /* unscheduled, it is not waiting on any resource nor is ready to run/running */
00023         THREAD_STATE_UNSCHEDULED = 0,
00024         /* ready to run */
00025         THREAD_STATE_READY,
00026         /* the thread is currently running */
00027         THREAD_STATE_RUNNING,
00028         /* the thread is waiting on a resource */
00029         THREAD_STATE_WAITING
00030 } ThreadState;
00031 
00032 /* the initial quantum is 1/10 of a second, or 100 ms */
00033 #define THREAD_QUANTUM_INITIAL (TIMER_HZ / 10)
00034 
00035 typedef unsigned int ThreadQuantum;
00036 
00037 /* the thread control block */
00038 typedef struct Thread
00039 {
00040         /* the position the thread holds in its scheduling list */
00041         ListNode schedulerList;
00042         /* the position of the threads in its task's thread list */
00043         ListNode threadList;
00044         /* the id of the thread */
00045         int id;
00046         /* the task containing the thread */
00047         Task * task; 
00048         /* the current run state of the thread */
00049         ThreadState state;
00050         /* the quantum remaining for the thread */
00051         ThreadQuantum quantum;
00052         /* the saved registers for the thread to be restored upon running */
00053         Registers registers;
00054         /* the wake handler for the thread when it is woken from sleeping on a resource */
00055         void (* waitingHandler) (struct Thread *, void *);
00056         /* data for the wake handler */
00057         void * waitingData;
00058 } Thread;
00059 
00067 extern int thread_manager_initialize (void);
00068 
00076 extern Thread * thread_current (void);
00077 
00087 extern Thread * thread_create (Task * task);
00096 extern void thread_destroy (Thread *);
00097 
00107 extern Thread * thread_fork (Task * task);
00118 extern void thread_exit (Thread * thread, int exitStatus);
00119 
00129 extern Thread * thread_find (int id);
00130 
00131 #endif /* __KERN_THREAD_H__ */
00132 

Generated on Fri Apr 9 21:59:16 2004 for 15-410 Project 3 by doxygen 1.3.2