From bf03de68ac4e570c79c932d416e264f33ab1d10c Mon Sep 17 00:00:00 2001 From: andreas Date: Fri, 15 Nov 2024 16:52:11 +0100 Subject: [PATCH] call requestHandler in user code outside of the API lock --- lib/usercode/GwUserCode.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/usercode/GwUserCode.cpp b/lib/usercode/GwUserCode.cpp index 211eda9..bf4502b 100644 --- a/lib/usercode/GwUserCode.cpp +++ b/lib/usercode/GwUserCode.cpp @@ -340,17 +340,23 @@ public: virtual void setCalibrationValue(const String &name, double value){ api->setCalibrationValue(name,value); } - virtual bool handleWebRequest(const String &url,AsyncWebServerRequest *req){ - GWSYNCHRONIZED(&localLock); - auto it=webHandlers.find(url); - if (it == webHandlers.end()){ - api->getLogger()->logDebug(GwLog::LOG,"no web handler task=%s url=%s",name.c_str(),url.c_str()); - return false; + virtual bool handleWebRequest(const String &url, AsyncWebServerRequest *req) + { + GwApi::HandlerFunction handler; + { + GWSYNCHRONIZED(&localLock); + auto it = webHandlers.find(url); + if (it == webHandlers.end()) + { + api->getLogger()->logDebug(GwLog::LOG, "no web handler task=%s url=%s", name.c_str(), url.c_str()); + return false; + } + handler = it->second; } - it->second(req); + if (handler) + handler(req); return true; } - }; GwUserCode::GwUserCode(GwApiInternal *api,SemaphoreHandle_t *mainLock){