Main Page | Modules | Data Structures | File List | Data Fields | Globals | Examples

Multi-threading library


Detailed Description

The event driven Contiki kernel does not provide multi-threading by itself - instead, preemptive multi-threading is implemented as a library that optionally can be linked with applications. This library constists of two parts: a platform independent part, which is the same for all platforms on which Contiki runs, and a platform specific part, which must be implemented specifically for the platform that the multi-threading library should run.


Modules

group Architecture support for multi-threading
group Multi-threading library convenience functions

Defines

#define MT_OK
 No error.


Functions

void mt_init (void)
 Initializes the multithreading library.

void mt_remove (void)
 Uninstalls library and cleans up.

void mt_start (struct mt_thread *thread, void(*function)(void *), void *data)
 Starts a multithreading thread.

void mt_exec (struct mt_thread *thread)
 Start executing a thread.

void mt_exec_event (struct mt_thread *thread, ek_event_t s, ek_data_t data)
 Post an event to a thread.

void mt_yield (void)
 Voluntarily give up the processor.

void mt_post (ek_id_t id, ek_event_t s, ek_data_t data)
 Emit a signal to another process.

void mt_wait (ek_event_t *s, ek_data_t *data)
 Block and wait for an event to occur.

void mt_exit (void)
 Exit a thread.


Function Documentation

void mt_exec struct mt_thread *  thread  ) 
 

Start executing a thread.

This function is called by a Contiki process and starts running a thread. The function does not return until the thread has yielded, or is preempted.

Note:
The thread must first be initialized with the mt_init() function.
Parameters:
thread A pointer to a struct mt_thread block that must be allocated by the caller.

void mt_exec_event struct mt_thread *  thread,
ek_event_t  s,
ek_data_t  data
 

Post an event to a thread.

This function posts an event to a thread. The thread will be scheduled if the thread currently is waiting for the posted event number. If the thread is not waiting for the event, this function does nothing.

Note:
The thread must first be initialized with the mt_init() function.
Parameters:
thread A pointer to a struct mt_thread block that must be allocated by the caller.
s The event that is posted to the thread.
data An opaque pointer to a user specified structure containing additonal information, or NULL if no additional information is needed.

void mt_exit void   ) 
 

Exit a thread.

This function is called from within an executing thread in order to exit the thread. The function never returns.

void mt_post ek_id_t  id,
ek_event_t  s,
ek_data_t  data
 

Emit a signal to another process.

This function is called by a running thread and will emit a signal to another Contiki process. This will cause the currently executing thread to yield.

Parameters:
s The signal to be emitted.
data A pointer to a message that is to be delivered together with the signal.
id The process ID of the receiver of the signal, or EK_ID_ALL for a broadcast signal.

void mt_start struct mt_thread *  thread,
void(*  function)(void *),
void *  data
 

Starts a multithreading thread.

Parameters:
thread Pointer to an mt_thread struct that must have been previously allocated by the caller.
function A pointer to the entry function of the thread that is to be set up.
data A pointer that will be passed to the entry function.

void mt_wait ek_event_t *  s,
ek_data_t *  data
 

Block and wait for an event to occur.

This function can be called by a running thread in order to block and wait for an event. The function returns when an event has occured. The event number and the associated data are placed in the variables pointed to by the function arguments.

void mt_yield void   ) 
 

Voluntarily give up the processor.

This function is called by a running thread in order to give up control of the CPU.


Generated on Wed Jul 6 01:19:06 2005 for Contiki/ESB by doxygen 1.3.6