@@ -119,15 +119,15 @@ bool schedule_recurrent_function_us(const std::function<bool(void)>& fn,
119
119
item->mFunc = fn;
120
120
item->alarm = alarm ;
121
121
122
+ esp8266::InterruptLock lockAllInterruptsInThisScope;
123
+
122
124
// prevent new item overwriting an already expired rTarget.
123
- const int32_t rRemaining = rTarget - micros ();
124
- if (!rFirst || (rRemaining > 0 && static_cast <uint32_t >(rRemaining ) > item->callNow .remaining ()))
125
+ const int32_t remaining = rTarget - micros ();
126
+ if (!rFirst || (remaining > 0 && static_cast <uint32_t >(remaining ) > item->callNow .remaining ()))
125
127
{
126
128
rTarget = micros () + item->callNow .remaining ();
127
129
}
128
130
129
- esp8266::InterruptLock lockAllInterruptsInThisScope;
130
-
131
131
if (rLast)
132
132
{
133
133
rLast->mNext = item;
@@ -145,8 +145,8 @@ uint32_t get_scheduled_recurrent_delay_us()
145
145
{
146
146
if (!rFirst) return ~static_cast <uint32_t >(0 );
147
147
// handle already expired rTarget.
148
- const int32_t rRemaining = rTarget - micros ();
149
- return (rRemaining > 0 ) ? static_cast <uint32_t >(rRemaining ) : 0 ;
148
+ const int32_t remaining = rTarget - micros ();
149
+ return (remaining > 0 ) ? static_cast <uint32_t >(remaining ) : 0 ;
150
150
}
151
151
152
152
void run_scheduled_functions ()
@@ -209,12 +209,18 @@ void run_scheduled_recurrent_functions()
209
209
fence = true ;
210
210
}
211
211
212
- rTarget = micros () + current-> callNow . remaining () ;
212
+ decltype (rLast) stop ;
213
213
recurrent_fn_t * prev = nullptr ;
214
- // prevent scheduling of new functions during this run
215
- auto stop = rLast;
216
-
217
214
bool done;
215
+
216
+ {
217
+ esp8266::InterruptLock lockAllInterruptsInThisScope;
218
+
219
+ // prevent scheduling of new functions during this run
220
+ stop = rLast;
221
+ rTarget = micros () + (~static_cast <decltype (micros ())>(0 ) >> 1 );
222
+ }
223
+
218
224
do
219
225
{
220
226
done = current == stop;
@@ -246,14 +252,16 @@ void run_scheduled_recurrent_functions()
246
252
}
247
253
else
248
254
{
249
- prev = current ;
250
- current = current-> mNext ;
255
+ esp8266::InterruptLock lockAllInterruptsInThisScope ;
256
+
251
257
// prevent current item overwriting an already expired rTarget.
252
- const int32_t rRemaining = rTarget - micros ();
253
- if (rRemaining > 0 && static_cast <uint32_t >(rRemaining ) > current->callNow .remaining ())
258
+ const int32_t remaining = rTarget - micros ();
259
+ if (remaining > 0 && static_cast <uint32_t >(remaining ) > current->callNow .remaining ())
254
260
{
255
261
rTarget = micros () + current->callNow .remaining ();
256
262
}
263
+ prev = current;
264
+ current = current->mNext ;
257
265
}
258
266
259
267
if (yieldNow)
0 commit comments