INOS
inos_1ms.h
Go to the documentation of this file.
1//******************************************************************************
27//******************************************************************************
28
29#if !defined( __INOS_1MS_H )
30#define __INOS_1MS_H
31
32//--------------------------------------------------------------------------
33//--- includes -----------------------------------------------------------------
34//------------------------------------------------------------------------------
35#include <functional>
36
37//------------------------------------------------------------------------------
38//--- class definitions --------------------------------------------------------
39//------------------------------------------------------------------------------
40
41// --- CINOSxmsHandler ---------------------------------------------------------
42
43class CINOS1ms;
44
52#include <cinosbushooks.h>
54{
55 //--- user interface ---------------------------------------------------
56
57 public:
58 // constructor
59 CINOSxmsHandlerBase(int32 aInterval, bool aActive=true, bool aSingle=false);
60 virtual ~CINOSxmsHandlerBase() {}
61 // activate handler
62 void Activate()
63 { Enable(); };
64 // deactivate handler
65 void Deactivate()
66 { Disable(); };
67 // set new interval and return old interval
68 long SetInterval(long aiInterval)
69 {
72 return iInterval;
73 };
75 long GetTimer() const
76 { return GetIntervalAct(); };
78 virtual void Call() = 0;
79
80 //--- internals --------------------------------------------------------
81
82 // private members
83 private :
84
85
86 // allow dynamic object handling (new/delete)
88};
89
93{
94 //--- user interface ---------------------------------------------------
95
96 public:
97 // constructor
98 CINOSxmsHandler(void* aHandler, void* aObject, int32 aInterval, bool aActive=true, bool aSingle=false)
100 {
101 // init members
102 pHandler = (void(*)(void)) aHandler;
103 pObject = aObject;
104 }
105 virtual ~CINOSxmsHandler() {}
107 virtual void Call() { INOSCallClassMember_0(pObject, (void *) pHandler); }
108
109 //--- internals --------------------------------------------------------
110
111 // private members
112 private :
113 void* pObject; // pointer to object (if member function)
114 void (*pHandler)(); // pointer to handler
115
116 // allow dynamic object handling (new/delete)
118};
119
123{
124 //--- user interface ---------------------------------------------------
125
126 public:
127 typedef std::function<void()> tFunction;
128 // constructor
129 CINOSxmsHandlerFunction(tFunction aFunction, int32 aInterval, bool aActive=true, bool aSingle=false)
131 m_Function(aFunction)
132 {
133 }
134 virtual ~CINOSxmsHandlerFunction() {}
136 virtual void Call() { m_Function(); }
137
138 //--- internals --------------------------------------------------------
139
140 // private members
141 private :
142 const tFunction m_Function;
143
144 // allow dynamic object handling (new/delete)
147};
148
149// --- CINOS1ms handler --------------------------------------------------------
150
174class CINOS1ms : public CINOSTask
175{
176 //--- user interface ---------------------------------------------------
177
178 public:
210 CINOSxmsHandler* AddHandler(void* aHandler, void* aObject, int32 aMS, bool aActive=true, bool aSingle=false);
224 uintptr_t& aTimeoutId, const CINOSxmsHandlerFunction::tFunction& aFunction, int32 aMS,
225 bool aActive=true, bool aSingle=false);
241
244 void eAddTimer(uint32 aTimerPtr);
246 void AddTimer(int32* aTimer);
249 { return g_pTarget->GetTickCount();};
252 { return aiTickCount-g_pTarget->GetTickCount();};
255 { return g_pTarget->GetTickAddress();};
258 { m_pTickAddress = apAddress; *m_pTickAddress = 0; };
261 { return GetResumeTicks();};
262
263 typedef uintptr_t tIntervalId;
278 template<typename TFct>
289 if (aIntervalId) {
290 auto p = reinterpret_cast<CINOSxmsHandlerBase*>(aIntervalId);
291 RemoveHandler(p, true);
293 }
294 }
295
296 typedef uintptr_t tTimeoutId;
311 template<typename TFct>
313 AddHandler(aTimeoutId, aFct, aTimeoutMs, true/*active*/, true/*single*/);
314 }
322 if (aTimeoutId) {
323 auto p = reinterpret_cast<CINOSxmsHandlerBase*>(aTimeoutId);
324 RemoveHandler(p, true);
326 }
327 }
328
331 { return m_Hooks.HasHooks(auNumber); }
332
333 //--- internals --------------------------------------------------------
334
335 // private members
336 private :
337 CINOSBusHooks m_Hooks;
338 /* list of timers */
340
343 int32* m_pTickAddress = 0;
346 CINOSTask* m_pExactSource = nullptr;
348 uint32 m_uTicksFor1ms = 0;
356 enum {
357 eThresholdMultiplier = 10
358 };
359 uint32 m_uTicksThresholdToSwitchSelected = 0;
362 uint32 m_uCountOfReselection = 0;
365 volatile uint32 m_uMostRecentlyResumedTicks = 0;
368 uint32 m_uOverrun = 0;
372 uint32 m_uWakeUpCount = 0;
373
375 CINOSxmsHandlerBase* m_pHandlerErr{};
376
377 // constructor
378 public:
379 CINOS1ms();
380 ~CINOS1ms();
386 bool KickExactly(CINOSTask* apSource = 0) INOS_COMPILE_OPTIMIZED;
398 bool KickSporadically() INOS_COMPILE_OPTIMIZED;
399
400 // protected members
401 protected:
402 // main task loop
404
405 private:
408 void iIdleKicker();
409
411 public:
418 static CINOS1ms* pInstance();
419};
420
421//--------------------------------------------------------------------------
422// 1ms handler
423//--------------------------------------------------------------------------
424
427#define pINOS1ms CINOS1ms::pInstance()
430#define g_pINOS1ms CINOS1ms::pInstance()
431
432#endif // __INOS_1MS_H
433
The CINOSBusHook class.
#define DECLARE_DYNAMIC_PLACEMENT(aClass)
Definition cinospartitionmemory.h:348
#define DECLARE_DYNAMIC(aClass)
Definition cinospartitionmemory.h:328
Definition inos_1ms.h:175
void RemoveHandler(CINOSxmsHandlerBase *aHandler, bool aDelete=true)
bool KickExactly(CINOSTask *apSource=0) INOS_COMPILE_OPTIMIZED
uint32 GetSystemTicksAtLast1msTick()
Definition inos_1ms.h:260
void AddHandler(CINOSxmsHandlerBase *aHandler)
int32 GetTickCount()
Definition inos_1ms.h:248
bool KickSporadically() INOS_COMPILE_OPTIMIZED
void ClearInterval(tIntervalId &aIntervalId)
Definition inos_1ms.h:288
void SetTimeout(TFct aFct, uint32 aTimeoutMs, tTimeoutId &aTimeoutId)
Definition inos_1ms.h:312
void SetInterval(TFct aFct, uint32 aIntervalMs, tIntervalId &aIntervalId)
Definition inos_1ms.h:279
static CINOSMutex m_Mutex
public
Definition inos_1ms.h:413
int32 GetTickDelta(int32 aiTickCount)
Definition inos_1ms.h:251
static CINOS1ms & Instance()
singleton
virtual void Action()
Task action loop, needs to be overwritten by the user. For more info, see section Creation.
static uint32 m_uCoreMask
core mask
Definition inos_1ms.h:415
CINOSxmsHandler * AddHandler(void *aHandler, void *aObject, int32 aMS, bool aActive=true, bool aSingle=false)
void eAddTimer(uint32 aTimerPtr)
bool HasHandlers(uint32 auNumber)
Definition inos_1ms.h:330
CINOSxmsHandlerFunction * AddHandler(uintptr_t &aTimeoutId, const CINOSxmsHandlerFunction::tFunction &aFunction, int32 aMS, bool aActive=true, bool aSingle=false)
void AddTimer(int32 *aTimer)
int32 * GetTickAddress()
Definition inos_1ms.h:254
void SetTickAddress(int32 *apAddress)
Definition inos_1ms.h:257
void ClearTimeout(tTimeoutId &aTimeoutId)
Definition inos_1ms.h:321
Definition cinosbushooks.h:145
void SetIntervalCmd(uint32 auInterval)
Set hook interval.
Definition cinosbushooks.h:163
uint32 GetIntervalAct() const
Get actual hook interval counter.
Definition cinosbushooks.h:180
uint32 GetIntervalCmd()
Get commanded hook interval.
Definition cinosbushooks.h:173
uint32 Disable()
Disable hook.
uint32 Enable()
Enable hook.
Definition cinosbushooks.h:479
bool HasHooks(uint32 auNumber)
Check whether the given number of hooks are still available.
Definition cinosbushooks.h:880
Definition cinosmcmodule.h:1900
Definition cinosmutex.h:36
Definition cinostask.h:52
Definition inos_1ms.h:54
long GetTimer() const
Definition inos_1ms.h:75
virtual void Call()=0
Definition inos_1ms.h:123
virtual void Call()
Definition inos_1ms.h:136
Definition inos_1ms.h:93
virtual void Call()
Definition inos_1ms.h:107