Merge branch 'bugfix/mdns_incorrect_semaphore_use_v3.2' into 'release/v3.2'

mdns: use binary semaphore instead of mutex when searching (Backport 3.2)

See merge request idf/esp-idf!4478
This commit is contained in:
Angus Gratton 2019-03-14 06:26:51 +08:00
commit 4849d7ae90
2 changed files with 7 additions and 12 deletions

View File

@ -3074,7 +3074,7 @@ static void _mdns_search_free(mdns_search_once_t * search)
free(search->instance);
free(search->service);
free(search->proto);
vSemaphoreDelete(search->lock);
vSemaphoreDelete(search->done_semaphore);
free(search);
}
@ -3090,8 +3090,8 @@ static mdns_search_once_t * _mdns_search_init(const char * name, const char * se
}
memset(search, 0, sizeof(mdns_search_once_t));
search->lock = xSemaphoreCreateMutex();
if (!search->lock) {
search->done_semaphore = xSemaphoreCreateBinary();
if (!search->done_semaphore) {
free(search);
return NULL;
}
@ -3130,8 +3130,6 @@ static mdns_search_once_t * _mdns_search_init(const char * name, const char * se
search->started_at = xTaskGetTickCount() * portTICK_PERIOD_MS;
search->next = NULL;
xSemaphoreTake(search->lock, 0);
return search;
}
@ -3142,7 +3140,7 @@ static void _mdns_search_finish(mdns_search_once_t * search)
{
search->state = SEARCH_OFF;
queueDetach(mdns_search_once_t, _mdns_server->search_once, search);
xSemaphoreGive(search->lock);
xSemaphoreGive(search->done_semaphore);
}
/**
@ -4148,7 +4146,7 @@ void mdns_free()
free(h->instance);
free(h->service);
free(h->proto);
vSemaphoreDelete(h->lock);
vSemaphoreDelete(h->done_semaphore);
if (h->result) {
mdns_query_results_free(h->result);
}
@ -4543,7 +4541,7 @@ esp_err_t mdns_query(const char * name, const char * service, const char * proto
_mdns_search_free(search);
return ESP_ERR_NO_MEM;
}
xSemaphoreTake(search->lock, portMAX_DELAY);
xSemaphoreTake(search->done_semaphore, portMAX_DELAY);
*results = search->result;
_mdns_search_free(search);

View File

@ -115,9 +115,6 @@
#define PCB_STATE_IS_ANNOUNCING(s) (s->state > PCB_PROBE_3 && s->state < PCB_RUNNING)
#define PCB_STATE_IS_RUNNING(s) (s->state == PCB_RUNNING)
#define MDNS_SEARCH_LOCK() xSemaphoreTake(_mdns_server->search.lock, portMAX_DELAY)
#define MDNS_SEARCH_UNLOCK() xSemaphoreGive(_mdns_server->search.lock)
#ifndef HOOK_MALLOC_FAILED
#define HOOK_MALLOC_FAILED ESP_LOGE(TAG, "Cannot allocate memory (line: %d, free heap: %d bytes)", __LINE__, esp_get_free_heap_size());
#endif
@ -318,7 +315,7 @@ typedef struct mdns_search_once_s {
uint32_t started_at;
uint32_t sent_at;
uint32_t timeout;
SemaphoreHandle_t lock;
SemaphoreHandle_t done_semaphore;
uint16_t type;
uint8_t max_results;
uint8_t num_results;