thread.h File Reference

Heder file for implementation of threads. More...

#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


Detailed Description

Heder file for implementation of threads.

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


Define Documentation

#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   \
)
The main CP0 status configuration for kernel threads. Switch to the kernel mode, enable all interrupts and mark coprocessor 0 as usable (this is not necessary because cp0 is available in the kernel mode automatically).

#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 Documentation

typedef struct thread_queue_struct thread_queue_struct_t

Definition in standart .._t notation


Enumeration Type Documentation

enum _thread_statuses

Describes actual state of thread in the system

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


Function Documentation

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


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