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.
This commit is contained in:
Alex Villacís Lasso
2021-01-02 17:43:33 -05:00
parent a8840bc652
commit 9509bdcd66

View File

@@ -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;