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

Function modTimersExecute

modules/base/timer/pebble/timer.c:75–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75void modTimersExecute(void)
76{
77 ModdablePebbleAppState state = (ModdablePebbleAppState)app_state_get_js_memory_api_context();
78
79 modCriticalSectionDeclare;
80 uint32_t now = modMilliseconds();
81 modTimer walker;
82#if MOD_TASKS
83 uintptr_t task = modTaskGetCurrent();
84#endif
85
86 // determine who is firing this time (timers added during this call are ineligible)
87 modCriticalSectionBegin();
88 for (walker = state->timers; NULL != walker; walker = walker->next) {
89 if (walker->flags & (kTimerFlagUnscheduled | kTimerFlagFire))
90 continue;
91 int32_t delta = walker->triggerTime - now;
92 if (delta <= 0)
93 walker->flags |= kTimerFlagFire;
94 }
95
96 // service eligible callbacks. then reschedule (repeating) or remove (one shot)
97 for (walker = state->timers; NULL != walker; ) {
98 if (!(walker->flags & kTimerFlagFire)
99#if MOD_TASKS
100 || (task != walker->task)
101#endif
102 ) {
103 walker = walker->next;
104 continue;
105 }
106
107 walker->flags &= ~kTimerFlagFire;
108 walker->triggerTime += walker->repeatInterval; // non-drifting... OK?
109
110 walker->useCount++;
111 modCriticalSectionEnd();
112 (walker->cb)(walker, walker->refcon, walker->refconSize);
113 modCriticalSectionBegin();
114 walker->useCount--;
115
116 if ((walker->useCount <= 0) || (0 == walker->repeatInterval)) {
117 modCriticalSectionEnd();
118 modTimerRemove(walker);
119 modCriticalSectionBegin();
120 walker = state->timers;
121 continue;
122 }
123
124 walker = walker->next;
125 }
126
127 modCriticalSectionEnd();
128}
129
130int modTimersNext(void)
131{

Callers 1

modTimerEventedExecuteFunction · 0.70

Calls 2

modMillisecondsFunction · 0.85
modTimerRemoveFunction · 0.70

Tested by

no test coverage detected