MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / modTimersExecute

Function modTimersExecute

modules/base/timer/mc/timer.c:51–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49static modTimer gTimers = NULL;
50
51void modTimersExecute(void)
52{
53 modCriticalSectionDeclare;
54 uint32_t now = modMilliseconds();
55 modTimer walker;
56#if MOD_TASKS
57 uintptr_t task = modTaskGetCurrent();
58#endif
59
60 // determine who is firing this time (timers added during this call are ineligible)
61 modCriticalSectionBegin();
62 for (walker = gTimers; NULL != walker; walker = walker->next) {
63 if (walker->flags & (kTimerFlagUnscheduled | kTimerFlagFire))
64 continue;
65 int32_t delta = walker->triggerTime - now;
66 if (delta <= 0)
67 walker->flags |= kTimerFlagFire;
68 }
69
70 // service eligible callbacks. then reschedule (repeating) or remove (one shot)
71 for (walker = gTimers; NULL != walker; ) {
72 if (!(walker->flags & kTimerFlagFire)
73#if MOD_TASKS
74 || (task != walker->task)
75#endif
76 ) {
77 walker = walker->next;
78 continue;
79 }
80
81 walker->flags &= ~kTimerFlagFire;
82 walker->triggerTime += walker->repeatInterval; // non-drifting... OK?
83
84 walker->useCount++;
85 modCriticalSectionEnd();
86 (walker->cb)(walker, walker->refcon, walker->refconSize);
87 modCriticalSectionBegin();
88 walker->useCount--;
89
90 if ((walker->useCount <= 0) || (0 == walker->repeatInterval)) {
91 modCriticalSectionEnd();
92 modTimerRemove(walker);
93 modCriticalSectionBegin();
94 walker = gTimers;
95 continue;
96 }
97
98 walker = walker->next;
99 }
100
101 modCriticalSectionEnd();
102}
103
104int modTimersNext(void)
105{

Callers 1

workerLoopFunction · 0.50

Calls 2

modMillisecondsFunction · 0.85
modTimerRemoveFunction · 0.70

Tested by

no test coverage detected