![]() |
embedded system library for e-puck
1.0.1
A redesigned API library for the e-puck robot platform
|
Go to the source code of this file.
Macros | |
#define | EL_PROCESS_MAX_NUM 7 |
#define | EL_PROCESS void |
Typedefs | |
typedef void(* | el_process )(void *) |
Functions | |
el_index | el_launch_process (el_process func, void *arg) |
execute a function in a process More... | |
void | el_process_wait (el_time t_ms) |
wait for a period of time More... | |
void | el_process_wait_fraction (unsigned int num, unsigned int den) |
wait for a period of time specified as a fraction More... | |
void | el_process_cooperate () |
Introduce an atomic wait so other processes can be executed. More... | |
void | el_process_resume (el_index process_idx) |
finish the waiting period of a process immediately More... | |
void | el_kill_process (el_index process_idx) |
kill the process (the abnormal way to end a process) More... | |
el_index | el_get_local_process_index () |
get index of the process where this function is called More... | |
el_index el_launch_process | ( | el_process | func, |
void * | arg | ||
) |
execute a function in a process
func | the pointer to the function to be executed (entry function) |
arg | an arguments passed to the function to be executed |
This function can execute a function (entry function) in a process with the given argument (as "func(arg);"). Maxmum number of processes is 7.
The entry function must be a function that takes a void pointer or a el_handle
as the argument and returns void. For example:
void el_process_wait | ( | el_time | t_ms | ) |
wait for a period of time
t_ms | time in millisecond |
This function induces a time delay. It can only be used in a process.
void el_process_wait_fraction | ( | unsigned int | num, |
unsigned int | den | ||
) |
wait for a period of time specified as a fraction
num | numerator of the time in seconds. |
den | denominator of the time in seconds. |
This function induces a time delay of (num/den) seconds in a process.
void el_process_cooperate | ( | ) |
Introduce an atomic wait so other processes can be executed.
This function introduce an atomic delay, which give other processes a chance to execute. Once this process get a chance to execute again, it will continue execute. Therefore, unlike "el_process_wait", "el_process_cooperate" does not cause a notable time delay. It can be used in polling mechanism inside a process. For example, the following scheme can be used to waiting for a condition to become true:
There could be a section in a process that simply cost large amount of computation and thus make the process alone occupy the CPU for a long time. "el_process_cooperate" should be called in appropriate positions in a process of such types. For instance, in a triple-nested loop with a loop body that is also time-costly, add a "el_process_cooperate();" after the middle loop:
void el_process_resume | ( | el_index | process_idx | ) |
finish the waiting period of a process immediately
process_idx | the index of the process |
This function can make a process in el_process_wait finish the waiting period immediately.
void el_kill_process | ( | el_index | process_idx | ) |
kill the process (the abnormal way to end a process)
process_idx | the index of the process to be killed |
This function can be used to forcefully stop a process while it is waiting (e.g. when it entered el_process_wait or el_process_cooperate). Unlike the relation between 'create' and 'delete', a launched process are not supposed to be killed. A process ends normally when its entry function returns (reach the end of the function).
Note: Killing a process causes all the local variables within to be lost. If a dynamically created object is referable only through such a local variable, a memory leak is resulted (unable to 'free'/'delete' through the pointer/handle anymore).
el_index el_get_local_process_index | ( | ) |
get index of the process where this function is called
When this function is not called within a process, it returns -1.