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

Multi-threading library
[Contiki system]


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

 Architecture support for multi-threading
 The Contiki multi-threading library requires some architecture specific support for seting up and switching stacks.
 Multi-threading library convenience functions
 The Contiki multi-threading library has an interface that might be hard to use.

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)
 Execute parts of a thread.
void mt_exec_event (struct mt_thread *thread, process_event_t s, process_data_t data)
 Post an event to a thread.
void mt_yield (void)
 Voluntarily give up the processor.
void mt_post (struct process *p, process_event_t ev, process_data_t data)
 Post an event to another process.
void mt_wait (process_event_t *ev, process_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  ) 
 

Execute parts of a thread.

This function is called by a Contiki process and runs 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.

Definition at line 82 of file mt.c.

References MT_STATE_PEEK, MT_STATE_READY, MT_STATE_RUNNING, mtarch_exec(), mt_thread::state, and mt_thread::thread.

void mt_exec_event struct mt_thread thread,
process_event_t  s,
process_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.

Definition at line 104 of file mt.c.

References mt_thread::dataptr, mt_thread::evptr, MT_STATE_PEEK, MT_STATE_RUNNING, MT_STATE_WAITING, mtarch_exec(), mt_thread::state, and mt_thread::thread.

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.

Definition at line 96 of file mt.c.

References MT_STATE_EXITED, mtarch_yield(), NULL, and mt_thread::state.

Referenced by mtp_exit().

void mt_post struct process p,
process_event_t  ev,
process_data_t  data
 

Post an event 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:
p The process receiving the signal, or PROCESS_BROADCAST for a broadcast event.
ev The event to be posted.
data A pointer to a message that is to be delivered together with the signal.

Definition at line 134 of file mt.c.

References process_post().

void mt_start struct mt_thread thread,
void(*)(void *)  function,
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.

Definition at line 72 of file mt.c.

References MT_STATE_READY, mtarch_start(), mt_thread::state, and mt_thread::thread.

Referenced by mtp_start().

void mt_wait process_event_t ev,
process_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.

Parameters:
ev A pointer to a process_event_t variable. The variable will be filled with the number event that woke the thread.
data A pointer to a process_data_t variable. The variable will be filled with the data associated with the event that woke the thread.

Definition at line 147 of file mt.c.

References mt_thread::dataptr, mt_thread::evptr, MT_STATE_WAITING, mtarch_yield(), NULL, and mt_thread::state.

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.

Definition at line 120 of file mt.c.

References MT_STATE_READY, mtarch_yield(), NULL, and mt_thread::state.


Generated on Thu Jun 22 17:45:43 2006 for Contiki 2.x by  doxygen 1.4.4