thread.h

Go to the documentation of this file.
00001 
00009 #ifndef _THREAD_H_
00010 #define _THREAD_H_
00011 
00012 #include "sys.h"
00013 #include "timers.h"
00014 
00015 
00021 #define KERNEL_THREAD_STATUS    \
00022 (                               \
00023         cp0_status_kx_mask      \
00024         | cp0_status_ie_mask    \
00025         | cp0_status_im_mask    \
00026         | cp0_status_cu0_mask   \
00027 )
00028 
00032 #define KERNEL_STACK_SIZE 4096
00033 
00034 //used in condvars
00036 #define WOKEN_UNDEFINED 0
00037 
00038 #define WOKEN_BY_TIMER 1
00039 
00040 #define WOKEN_BY_ANOTHER_THREAD 2
00041 
00042 /*
00043  * Thread status definitions
00044  *
00045  * TS_DISABLED
00046  *      the thread is not prepared to enter the internal structures
00047  * TS_READY_TO_RUN
00048  *      the thread is active and is waiting for a processor
00049  * TS_SLEEP
00050  *      the thread is disabled - waiting on a synchronization primitive
00051  * TS_RUN
00052  *      the thread is active and running
00053  */
00054  
00058 #define THREAD_INVALID  -1
00059 
00063 enum _thread_statuses {
00065         THRS_DISABLED,
00067         THRS_READY,
00069         THRS_SLEEPING,
00071         THRS_SUSPENDED,
00073         THRS_ZOMBIE
00074 };
00075 
00076 // for debuging purposes only, stores names of states
00077 extern char * thread_status [6];
00078 
00082 #define ts(status) (thread_status[status])
00083 
00084 
00085 
00086 typedef void (*thread_start_function)(void *);
00087 struct valid_thread_item_struct;
00088 
00094 struct thread_queue_struct {
00100         struct thread_struct *next, *prev;
00102 };
00103 
00105 typedef struct thread_queue_struct thread_queue_struct_t;
00106 
00107 void thread_queue_struct_init(thread_queue_struct_t queue);
00108 
00114 enum queue_types {
00115         GENERAL, VALID  
00116 };
00117 
00118 typedef struct thread_struct{
00120         int state;
00122         int *kernel_stack_context;
00124         int *kernel_stack_top;
00126         int *kernel_stack;
00128         int interrupt_counter;
00130         thread_queue_struct_t queues[2];
00132         int num_semaphores_inc;
00134         struct thread_struct * joined; 
00136         int id;
00138         int detached;
00140         int finished;
00142         unsigned sleep_start_time;
00144         unsigned sleep_length; 
00146         int interrupt_previous_state;
00148         int resource_couter;
00150         int woken_up;
00152         timer_t timer;
00154         struct thread_struct ** actual_queue;
00155 
00156 } *thread_t;
00157 
00159 extern thread_t current_thread;
00160 extern thread_t idle_thread;
00161 
00163 extern int living_threads;
00164 
00165 //typedef thread_t thread_queue_t; 
00166 inline unsigned thread_get_wakeup_time_in_ticks(thread_t thread);
00167 
00168 void thread_set_state(thread_t t , int state);
00169 
00170 void thread_remove(thread_t t);
00171 
00172 thread_t thread_create_system (void (*start) (void), int status);
00173 
00174 struct thread_struct * init_thread (void (*start) (), void *data, int status);
00175 
00176 //Functions implemented
00177 int thread_create (thread_t * thread_ptr, void (* thread_start) (void *), void * data);
00178 thread_t thread_get_current (void);
00179 int thread_join (thread_t thr);
00180 int thread_join_timeout (thread_t thr, const unsigned int usec);
00181 int thread_detach (thread_t thr);
00182 void thread_sleep (const unsigned int sec);
00183 void thread_usleep (const unsigned int usec);
00184 void thread_yield (void);
00185 void thread_suspend (void);
00186 int thread_wakeup (thread_t thr);
00187 void thread_wakeup_by_timer (timer_t * tmr, void* data);
00188 int thread_kill (thread_t thr);
00189 
00190 int thread_is_valid(thread_t thr);
00191 void __thread_dprint(thread_t thr);
00192 
00193 #endif /* _THREAD_H_ */

Generated on Wed Nov 15 17:25:43 2006 for Kalisto by  doxygen 1.4.7