From 9509bdcd66c59c7f715774a9434eb39c727039d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Villac=C3=ADs=20Lasso?= Date: Sat, 2 Jan 2021 17:43:33 -0500 Subject: [PATCH] Compare task handles instead of opaque undocumented symbols Based on commit 9b98550f64000b937db9567b69e1275feccf1f0f of dumbfixes branch of 0xFEEDC0DE64 fork of ESPAsyncWebServer. The AsyncWebLock class tries to prevent self-deadlock by comparing the current task with the task currently holding the lock (if any). Use documented task handle values and APIs instead of grabbing undocumented external symbols for this. --- src/AsyncWebSynchronization.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AsyncWebSynchronization.h b/src/AsyncWebSynchronization.h index 0f76815..0591ea1 100644 --- a/src/AsyncWebSynchronization.h +++ b/src/AsyncWebSynchronization.h @@ -44,7 +44,7 @@ class AsyncWebLock { private: SemaphoreHandle_t _lock; - mutable void *_lockedBy; + mutable TaskHandle_t _lockedBy{}; public: AsyncWebLock() { @@ -61,10 +61,10 @@ public: } bool lock() const { - extern void *pxCurrentTCB; - if (_lockedBy != pxCurrentTCB) { + const auto currentTask = xTaskGetCurrentTaskHandle(); + if (_lockedBy != currentTask) { xSemaphoreTake(_lock, portMAX_DELAY); - _lockedBy = pxCurrentTCB; + _lockedBy = currentTask; return true; } return false;