From 3b195a25cc436e50d432042ec176550f4dbb9bba Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Tue, 24 May 2022 10:11:07 +0300 Subject: [PATCH] risc-v/espc32c3: Remove dependency to group->tg_exit Allocate the the semaphore storage from TLS instead --- .../risc-v/src/esp32c3/esp32c3_wifi_adapter.c | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c b/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c index 7cb6cf3ea94ba..37d353b16c286 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c +++ b/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c @@ -410,6 +410,11 @@ uint8_t esp_crc8(const uint8_t *p, uint32_t len); static bool g_wifi_irq_bind; +/* Wi-Fi thread private data */ + +static int g_wifi_thread_key; +static bool g_wifi_tkey_init; + /* Wi-Fi event private data */ static struct work_s g_wifi_evt_work; @@ -1335,20 +1340,23 @@ static int IRAM_ATTR wifi_is_in_isr(void) static void *esp_thread_semphr_get(void) { int ret; - int i; void *sem; - struct tcb_s *tcb = this_task(); - struct task_group_s *group = tcb->group; - for (i = 0; i < CONFIG_SCHED_EXIT_MAX; i++) + if (!g_wifi_tkey_init) { - if (group->tg_exit[i].func.on == esp_thread_semphr_free) + ret = tls_alloc(NULL); + if (ret < 0) { - break; + wlerr("Failed to create pthread key\n"); + return NULL; } + + g_wifi_thread_key = ret; + g_wifi_tkey_init = true; } - if (i >= CONFIG_SCHED_EXIT_MAX) + sem = (void *)tls_get_value(g_wifi_thread_key); + if (!sem) { sem = esp_semphr_create(1, 0); if (!sem) @@ -1357,6 +1365,14 @@ static void *esp_thread_semphr_get(void) return NULL; } + ret = tls_set_value(g_wifi_thread_key, (uintptr_t)sem); + if (ret < 0) + { + wlerr("Failed to set specific\n"); + esp_semphr_delete(sem); + return NULL; + } + ret = on_exit(esp_thread_semphr_free, sem); if (ret < 0) { @@ -1365,10 +1381,6 @@ static void *esp_thread_semphr_get(void) return NULL; } } - else - { - sem = group->tg_exit[i].arg; - } return sem; }