Skip to content

Commit 10cf967

Browse files
authored
Fix issue with tasks not getting handled at startup (#2972)
Issue #2971 revealed a problem with the task queue where the `onReady` callback never gets called. The callback gets queued but the event loop is created afterwards and lacked a 'kick' to the tcpip thread to start message processing. This bug has been present since PR #2913.
1 parent 1c00c6c commit 10cf967

File tree

1 file changed

+24
-8
lines changed
  • Sming/Arch/Esp32/Components/esp32/src

1 file changed

+24
-8
lines changed

Sming/Arch/Esp32/Components/esp32/src/tasks.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ void sming_task_loop(void*)
2626
tcpip_callback_msg* callbackMessage;
2727
volatile bool eventQueueFlag;
2828

29+
/**
30+
* @brief Process all messages in the Sming event queue
31+
* Called in the context of the tcpip message thread.
32+
*/
2933
void tcpip_message_handler(void*)
3034
{
3135
eventQueueFlag = false;
@@ -35,6 +39,22 @@ void tcpip_message_handler(void*)
3539
}
3640
}
3741

42+
/**
43+
* @brief Kick the tcpip message handling thread so we get a callback
44+
* @retval bool Woken flag, true if a message was queued, false for no action
45+
*/
46+
bool tcpip_kick_thread()
47+
{
48+
// If queue isn't empty and we haven't already asked for a tcpip callback, do that now
49+
if(xQueueIsQueueEmptyFromISR(eventQueue) == pdFALSE && !eventQueueFlag) {
50+
eventQueueFlag = true;
51+
auto err = tcpip_callbackmsg_trycallback_fromisr(callbackMessage);
52+
return (err == ERR_NEED_SCHED);
53+
}
54+
55+
return false;
56+
}
57+
3858
#endif
3959

4060
} // namespace
@@ -82,6 +102,9 @@ void start_sming_task_loop()
82102

83103
callbackMessage = tcpip_callbackmsg_new(tcpip_callback_fn(tcpip_message_handler), nullptr);
84104

105+
// There may be messages already queued
106+
tcpip_kick_thread();
107+
85108
#endif
86109
}
87110

@@ -103,14 +126,7 @@ bool IRAM_ATTR system_os_post(uint8_t prio, os_signal_t sig, os_param_t par)
103126
// Message loop not yet active
104127
return true;
105128
}
106-
// If queue isn't empty and we haven't already asked for a tcpip callback, do that now
107-
if(xQueueIsQueueEmptyFromISR(eventQueue) == pdFALSE && !eventQueueFlag) {
108-
eventQueueFlag = true;
109-
auto err = tcpip_callbackmsg_trycallback_fromisr(callbackMessage);
110-
woken = (err == ERR_NEED_SCHED);
111-
} else {
112-
woken = false;
113-
}
129+
woken = tcpip_kick_thread();
114130
#endif
115131

116132
portYIELD_FROM_ISR_ARG(woken);

0 commit comments

Comments
 (0)