From 565eee12a044c13e21000d6bc17d38191fc32354 Mon Sep 17 00:00:00 2001 From: Konstantin Kondrashov Date: Sat, 15 Feb 2020 13:14:08 +0800 Subject: [PATCH] lwip: Add to sys_arch_protect() a check that the mutex is created before use if not then creates it Closes: https://github.com/espressif/esp-idf/issues/944 Closes: https://github.com/espressif/esp-idf/issues/3931 Closes: WIFI-1019 --- components/lwip/port/esp32/freertos/sys_arch.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/lwip/port/esp32/freertos/sys_arch.c b/components/lwip/port/esp32/freertos/sys_arch.c index c9d5b361c..9319fa9f2 100644 --- a/components/lwip/port/esp32/freertos/sys_arch.c +++ b/components/lwip/port/esp32/freertos/sys_arch.c @@ -423,8 +423,10 @@ sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize void sys_init(void) { - if (ERR_OK != sys_mutex_new(&g_lwip_protect_mutex)) { - ESP_LOGE(TAG, "sys_init: failed to init lwip protect mutex\n"); + if (!g_lwip_protect_mutex) { + if (ERR_OK != sys_mutex_new(&g_lwip_protect_mutex)) { + ESP_LOGE(TAG, "sys_init: failed to init lwip protect mutex\n"); + } } // Create the pthreads key for the per-thread semaphore storage @@ -465,6 +467,9 @@ sys_now(void) sys_prot_t sys_arch_protect(void) { + if (unlikely(!g_lwip_protect_mutex)) { + sys_mutex_new(&g_lwip_protect_mutex); + } sys_mutex_lock(&g_lwip_protect_mutex); return (sys_prot_t) 1; }