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

@@ -353,8 +353,9 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
USER_PRINTLN(F("deserializeSegment() image: strip is still drawing effects."));
strip.waitUntilIdle();
}
// WLEDMM protect against parallel drawing
if (esp32SemTake(busDrawMux, 250) == pdTRUE) { // WLEDMM first acquire draw mutex, start of critical section
seg.startFrame();
// WLEDMM end
// set brightness immediately and disable transition
transitionDelayTemp = 0;
@@ -404,6 +405,9 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
set = 0;
}
}
esp32SemGive(busDrawMux); // release lock
} // end of critical section
seg.map1D2D = oldMap1D2D; // restore mapping
strip.trigger(); // force segment update
suspendStripService = oldLock; // restore previous lock status