A periodic task, implementing a microthread.
More...
#include <Process.h>
|
| virtual void | onUpdate (uint64_t msecs)=0 |
| |
| virtual void | onInit (uint64_t msecs) |
| |
| virtual bool | onKill () |
| |
|
virtual void | onPause () |
| | Called when a process is paused.
|
| |
|
virtual void | onWakeUp () |
| | Called when process is woken up.
|
| |
| virtual void | killDone () |
| |
A periodic task, implementing a microthread.
Once the process is inserted in a mel::tasking::ProcessScheduler (usually done through a Runnable via mel::tasking::Runnable::post or mel::tasking::Runnable::execute) the update() (private) member function will be called. because this class is abstract, a concrete Process must implement the function onUpdate function to code its custom behaviour. The task will be executed as time intervals, given by the period (getPeriod) until is killed (see kill)
◆ EProcessState
| Enumerator |
|---|
| PREPARED | Process created but not executed.
|
| INITIATED | executing process normally
|
| ASLEEP | sleeping. Waiting for a wakeup
|
| PREPARED_TO_DIE | it's going to die, but process manager doesn't discard it yet
|
| TRYING_TO_KILL | sending kill signal but no accepted yet
|
| KILLING_WAITING_FOR_SCHEDULED | switched and no shceduled yet
|
| DEAD | process is out of process manager
|
◆ ESwitchResult
Reason why the process returns from context switch.
| Enumerator |
|---|
| ESWITCH_OK | return from context switch was ok
|
| ESWITCH_WAKEUP | return from context switch was because a wakeup
|
| ESWITCH_ERROR | switch couldn't be done
|
| ESWITCH_KILL | return from context switch because a kill
|
◆ Process()
| mel::tasking::Process::Process |
( |
unsigned short |
capacity = 0 | ) |
|
constructor
- Parameters
-
| capacity | Initial stack capacity,in bytes. A value of 0 means no stack precreated. In any case, stack grows as needed |
◆ getDead()
| bool mel::tasking::Process::getDead |
( |
| ) |
const |
|
inline |
◆ getElapsedTime()
| unsigned int mel::tasking::Process::getElapsedTime |
( |
| ) |
const |
returns time elapsed during this iteration
◆ getLastUpdateTime()
| uint64_t mel::tasking::Process::getLastUpdateTime |
( |
| ) |
const |
|
inline |
- Returns
- time when task was executed in last iteration, when onUpdate is called:
- Note
- context switches or waits inside code doesn't modify update time.
◆ getPeriod()
| unsigned int mel::tasking::Process::getPeriod |
( |
| ) |
const |
|
inline |
get period (milliseconds)
check if process is going to die
◆ kill()
| void mel::tasking::Process::kill |
( |
bool |
force = false | ) |
|
Mark this process to be eliminated by the process manager.
Internally, kill calls virtual function Process::onKill, which returns true if kill can be acomplished or not. In case of true, then process is put in PREPARED_TO_DIE state, so the scheduler can remove it. In case of false, process is put in a TRYING_TO_KILL state so scheduler will continue to trying to kill it in next iterations. You can know if a process is die checking getDead
- Parameters
-
| [in] | force | if true, then killing is without regarding previous explained process, so Process go inmediately to PREPARED_TO_DIE |
◆ killDone()
| virtual void mel::tasking::Process::killDone |
( |
| ) |
|
|
inlineprotectedvirtual |
called when kill is definitively done
◆ onInit()
| virtual void mel::tasking::Process::onInit |
( |
uint64_t |
msecs | ) |
|
|
inlineprotectedvirtual |
◆ onKill()
| virtual bool mel::tasking::Process::onKill |
( |
| ) |
|
|
inlineprotectedvirtual |
called when process is going to be got out of scheduler and was inited (not in PREPARED state) can be overridden by children
- Returns
- bool. True if kill can be acomplished
Reimplemented in mel::tasking::GenericProcess.
◆ onUpdate()
| virtual void mel::tasking::Process::onUpdate |
( |
uint64_t |
msecs | ) |
|
|
protectedpure virtual |
behaviour function. The main function of a process. MUST be implemented in childs. It's called automatically when elapsed time >= mPeriod
- Parameters
-
Implemented in mel::tasking::GenericProcess.
◆ setPeriod()
| void mel::tasking::Process::setPeriod |
( |
unsigned int |
value | ) |
|
|
inline |
Set the period for this process.
- Parameters
-
| value | the new period (in msecs) |
◆ sleep()
pause current process. To reactivate you must use wakeUp
- Returns
- true if process received kill signal
- See also
- switchProcess for comments
◆ sleepAndDo()
Sleep current process and execute given callable. To reactivate to you must use wakeUp.
- Parameters
-
| [in] | postSleep | functor (signature void(void) ) to execute just in the moment when Process go to sleep |
- Returns
- resulting state of these operation
- See also
- sleep
◆ switchProcess()
| static ESwitchResult mel::tasking::Process::switchProcess |
( |
bool |
continueInmediately | ) |
|
|
static |
Evict current process and will continue executing from the same point the next time is scheduled.
this function is a static one because, in the same way threads work, is the currently executing process which can be evicted in any point of the execution call stack.
- Parameters
-
| continueInmediately | if true, the process will continue executing in the next shceduler cycle, so without respecting the period. |
◆ wait()
| static ESwitchResult mel::tasking::Process::wait |
( |
unsigned int |
msegs | ) |
|
|
static |
- Returns
- true if process received kill signal
- See also
- switchProcess for comments
◆ waitAndDo()
Wait for a given time and execute given callable.
- Parameters
-
| [in] | postWait | functor (signature <void,void>) to execute just in the moment when Process go to sleep |
- Returns
- resulting state of the operation
- See also
- sleep
The documentation for this class was generated from the following file:
- /github/workspace/mel/include/tasking/Process.h