From 0050fa940c7d719a5f7f182e7b51bfdfb2a49fad Mon Sep 17 00:00:00 2001 From: Viktor Babrian Date: Tue, 14 Feb 2023 11:43:02 +0100 Subject: [PATCH] components/mdns: use semaphore instead of task notification bits (IDFGH-9380) Component should not alter the task notification bits of the calling task. --- components/mdns/mdns.c | 15 ++++++++++++--- components/mdns/private_include/mdns_private.h | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/components/mdns/mdns.c b/components/mdns/mdns.c index 6a5c7b1097..b658b16ea1 100644 --- a/components/mdns/mdns.c +++ b/components/mdns/mdns.c @@ -4354,7 +4354,7 @@ static void _mdns_execute_action(mdns_action_t * action) _mdns_server->hostname = action->data.hostname_set.hostname; _mdns_self_host.hostname = action->data.hostname_set.hostname; _mdns_restart_all_pcbs(); - xTaskNotifyGive(action->data.hostname_set.calling_task); + xSemaphoreGive(_mdns_server->action_sema); break; case ACTION_INSTANCE_SET: _mdns_send_bye_all_pcbs_no_instance(false); @@ -4808,6 +4808,13 @@ esp_err_t mdns_init(void) err = ESP_ERR_NO_MEM; goto free_lock; } + + _mdns_server->action_sema = xSemaphoreCreateBinary(); + if (!_mdns_server->action_sema) { + err = ESP_ERR_NO_MEM; + goto free_queue; + } + if ((err = esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL)) != ESP_OK) { goto free_event_handlers; } @@ -4855,6 +4862,8 @@ free_event_handlers: #if CONFIG_ETH_ENABLED esp_event_handler_unregister(ETH_EVENT, ESP_EVENT_ANY_ID, &event_handler); #endif + vSemaphoreDelete(_mdns_server->action_sema); +free_queue: vQueueDelete(_mdns_server->action_queue); free_lock: vSemaphoreDelete(_mdns_server->lock); @@ -4908,6 +4917,7 @@ void mdns_free(void) } free(h); } + vSemaphoreDelete(_mdns_server->action_sema); vSemaphoreDelete(_mdns_server->lock); free(_mdns_server); _mdns_server = NULL; @@ -4934,13 +4944,12 @@ esp_err_t mdns_hostname_set(const char * hostname) } action->type = ACTION_HOSTNAME_SET; action->data.hostname_set.hostname = new_hostname; - action->data.hostname_set.calling_task = xTaskGetCurrentTaskHandle(); if (xQueueSend(_mdns_server->action_queue, &action, (portTickType)0) != pdPASS) { free(new_hostname); free(action); return ESP_ERR_NO_MEM; } - xTaskNotifyWait(0, 0, NULL, portMAX_DELAY); + xSemaphoreTake(_mdns_server->action_sema, portMAX_DELAY); return ESP_OK; } diff --git a/components/mdns/private_include/mdns_private.h b/components/mdns/private_include/mdns_private.h index 059d1ad252..bc937ff176 100644 --- a/components/mdns/private_include/mdns_private.h +++ b/components/mdns/private_include/mdns_private.h @@ -385,6 +385,7 @@ typedef struct mdns_server_s { mdns_srv_item_t * services; SemaphoreHandle_t lock; QueueHandle_t action_queue; + SemaphoreHandle_t action_sema; mdns_tx_packet_t * tx_queue_head; mdns_search_once_t * search_once; esp_timer_handle_t timer_handle; @@ -395,7 +396,6 @@ typedef struct { union { struct { char * hostname; - xTaskHandle calling_task; } hostname_set; char * instance; struct {