risc-v/esp32c3: Use onexit to free thread private semaphore
This commit is contained in:
parent
906cb8b0f4
commit
f5eaf82c93
@ -38,6 +38,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <irq/irq.h>
|
||||
#include <sched/sched.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/mqueue.h>
|
||||
#include <nuttx/spinlock.h>
|
||||
@ -75,6 +76,10 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_SCHED_ONEXIT
|
||||
# error "on_exit() API must be enabled for deallocating Wi-Fi resources"
|
||||
#endif
|
||||
|
||||
#define MAC_ADDR0_REG (DR_REG_EFUSE_BASE + 0x044)
|
||||
#define MAC_ADDR1_REG (DR_REG_EFUSE_BASE + 0x048)
|
||||
|
||||
@ -396,11 +401,6 @@ uint8_t esp_crc8(const uint8_t *p, uint32_t len);
|
||||
|
||||
static bool g_wifi_irq_bind;
|
||||
|
||||
/* Wi-Fi thread private data */
|
||||
|
||||
static pthread_key_t g_wifi_thread_key;
|
||||
static bool g_wifi_tkey_init;
|
||||
|
||||
/* Wi-Fi sleep private data */
|
||||
|
||||
static uint32_t g_phy_clk_en_cnt;
|
||||
@ -742,7 +742,7 @@ static int esp_int_adpt_cb(int irq, void *context, FAR void *arg)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void esp_thread_semphr_free(void *semphr)
|
||||
static void esp_thread_semphr_free(int status, void *semphr)
|
||||
{
|
||||
if (semphr)
|
||||
{
|
||||
@ -1250,22 +1250,20 @@ 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;
|
||||
|
||||
if (g_wifi_tkey_init)
|
||||
{
|
||||
ret = pthread_key_create(&g_wifi_thread_key, esp_thread_semphr_free);
|
||||
if (ret)
|
||||
{
|
||||
wlerr("ERROR: Failed to create pthread key\n");
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < CONFIG_SCHED_EXIT_MAX; i++)
|
||||
{
|
||||
if (group->tg_exit[i].func.on == esp_thread_semphr_free)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_wifi_tkey_init = true;
|
||||
}
|
||||
|
||||
sem = pthread_getspecific(g_wifi_thread_key);
|
||||
if (!sem)
|
||||
if (i >= CONFIG_SCHED_EXIT_MAX)
|
||||
{
|
||||
sem = esp_semphr_create(1, 0);
|
||||
if (!sem)
|
||||
@ -1274,14 +1272,18 @@ static void *esp_thread_semphr_get(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = pthread_setspecific(g_wifi_thread_key, sem);
|
||||
if (ret)
|
||||
ret = on_exit(esp_thread_semphr_free, sem);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: Failed to set specific\n");
|
||||
wlerr("ERROR: Failed to bind semaphore\n");
|
||||
esp_semphr_delete(sem);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sem = group->tg_exit[i].arg;
|
||||
}
|
||||
|
||||
return sem;
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_PTHREAD_MUTEX_TYPES=y
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_SCHED_LPWORK=y
|
||||
CONFIG_SCHED_ONEXIT=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SIG_DEFAULT=y
|
||||
CONFIG_START_DAY=6
|
||||
|
@ -63,6 +63,7 @@ CONFIG_PTHREAD_MUTEX_TYPES=y
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_LPWORK=y
|
||||
CONFIG_SCHED_ONEXIT=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_SIG_DEFAULT=y
|
||||
|
@ -49,6 +49,7 @@ CONFIG_PTHREAD_MUTEX_TYPES=y
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_LPWORK=y
|
||||
CONFIG_SCHED_ONEXIT=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SIG_DEFAULT=y
|
||||
CONFIG_START_DAY=6
|
||||
|
Loading…
Reference in New Issue
Block a user