switch to Recursive Mutex and non-blocking

This commit is contained in:
2024-12-13 22:29:48 +01:00
parent 8205253b5a
commit 1af962190e
6 changed files with 88 additions and 36 deletions

View File

@ -205,7 +205,7 @@ void taskMetrics(void *pvParameters)
void vSetMetrics(sMetric *paMetrics, uint16_t u16Size)
{
if (xSemaphoreTake(xMutexAccessMetricResponse, (TickType_t)100) == pdTRUE)
if (xSemaphoreTakeRecursive(xMutexAccessMetricResponse, pdMS_TO_TICKS(5000)) == pdTRUE)
{
memset(caHtmlResponse, 0, strlen(caHtmlResponse));
for (uint16_t u16Index = 0U; u16Index < u16Size; u16Index++)
@ -217,7 +217,7 @@ void vSetMetrics(sMetric *paMetrics, uint16_t u16Size)
strcat(caHtmlResponse, caValueBuffer);
strcat(caHtmlResponse, "\n");
}
xSemaphoreGive(xMutexAccessMetricResponse);
xSemaphoreGiveRecursive(xMutexAccessMetricResponse);
}
else
{
@ -314,10 +314,10 @@ void connect_wifi(void)
esp_err_t get_metrics_handler(httpd_req_t *req)
{
if (xSemaphoreTake(xMutexAccessMetricResponse, (TickType_t)100) == pdTRUE)
if (xSemaphoreTakeRecursive(xMutexAccessMetricResponse, pdMS_TO_TICKS(5000)) == pdTRUE)
{
esp_err_t err = httpd_resp_send(req, caHtmlResponse, HTTPD_RESP_USE_STRLEN);
xSemaphoreGive(xMutexAccessMetricResponse);
xSemaphoreGiveRecursive(xMutexAccessMetricResponse);
return err;
}
else
@ -339,12 +339,12 @@ httpd_handle_t setup_server(void)
.handler = get_metrics_handler,
.user_ctx = NULL};
xMutexAccessMetricResponse = xSemaphoreCreateBinary();
xMutexAccessMetricResponse = xSemaphoreCreateRecursiveMutex();
if (xMutexAccessMetricResponse == NULL)
{
ESP_LOGE(TAG, "Unable to create mutex for metric response");
}
xSemaphoreGive(xMutexAccessMetricResponse);
xSemaphoreGiveRecursive(xMutexAccessMetricResponse);
if (httpd_start(&server, &config) == ESP_OK)
{