mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
Fix issue with functions scheduled from scheduled functions (#6770)
Calling schedule_function() from a scheduled function would result in an infinite loop, because the list traversal would never end.
This commit is contained in:
parent
2f26d94f64
commit
6f3c57b7fa
@ -119,23 +119,33 @@ void run_scheduled_functions()
|
||||
{
|
||||
esp8266::polledTimeout::periodicFastMs yieldNow(100); // yield every 100ms
|
||||
|
||||
while (sFirst)
|
||||
// prevent scheduling of new functions during this run
|
||||
auto stop = sLast;
|
||||
bool done = false;
|
||||
while (sFirst && !done)
|
||||
{
|
||||
done = sFirst == stop;
|
||||
|
||||
sFirst->mFunc();
|
||||
|
||||
{
|
||||
// remove function from stack
|
||||
esp8266::InterruptLock lockAllInterruptsInThisScope;
|
||||
|
||||
auto to_recycle = sFirst;
|
||||
sFirst = sFirst->mNext;
|
||||
if (!sFirst)
|
||||
|
||||
// removing rLast
|
||||
if (sLast == sFirst)
|
||||
sLast = nullptr;
|
||||
|
||||
sFirst = sFirst->mNext;
|
||||
|
||||
recycle_fn_unsafe(to_recycle);
|
||||
}
|
||||
|
||||
if (yieldNow)
|
||||
{
|
||||
// because scheduled function are allowed to last:
|
||||
// because scheduled functions might last too long for watchdog etc,
|
||||
// this is yield() in cont stack:
|
||||
esp_schedule();
|
||||
cont_yield(g_pcont);
|
||||
|
Loading…
x
Reference in New Issue
Block a user