Skip to content

Commit b5b6dc9

Browse files
committed
Yield in scheduling loop to prevent wdt elapsing.
1 parent bfe8739 commit b5b6dc9

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

cores/esp32/Schedule.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
21
#include "Schedule.h"
32
#include "PolledTimeout.h"
43
#ifdef ESP8266
54
#include "interrupts.h"
5+
#include "coredecls.h"
66
#else
77
#include <mutex>
88
#endif
@@ -29,9 +29,9 @@ namespace {
2929
bool IRAM_ATTR schedule_function_us(std::function<bool(void)>&& fn, uint32_t repeat_us, schedule_e policy)
3030
{
3131
scheduled_fn_t item;
32+
item.policy = policy;
3233
item.mFunc = std::move(fn);
3334
if (repeat_us) item.callNow.reset(repeat_us);
34-
item.policy = policy;
3535
return schedule_queue.push(std::move(item));
3636
}
3737

@@ -70,15 +70,24 @@ void run_scheduled_functions(schedule_e policy)
7070
return;
7171
}
7272
fence = true;
73-
74-
// run scheduled function:
75-
// - when its schedule policy allows it anytime
76-
// - or if we are called at loop() time
77-
// and
78-
// - its time policy allows it
7973
}
80-
schedule_queue.for_each_requeue([policy](scheduled_fn_t& func)
74+
75+
esp8266::polledTimeout::periodicFastMs yieldNow(100); // yield every 100ms
76+
77+
// run scheduled function:
78+
// - when its schedule policy allows it anytime
79+
// - or if we are called at loop() time
80+
// and
81+
// - its time policy allows it
82+
schedule_queue.for_each_requeue([policy, &yieldNow](scheduled_fn_t& func)
8183
{
84+
if (yieldNow) {
85+
#ifdef ESP8266
86+
cont_yield(g_pcont);
87+
#else
88+
yield();
89+
#endif
90+
}
8291
return
8392
(func.policy != SCHEDULE_FUNCTION_WITHOUT_YIELDELAYCALLS && policy != SCHEDULE_FUNCTION_FROM_LOOP)
8493
|| !func.callNow

0 commit comments

Comments
 (0)