and mutex for all

revised mutex and critical section handling for segment drawing
- simplified code with macros (no more #if ESP32 ... #endif)
- remove some critical sections (prevents interrupt stalling)
- added mutex to functions that change the list of segments
- added mutexes to all (potential) background drawing code
- use recursive mutexes to prevent accidental self-locking of tasks
This commit is contained in:
Frank
2025-12-20 17:13:52 +01:00
parent e5a3942610
commit 7df63db744
5 changed files with 83 additions and 61 deletions

View File

@@ -477,8 +477,8 @@ void WLED::setup()
init_math(); // WLEDMM: pre-calculate some lookup tables
#ifdef ARDUINO_ARCH_ESP32
busDrawMux = xSemaphoreCreateBinary(); // WLEDMM prevent concurrent running of strip.show and strip.service
xSemaphoreGive(busDrawMux); // init semaphores to initially allow drawing
busDrawMux = xSemaphoreCreateRecursiveMutex(); // WLEDMM prevent concurrent running of strip.show and strip.service
xSemaphoreGiveRecursive(busDrawMux); // init semaphores to initially allow drawing
#endif
#ifdef ARDUINO_ARCH_ESP32
@@ -1103,16 +1103,16 @@ bool WLED::initEthernet()
void WLED::initConnection()
{
#ifdef WLED_ENABLE_WEBSOCKETS
ws.onEvent(wsEvent);
#endif
#ifdef ARDUINO_ARCH_ESP32
unsigned long t_wait = millis();
while(strip.isUpdating() && (millis() - t_wait < 86)) delay(1); // WLEDMM try to catch a moment when strip is idle
//if (strip.isUpdating()) USER_PRINTLN("WLED::initConnection: strip still updating.");
#endif
#ifdef WLED_ENABLE_WEBSOCKETS
ws.onEvent(wsEvent);
#endif
WiFi.disconnect(true); // close old connections
#ifdef ESP8266
WiFi.setPhyMode(force802_3g ? WIFI_PHY_MODE_11G : WIFI_PHY_MODE_11N);