Skip to content

Fix issue with functions scheduled from scheduled functions #6770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions cores/esp8266/Schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down