thread.c File Reference

Implementation of the threads. More...

#include "thread.h"
#include "errnums.h"
#include "malloc.h"
#include "offset.h"
#include "tqueue.h"
#include "sched.h"
#include "int.h"
#include "debug.h"
#include "io.h"
#include "timers.h"

Functions

unsigned thread_get_wakeup_time_in_ticks (thread_t thread)
int __thread_alloc_memory (thread_t *thr)
void __thread_free_memory (thread_t thread)
void thread_queue_struct_init (thread_queue_struct_t queue)
int __thread_set_state (thread_t thread, int state)
thread_t thread_create_system (void(*start)(void), int status)
void thread_remove (thread_t t)
void thread_set_state (thread_t t, int state)
void __thread_dprint (thread_t thr)
int thread_create (thread_t *thread_ptr, void(*thread_start)(void *), void *data)
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_detach (thread_t thr)
 Detach thread given as parameter.
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.
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.
int thread_is_valid (thread_t thr)
 check, if the thread given is or is NOT valid in the system
thread_t thread_get_current (void)

Variables

int living_threads
char * thread_status [6] = {"d", "r", "sl", "su", "z"}
thread_t current_thread
thread_t idle_thread
int thread_id_counter = 0


Detailed Description

Implementation of the threads.

Threads are implemented as a structure containing all needed things to store context. What is litle bit strange is, that each thread has one timer used for wakeing up from state sleeping of the thread. Function usleep differrs if time is short enought to sleep actively (compare registers only) or yield and let some other thread do something "usefull". In system are couted living threads (system thread, sleeping threads, suspended threads, not zombie). For detail info look at thread.h, definition of the structure thread and sched.c for commnets, how scheduling is done

See also:
sched.c

thread.h

This file is based on Kalisto, Development Kernel copyrighted (c) to Distributed Systems Research Group MFF UK, Czech republic.

Function Documentation

int __thread_alloc_memory ( thread_t *  thr  ) 

Alloc memory for new thread.

Parameters:
pointer to thread to allocate memory for.
Returns:
EOK on succes or ENOMEM on memory lack problem

void __thread_free_memory ( thread_t  thread  ) 

Free all the memmory allocated for the thread...

int __thread_set_state ( thread_t  thread,
int  state 
)

FIXMEE, neni kompletni, jen to co jsme potrebovali...

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.

Parameters:
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

Parameters:
thr - thread to be checked
Returns:
EINVAL in case thread is not valid, EOK else.

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.

Parameters:
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.

Parameters:
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.

Parameters:
thr thread to be removed
Returns:
EINVAL on invalid thread id, EOK else

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.

Parameters:
sec time in seconds to sleep.
Returns:
EINVAL in case thread is not valid, EOK else.

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

Parameters:
usec time in useconds to sleep.
Returns:
EINVAL in case thread is not valid, EOK else.

int thread_wakeup ( thread_t  thr  ) 

wake up the thread

Parameters:
thread to wake up
Returns:
EINVAL on invalid thread identifier, EOK else

void thread_yield ( void   ) 

current thread yields one times


Variable Documentation

thread_t current_thread

global wariables to store

int living_threads

global variable to store nr of living threads int he system

int thread_id_counter = 0

queue to store all threads living in system


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