INOS
|
#include <inos_1ms.h>
Public Types | |
typedef uintptr_t | tIntervalId |
typedef uintptr_t | tTimeoutId |
![]() | |
enum | ETskType { eTskTypeBoot = 0 , eTskTypeResource = 1 , eTskTypeSystem = 2 , eTskTypeApplication = 3 , eTskTypeCommunication = 4 , eTskTypeRealtime = 5 , eTskTypeInterrupt = 6 , eTskTypeBackground = 7 , eTskTypeLua = 8 , eTskTypeTest = 9 , eTskTypeReserved0 = 10 , eTskTypeReserved1 = 11 , eTskTypeUser0 = 12 , eTskTypeUser1 = 13 , eTskTypeUser2 = 14 , eTskTypeUser3 = 15 } |
Task types. | |
Public Member Functions | |
CINOSxmsHandler * | AddHandler (void *aHandler, void *aObject, int32 aMS, bool aActive=true, bool aSingle=false) |
CINOSxmsHandlerFunction * | AddHandler (uintptr_t &aTimeoutId, const CINOSxmsHandlerFunction::tFunction &aFunction, int32 aMS, bool aActive=true, bool aSingle=false) |
void | AddHandler (CINOSxmsHandlerBase *aHandler) |
void | RemoveHandler (CINOSxmsHandlerBase *aHandler, bool aDelete=true) |
void | eAddTimer (uint32 aTimerPtr) |
void | AddTimer (int32 *aTimer) |
int32 | GetTickCount () |
int32 | GetTickDelta (int32 aiTickCount) |
int32 * | GetTickAddress () |
void | SetTickAddress (int32 *apAddress) |
uint32 | GetSystemTicksAtLast1msTick () |
template<typename TFct > | |
void | SetInterval (TFct aFct, uint32 aIntervalMs, tIntervalId &aIntervalId) |
void | ClearInterval (tIntervalId &aIntervalId) |
template<typename TFct > | |
void | SetTimeout (TFct aFct, uint32 aTimeoutMs, tTimeoutId &aTimeoutId) |
void | ClearTimeout (tTimeoutId &aTimeoutId) |
bool | HasHandlers (uint32 auNumber) |
bool | KickExactly (CINOSTask *apSource=0) INOS_COMPILE_OPTIMIZED |
bool | KickSporadically () INOS_COMPILE_OPTIMIZED |
![]() | |
CINOSTask (char *apName=nullptr, uint32 auStackSize=defDefaultStackSize, uint32 auPriority=DF_INOS_TASK_PRIO_LOWEST, bool abFloatingPoint=true, uint32 auTimeSlice=defDefaultTimeSlice, bool abInterruptsDisabled=false, void *apHandler=0, void *apObject=0) | |
Create a task with given properties. One needs to Resume the task after creation to get it running. | |
CINOSTask (std::function< void(void *)> aFunction, void *apParam=nullptr, uint8 auPriority=DF_INOS_TASK_PRIO_LOWEST) | |
Create a task with given properties. One needs to Resume the task after creation to get it running. | |
CINOSTask (const char *apName, std::function< void(void *)> aFunction, void *apParam=nullptr, uint8 auPriority=DF_INOS_TASK_PRIO_LOWEST) | |
Create a task with given properties. One needs to Resume the task after creation to get it running. | |
virtual | ~CINOSTask () |
Destroy task. | |
virtual uint32 | Shutdown (CINOSSync *apSync=DF_INOS_SYNCHRONOUS) |
Shutdown task, used to shutdown a foreign task. | |
virtual uint32 | Join () |
Join task or in other words, wait till it terminates. | |
virtual void | Detach () |
Detach task from parent. One uses this method if one doesn't want this task to be shut down if the parent shuts down. | |
virtual void | Exit () |
Terminate myself. Exit code is INOS_OK or the code previously set with SetExitCode. | |
virtual void | Exit (uint32 auExitCode) |
Terminate myself. | |
virtual void | SetExitCode (uint32 auExitCode) |
Set exit code. | |
virtual uint32 | GetExitCode () |
Get exit code. | |
virtual bool | CheckShutdown () |
Check if a shutdown is pending. | |
virtual void | SetSuspendHook (void *apSuspendHook) |
Set Suspend hook. | |
virtual void | ClrSuspendHook () |
Clear Suspend hook. | |
virtual void * | GetSuspendHook () |
Get Suspend hook if any. | |
INOS_INLINE ETskType | GetTskType () |
Get task type. | |
INOS_INLINE ETskType | SetTskType (ETskType aeType) |
Set task type. | |
Static Public Member Functions | |
static CINOS1ms & | Instance () |
singleton | |
static CINOS1ms * | pInstance () |
Static Public Attributes | |
static CINOSMutex | m_Mutex |
public | |
static uint32 | m_uCoreMask |
core mask | |
Protected Member Functions | |
virtual void | Action () |
Task action loop, needs to be overwritten by the user. For more info, see section Creation. | |
A global 'INOS timing service' running with 1 millisecond resolution. It's intended to register "callbacks", which are called at specific points in time in the future. Such "callbacks" will either be called once or multiple time. Such a "callback" registration (identified by a 'handler'), can temporarily be disabled or permanently unregistered to avoid "callback" calls.
void CINOS1ms::AddHandler | ( | CINOSxmsHandlerBase * | aHandler | ) |
Add a preconstructed handler object. Usually, using the overloaded 'AddHandler' function is the recommended way to create and add new handlers. This one is for more sophisticated use cases
CINOSxmsHandlerFunction * CINOS1ms::AddHandler | ( | uintptr_t & | aTimeoutId, |
const CINOSxmsHandlerFunction::tFunction & | aFunction, | ||
int32 | aMS, | ||
bool | aActive = true , |
||
bool | aSingle = false |
||
) |
Same as AddHandler(void*,void*,int32,bool,bool) but for a C++11 std::function.
Example: Register a C++ lambda that's getting called on every 1 second. auto pHandler = CINOS1ms::Instance().AddHandler(aTokenId, [this]() { ... do whatever needs to be done every second ... }, 1000); ... do whatever ... CIONS1ms::Instance().RemoveHandler(pHandler);
CINOSxmsHandler * CINOS1ms::AddHandler | ( | void * | aHandler, |
void * | aObject, | ||
int32 | aMS, | ||
bool | aActive = true , |
||
bool | aSingle = false |
||
) |
Register "callback" specified by a function address and a this pointer.
aHandler | the function address |
aObject | the 'this' pointer if the callback is a member function. |
aMs | Period by which the "callback" will be called |
aActive | If false, the "callback" is registered, but will not yet be called. Call 'Activate' on the returned object to activate it later. Default is 'true', which means the timer will be active immediately. |
aSingle | By default, the "callback" will be called endlessly, unless the handler will be inactivated or removed. By passing 'true' here, the "callback" will be called exactly once and the handler will then automatically be removed. In that case, the user doesn't need to call RemoveHandler anymore. |
Example:
Register MyCallback being called every second auto pHandler = CINOS1ms::Instance().AddHandler( ClassMemberPointer(CMyClass, MyCallback), this, 1000); ... do whatever ...
finally, remove handler and cleanup resources CINOS1ms::Instance().RemoveHandler(pHandler);
Note that it is allowed to remove the returned handler within the context of "callback" (by calling RemoveHandler).
void CINOS1ms::AddTimer | ( | int32 * | aTimer | ) |
decrement '*aTimer' every ms until it is 0
|
inline |
Cancel a callback registration done by SetInterval. This operation is intended to abort a setup callback. Do not call this function with the same handler id twice as it may in worst case cause another interval callback from getting cancelled as that new interval may have recycled the previous id.
aIntervalId | A valid 'interval id' or zero. |
|
inline |
Cancel a callback registration done by SetTimeout. This operation is intended to abort a setup callback before it actually occurred. Calling it afterwards is forbidden and may in worst case cause another timeout callback from getting cancelled as that new timeout may have recycled the previous id.
aTimeoutId | A valid 'timeout id' or zero. |
void CINOS1ms::eAddTimer | ( | uint32 | aTimerPtr | ) |
Same as AddTimer, but for being registered in the INCO tree. aTimerPtr is expected to be the value of a pointer.
|
inline |
return system ticks at last 1ms tick
|
inline |
return address of 1ms ticker
|
inline |
return actual 1ms timer value
|
inline |
return actual 1ms timer value
|
inline |
return true if at least auNumber of handlers free
If there are 'exact sources', they shall call this function exactly every 1ms. Typical 'exact sources' are field busses.
bool CINOS1ms::KickSporadically | ( | ) |
Shall be called 'sporadically' e.g. by the "Idle" task or from time to time by the scheduler. The caller is responsible to disable interrupts (no core lock is required, as each core has a separate instance of this class). Without such a lock, the 1ms timing would "in average" be much worse, because we could get interrupted in between the "timing calculations" and the "Resume" which would cause the timing calculation to be wrong and ultimately causing that the 1ms task would "in average" run only e.g. every 1.0123ms.
void CINOS1ms::RemoveHandler | ( | CINOSxmsHandlerBase * | aHandler, |
bool | aDelete = true |
||
) |
Remove 'aHandler' from list of handlers. note that it is allowed to remove "itself" while being within the callback function - but it's not allowed to remove any other handlers within that context. (The reason is that we are iterating through the list of all handlers and removing a handler modifies the list while iterating...)
aDelete | If 'true', the handler object will be deleted. If 'false', the object will not be deleted and must either be deleted by the caller to cleanup resources, or can be re-used using AddHandler(). |
|
inline |
Register C++11 std::function that gets called periodically with the specified time.
The function has been inspired by JavaScripts 'SetInterval'.
aIntervalMs | Period time in [ms] by which the function shall be called |
aIntervalId | Input & output parameter, if the incoming value is unequal zero, it is treated as a valid 'id' and the system ensures to cancel the previous setup interval belonging to the id. The output id is the new 'inteval id' that can be passed to ClearInterval. Note that the output value may be equal to what has been passed in (i.e. the id may be reused). |
|
inline |
set address of 1ms ticker
|
inline |
Register C++11 std::function that gets called exactly once after a specified time.
The function has been inspired by JavaScripts 'SetTimeout'.
aTimeoutMs | Time in [ms] after which the function shall be called |
aTimeoutId | Input & output parameter, if the incoming value is unequal zero, it is treated as a valid 'id' and the system ensures to cancel the previous setup timeout belonging to the id. The output id is the new 'timeout id' that can be passed to ClearTimeout. Note that the output value may be equal to what has been passed in (i.e. the id may be reused). |
|
static |
public
creation mutex