gustavonihei commented on code in PR #6197: URL: https://github.com/apache/incubator-nuttx/pull/6197#discussion_r880520920
########## arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c: ########## @@ -1339,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); Review Comment: > Why not align the risc-v esp32 wifi driver to xtensa's one first? And then @donghengqaz @gustavonihei could apply the same improvement if needed. The ESP32 driver leaks the semaphore, it fails to call the destructor when required. The ESP32-C3 driver fixed that behavior on https://github.com/apache/incubator-nuttx/pull/4092. Unfortunately reverting that patch will be a regression. ########## arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c: ########## @@ -1339,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); Review Comment: > Why not align the risc-v esp32 wifi driver to xtensa's one first? And then @donghengqaz @gustavonihei could apply the same improvement if needed. The **ESP32** driver leaks the semaphore, it fails to call the destructor when required. The **ESP32-C3** driver fixed that behavior on https://github.com/apache/incubator-nuttx/pull/4092. Unfortunately reverting that patch will be a regression. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org