Skip to content

Commit

Permalink
risc-v/espc32c3: Remove dependency to group->tg_exit
Browse files Browse the repository at this point in the history
Allocate the the semaphore storage from TLS instead
  • Loading branch information
pussuw committed May 24, 2022
1 parent b577187 commit 3b195a2
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand All @@ -1365,10 +1381,6 @@ static void *esp_thread_semphr_get(void)
return NULL;
}
}
else
{
sem = group->tg_exit[i].arg;
}

return sem;
}
Expand Down

0 comments on commit 3b195a2

Please sign in to comment.