mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-22 21:23:07 +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
|
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();
|
sFirst->mFunc();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
// remove function from stack
|
||||||
esp8266::InterruptLock lockAllInterruptsInThisScope;
|
esp8266::InterruptLock lockAllInterruptsInThisScope;
|
||||||
|
|
||||||
auto to_recycle = sFirst;
|
auto to_recycle = sFirst;
|
||||||
sFirst = sFirst->mNext;
|
|
||||||
if (!sFirst)
|
// removing rLast
|
||||||
|
if (sLast == sFirst)
|
||||||
sLast = nullptr;
|
sLast = nullptr;
|
||||||
|
|
||||||
|
sFirst = sFirst->mNext;
|
||||||
|
|
||||||
recycle_fn_unsafe(to_recycle);
|
recycle_fn_unsafe(to_recycle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (yieldNow)
|
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:
|
// this is yield() in cont stack:
|
||||||
esp_schedule();
|
esp_schedule();
|
||||||
cont_yield(g_pcont);
|
cont_yield(g_pcont);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user