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 consists 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 setting up and switching stacks. | |
Data Structures | |
struct | mt_thread |
Macros | |
#define | MT_OK |
No error. More... | |
Functions | |
void | mt_exec (struct mt_thread *thread) |
Execute parts of a thread. More... | |
void | mt_exit (void) |
Exit a thread. More... | |
void | mt_init (void) |
Initializes the multithreading library. More... | |
void | mt_remove (void) |
Uninstalls library and cleans up. More... | |
void | mt_start (struct mt_thread *thread, void(*function)(void *), void *data) |
Starts a multithreading thread. More... | |
void | mt_stop (struct mt_thread *thread) |
Stop a thread. More... | |
void | mt_yield (void) |
Voluntarily give up the processor. More... | |
#define MT_OK |
No error.
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.
thread | A pointer to a struct mt_thread block that must be allocated by the caller. |
References MT_STATE_READY, MT_STATE_RUNNING, 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.
References MT_STATE_EXITED, mtarch_yield(), NULL, and mt_thread::state.
void mt_init | ( | void | ) |
Initializes the multithreading library.
References mtarch_init().
void mt_remove | ( | void | ) |
Uninstalls library and cleans up.
References mtarch_remove().
void mt_start | ( | struct mt_thread * | thread, |
void(*)(void *) | function, | ||
void * | data | ||
) |
Starts a multithreading thread.
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. |
References MT_STATE_READY, mtarch_start(), mt_thread::state, and mt_thread::thread.
void mt_stop | ( | struct mt_thread * | thread | ) |
Stop a thread.
This function is called by a Contiki process in order to clean up a thread. The struct mt_thread block may then be discarded by the caller.
thread | A pointer to a struct mt_thread block that must be allocated by the caller. |
References mtarch_stop(), and mt_thread::thread.
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.
References MT_STATE_READY, mtarch_pstop(), mtarch_yield(), NULL, and mt_thread::state.