@@ -24,8 +24,7 @@ struct recurrent_fn_t
24
24
recurrent_fn_t * mNext = nullptr ;
25
25
mRecFuncT mFunc ;
26
26
esp8266::polledTimeout::periodicFastUs callNow;
27
- const std::atomic<bool >* wakeupToken = nullptr ;
28
- bool wakeupTokenCmp = false ;
27
+ std::function<bool ()> alarm = nullptr ;
29
28
recurrent_fn_t (esp8266::polledTimeout::periodicFastUs interval) : callNow(interval) { }
30
29
};
31
30
@@ -86,8 +85,8 @@ bool schedule_function (const std::function<void(void)>& fn)
86
85
return true ;
87
86
}
88
87
89
- bool schedule_recurrent_function_us (const std::function<bool (void )>& fn, uint32_t repeat_us,
90
- const std::atomic <bool>* wakeupToken )
88
+ bool schedule_recurrent_function_us (const std::function<bool (void )>& fn,
89
+ uint32_t repeat_us, std::function <bool()> alarm )
91
90
{
92
91
assert (repeat_us < decltype (recurrent_fn_t ::callNow)::neverExpires); // ~26800000us (26.8s)
93
92
@@ -100,8 +99,7 @@ bool schedule_recurrent_function_us(const std::function<bool(void)>& fn, uint32_
100
99
101
100
item->mFunc = fn;
102
101
item->mNext = nullptr ;
103
- item->wakeupToken = wakeupToken;
104
- item->wakeupTokenCmp = wakeupToken && wakeupToken->load ();
102
+ item->alarm = std::move (alarm);
105
103
106
104
esp8266::InterruptLock lockAllInterruptsInThisScope;
107
105
@@ -174,8 +172,7 @@ void run_scheduled_recurrent_functions()
174
172
do
175
173
{
176
174
done = current == stop;
177
- const bool wakeupToken = current->wakeupToken && current->wakeupToken ->load ();
178
- const bool wakeup = current->wakeupTokenCmp != wakeupToken;
175
+ const bool wakeup = current->alarm && current->alarm ();
179
176
bool callNow = current->callNow ;
180
177
181
178
if ((wakeup || callNow) && !current->mFunc ())
0 commit comments