Skip to content

Commit d6e603f

Browse files
committed
Fix optimistic_yield to not yield on every call after a loop runs for x us, but yield only every x us between optimistic_yield calls.
1 parent a8515a7 commit d6e603f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cores/esp8266/core_esp8266_main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ cont_t* g_pcont __attribute__((section(".noinit")));
5858
static os_event_t s_loop_queue[LOOP_QUEUE_SIZE];
5959

6060
/* Used to implement optimistic_yield */
61-
static uint32_t s_micros_at_task_start;
61+
static uint32_t s_micros_since_yield_start;
6262

6363
/* For ets_intr_lock_nest / ets_intr_unlock_nest
6464
* Max nesting seen by SDK so far is 2.
@@ -116,6 +116,7 @@ extern "C" void __yield() {
116116
if (can_yield()) {
117117
esp_schedule();
118118
esp_yield_within_cont();
119+
s_micros_since_yield_start = system_get_time();
119120
}
120121
else {
121122
panic();
@@ -126,7 +127,7 @@ extern "C" void yield(void) __attribute__ ((weak, alias("__yield")));
126127

127128
extern "C" void optimistic_yield(uint32_t interval_us) {
128129
if (can_yield() &&
129-
(system_get_time() - s_micros_at_task_start) > interval_us)
130+
(system_get_time() - s_micros_since_yield_start) > interval_us)
130131
{
131132
yield();
132133
}
@@ -183,7 +184,7 @@ static void loop_wrapper() {
183184

184185
static void loop_task(os_event_t *events) {
185186
(void) events;
186-
s_micros_at_task_start = system_get_time();
187+
s_micros_since_yield_start = system_get_time();
187188
cont_run(g_pcont, &loop_wrapper);
188189
if (cont_check(g_pcont) != 0) {
189190
panic();

0 commit comments

Comments
 (0)