prevent race conditions in realtimeLock / exitRealtime
This commit is contained in:
@@ -203,10 +203,15 @@ void realtimeLock(uint32_t timeoutMs, byte md)
|
|||||||
realtimeMode = md;
|
realtimeMode = md;
|
||||||
|
|
||||||
// WLEDMM cache current "main segment"
|
// WLEDMM cache current "main segment"
|
||||||
Segment& mainSegRef = strip.getMainSegment();
|
if (esp32SemTake(busDrawMux, 1200) == pdTRUE) { // stupid long timeout, but we don't want to wait forever
|
||||||
theMainSeg = &mainSegRef; //convert from reference to pointer
|
// WLEDMM protect against parallel cache updates from different tasks
|
||||||
theMainSegLength = realtimeOverride ? 0 : theMainSeg->length();
|
// positive side-effect: this also introduces a wait if other bus activities are happeening in parallel
|
||||||
theStripLength = realtimeOverride ? 0 : strip.getLengthTotal();
|
Segment& mainSegRef = strip.getMainSegment();
|
||||||
|
theMainSeg = &mainSegRef; //convert from reference to pointer
|
||||||
|
theMainSegLength = realtimeOverride ? 0 : theMainSeg->length();
|
||||||
|
theStripLength = realtimeOverride ? 0 : strip.getLengthTotal();
|
||||||
|
esp32SemGive(busDrawMux);
|
||||||
|
}
|
||||||
|
|
||||||
if (realtimeOverride) return;
|
if (realtimeOverride) return;
|
||||||
if (arlsForceMaxBri) strip.setBrightness(scaledBri(255), true);
|
if (arlsForceMaxBri) strip.setBrightness(scaledBri(255), true);
|
||||||
@@ -228,9 +233,13 @@ void exitRealtime() {
|
|||||||
strip.show(); // possible fix for #3589
|
strip.show(); // possible fix for #3589
|
||||||
}
|
}
|
||||||
// WLEDMM invalide cached main segment pointer and length
|
// WLEDMM invalide cached main segment pointer and length
|
||||||
theMainSeg = nullptr;
|
if (esp32SemTake(busDrawMux, 200) == pdTRUE) {
|
||||||
theMainSegLength = 0;
|
// WLEDMM protect against parallel cache updates from different tasks
|
||||||
theStripLength = 0;
|
theMainSeg = nullptr;
|
||||||
|
theMainSegLength = 0;
|
||||||
|
theStripLength = 0;
|
||||||
|
esp32SemGive(busDrawMux);
|
||||||
|
}
|
||||||
busses.invalidateCache(false); // WLEDMM
|
busses.invalidateCache(false); // WLEDMM
|
||||||
USER_PRINTLN(F("exitRealtime() realtime mode ended."));
|
USER_PRINTLN(F("exitRealtime() realtime mode ended."));
|
||||||
updateInterfaces(CALL_MODE_WS_SEND);
|
updateInterfaces(CALL_MODE_WS_SEND);
|
||||||
|
|||||||
Reference in New Issue
Block a user