components/mdns: use semaphore instead of task notification bits (IDFGH-9380)

Component should not alter the task notification bits of the calling task.
This commit is contained in:
Viktor Babrian 2023-02-14 11:43:02 +01:00 committed by David Cermak
parent 7894f032f6
commit 0050fa940c
2 changed files with 13 additions and 4 deletions

View File

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

View File

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