Skip to content

Commit 80b9069

Browse files
committed
requestJSONBufferLock() variable timeout
* default timeout = 1800ms * reduced timeout for ws (300ms)
1 parent 5739a54 commit 80b9069

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

wled00/fcn_declare.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ void sappend(char stype, const char* key, int val);
439439
void sappends(char stype, const char* key, char* val);
440440
void prepareHostname(char* hostname);
441441
bool isAsterisksOnly(const char* str, byte maxLen) __attribute__((pure));
442-
bool requestJSONBufferLock(uint8_t module=255);
442+
bool requestJSONBufferLock(uint8_t module=255, unsigned timeoutMS = 1800);
443443
void releaseJSONBufferLock();
444444
uint8_t extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen);
445445
uint8_t extractModeSlider(uint8_t mode, uint8_t slider, char *dest, uint8_t maxLen, uint8_t *var = nullptr);

wled00/util.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,19 @@ bool isAsterisksOnly(const char* str, byte maxLen)
220220

221221

222222
//threading/network callback details: https://github.com/Aircoookie/WLED/pull/2336#discussion_r762276994
223-
bool requestJSONBufferLock(uint8_t module)
223+
bool requestJSONBufferLock(uint8_t module, unsigned timeoutMS)
224224
{
225225
bool haveLock = false;
226226
#ifdef ARDUINO_ARCH_ESP32
227227
// We use a recursive mutex to prevent parallel JSON writes from parallel tasks.
228228
// This also fixes hanging up for the full timeout interval in cases when the contention is from the same task.
229229
// 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
230+
if (esp32SemTake(jsonBufferLockMutex, timeoutMS) == pdTRUE) haveLock = true; // WLEDMM must wait longer than suspendStripService timeout = 1500ms
231231
#else
232232
// 8266: only wait in case that can_yield() tells us we can yield and delay
233233
if (can_yield()) {
234234
unsigned long now = millis();
235-
while (jsonBufferLock && millis()-now < 1800) delay(1); // wait for fraction for buffer lock // WLEDMM must wait longer than suspendStripService timeout = 1500ms
235+
while (jsonBufferLock && millis()-now < timeoutMS) delay(1); // wait for fraction for buffer lock // WLEDMM must wait longer than suspendStripService timeout = 1500ms
236236
if (!jsonBufferLock) haveLock = true;
237237
}
238238
#endif

wled00/ws.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
4949
}
5050

5151
bool verboseResponse = false;
52-
if (!requestJSONBufferLock(11)) {
52+
if (!requestJSONBufferLock(11, 300)) {
5353
client->text(F("{\"error\":3}")); // ERR_NOBUF
5454
return;
5555
}
@@ -138,7 +138,7 @@ void sendDataWs(AsyncWebSocketClient * client)
138138
DEBUG_PRINTF("sendDataWs\n");
139139
if (!ws.count()) return;
140140

141-
if (!requestJSONBufferLock(12)) {
141+
if (!requestJSONBufferLock(12, 300)) {
142142
if (client) {
143143
client->text(F("{\"error\":3}")); // ERR_NOBUF
144144
} else {

0 commit comments

Comments
 (0)