You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
while (jsonBufferLock && millis()-now < 1100) delay(1); // wait for fraction for buffer lock
225
+
bool haveLock = false;
226
+
#ifdef ARDUINO_ARCH_ESP32
227
+
// We use a recursive mutex to prevent parallel JSON writes from parallel tasks.
228
+
// This also fixes hanging up for the full timeout interval in cases when the contention is from the same task.
229
+
// see https://github.com/wled/WLED/pull/4089 for more details.
230
+
if (esp32SemTake(jsonBufferLockMutex, 1800) == pdTRUE) haveLock = true; // WLEDMM must wait longer than suspendStripService timeout = 1500ms
231
+
#else
232
+
// 8266: only wait in case that can_yield() tells us we can yield and delay
233
+
if (can_yield()) {
234
+
unsignedlong now = millis();
235
+
while (jsonBufferLock && millis()-now < 1800) delay(1); // wait for fraction for buffer lock // WLEDMM must wait longer than suspendStripService timeout = 1500ms
236
+
if (!jsonBufferLock) haveLock = true;
237
+
}
238
+
#endif
228
239
229
-
if (jsonBufferLock) {
240
+
if (jsonBufferLock || !haveLock) {
241
+
if (haveLock) esp32SemGive(jsonBufferLockMutex); // we got the mutex, but jsonBufferLock says the opposite -> give up
242
+
delay(10); // WLEDMM experimental: small extra wait, in case that esp32 cores temporarily disagree on the value of jsonBufferLock
230
243
USER_PRINT(F("ERROR: Locking JSON buffer failed! (still locked by "));
231
244
USER_PRINT(jsonBufferLock);
232
245
USER_PRINTLN(")");
233
246
returnfalse; // waiting time-outed
234
247
}
235
248
249
+
// success - we keep holding the mutex until releaseJSONBufferLock()
236
250
jsonBufferLock = module ? module : 255;
237
251
DEBUG_PRINT(F("JSON buffer locked. ("));
238
252
DEBUG_PRINT(jsonBufferLock);
@@ -250,6 +264,7 @@ void releaseJSONBufferLock()
250
264
DEBUG_PRINTLN(")");
251
265
fileDoc = nullptr;
252
266
jsonBufferLock = 0;
267
+
esp32SemGive(jsonBufferLockMutex); // return the mutex
0 commit comments