#include "sys.h"
#include "timers.h"
Go to the source code of this file.
Data Structures | |
struct | thread_queue_struct |
struct | thread_struct |
Defines | |
#define | KERNEL_THREAD_STATUS |
#define | KERNEL_STACK_SIZE 4096 |
#define | WOKEN_UNDEFINED 0 |
#define | WOKEN_BY_TIMER 1 |
#define | WOKEN_BY_ANOTHER_THREAD 2 |
#define | THREAD_INVALID -1 |
#define | ts(status) (thread_status[status]) |
Typedefs | |
typedef void(*) | thread_start_function (void *) |
typedef thread_queue_struct | thread_queue_struct_t |
typedef thread_struct * | thread_t |
Enumerations | |
enum | _thread_statuses { THRS_DISABLED, THRS_READY, THRS_SLEEPING, THRS_SUSPENDED, THRS_ZOMBIE } |
enum | queue_types { GENERAL, VALID } |
Functions | |
void | thread_queue_struct_init (thread_queue_struct_t queue) |
unsigned | thread_get_wakeup_time_in_ticks (thread_t thread) |
void | thread_set_state (thread_t t, int state) |
void | thread_remove (thread_t t) |
thread_t | thread_create_system (void(*start)(void), int status) |
thread_struct * | init_thread (void(*start)(), void *data, int status) |
int | thread_create (thread_t *thread_ptr, void(*thread_start)(void *), void *data) |
thread_t | thread_get_current (void) |
int | thread_join (thread_t thr) |
Join thread given as parameter. | |
int | thread_join_timeout (thread_t thr, const unsigned int usec) |
Try to join thread given as parameter for fixed time. | |
int | thread_detach (thread_t thr) |
Detach thread given as parameter. | |
void | thread_sleep (const unsigned int sec) |
Stops execution of thee thread for time in useconds. | |
void | thread_usleep (const unsigned int usec) |
Stops execution of thee thread for time in useconds. | |
void | thread_yield (void) |
void | thread_suspend (void) |
int | thread_wakeup (thread_t thr) |
void | thread_wakeup_by_timer (timer_t *tmr, void *data) |
int | thread_kill (thread_t thr) |
int | thread_is_valid (thread_t thr) |
check, if the thread given is or is NOT valid in the system | |
void | __thread_dprint (thread_t thr) |
Variables | |
char * | thread_status [6] |
thread_t | current_thread |
thread_t | idle_thread |
int | living_threads |
This file is based on Kalisto, Development Kernel copyrighted (c) to Distributed Systems Research Group MFF UK, Czech republic.
#define KERNEL_STACK_SIZE 4096 |
Size of the stack for kernel thread
#define KERNEL_THREAD_STATUS |
Value:
( \ cp0_status_kx_mask \ | cp0_status_ie_mask \ | cp0_status_im_mask \ | cp0_status_cu0_mask \ )
#define THREAD_INVALID -1 |
returned on thread creation if no memory is available or some other problem occur
#define ts | ( | status | ) | (thread_status[status]) |
for debuging purposes only, replace name of the state (state is enum, uncomfortable for debuging)
#define WOKEN_BY_ANOTHER_THREAD 2 |
how was the thread woken? thread was waken by another thread
#define WOKEN_BY_TIMER 1 |
how was the thread woken? was woken by timer (moved from sleeping to runnable threads to be scheduled)
#define WOKEN_UNDEFINED 0 |
how was the thread woken? thread was not waked up yet
typedef struct thread_queue_struct thread_queue_struct_t |
Definition in standart .._t notation
enum _thread_statuses |
Describes actual state of thread in the system
THRS_DISABLED | the thread is not prepared to enter the internal structures |
THRS_READY | the thread is active and is waiting for a processor |
THRS_SLEEPING | the thread is waiting to some time to be woken up |
THRS_SUSPENDED | the thread was suspended on some synchro primitive or by call thread_suspend() |
THRS_ZOMBIE | thread is waiting in the system to be removed (if detached or joined) or to be joined |
enum queue_types |
Thread contains in this time pointers to two queues, one of them is for keeping thread in valid thread queue (VALID) and second for, lets say, actual queue of the thread (GENERAL) This can be queue on synchro primitive or runnable queue
int thread_detach | ( | thread_t | thr | ) |
Detach thread given as parameter.
This function detach thread, so nobody will wait for it, and thread will be removed from the system as possible.
thr | thread to be removed from the system. |
int thread_is_valid | ( | thread_t | thr | ) |
check, if the thread given is or is NOT valid in the system
Walk thrue queue of valid threads and try to find this thread
thr | - thread to be checked |
int thread_join | ( | thread_t | thr | ) |
Join thread given as parameter.
This function join thread X given as parameter. If X is finished, is removed from system, otherwise current thread is suspended until X finishes.
thr | thread to be joinde. |
int thread_join_timeout | ( | thread_t | thr, | |
const unsigned int | usec | |||
) |
Try to join thread given as parameter for fixed time.
This function make an attemtp to join thread given as parameter for maimum time given in parameter.
thr | thread to be joinde. | |
usec | time to wait in useconds |
int thread_kill | ( | thread_t | thr | ) |
@ Stops execution oof given thread Remove thread from runnable threads.
thr | thread to be removed |
void thread_remove | ( | thread_t | t | ) |
free memory of the thread, so remove thread from the system. Thread is not valid any more...
void thread_set_state | ( | thread_t | t, | |
int | state | |||
) |
Set state to the thread (change thread internal structure a do thread queues managements Function is now implemented correctly only for state THRS_READY
void thread_sleep | ( | const unsigned int | sec | ) |
Stops execution of thee thread for time in useconds.
sec | time in seconds to sleep. |
void thread_suspend | ( | void | ) |
curent thread suspends until another thread calls wake_up
void thread_usleep | ( | const unsigned int | usec | ) |
Stops execution of thee thread for time in useconds.
Functio differs if time of sleeping is short and is better to sleep actively and longer time, when function case timer setting for time to be woken up
usec | time in useconds to sleep. |
int thread_wakeup | ( | thread_t | thr | ) |
wake up the thread
thread | to wake up |
void thread_yield | ( | void | ) |
current thread yields one times
thread_t current_thread |
global wariables to store
int living_threads |
global variable to store nr of living threads int he system