xtensa/esp32s3: add lock for async operation work

g_work as singleton can be changed by context switching,
but previous one async operation have not finished yet.
This commit is contained in:
Gao Feng 2024-12-09 15:01:05 +08:00 committed by Xiang Xiao
parent d1786507b6
commit 10a1d17a85

View file

@ -205,6 +205,7 @@ static mutex_t g_lock = NXMUTEX_INITIALIZER;
#ifdef CONFIG_ESP32S3_SPI_FLASH_SUPPORT_PSRAM_STACK
static struct work_s g_work;
static mutex_t g_work_lock = NXMUTEX_INITIALIZER;
#endif
/****************************************************************************
@ -335,6 +336,12 @@ static int esp32s3_async_op(enum spiflash_op_code_e opcode,
.sem = NXSEM_INITIALIZER(0, 0)
};
ret = nxmutex_lock(&g_work_lock);
if (ret < 0)
{
return ret;
}
ret = work_queue(LPWORK, &g_work, esp32s3_spiflash_work, &work_arg, 0);
if (ret == 0)
{
@ -342,6 +349,8 @@ static int esp32s3_async_op(enum spiflash_op_code_e opcode,
ret = work_arg.ret;
}
nxmutex_unlock(&g_work_lock);
return ret;
}
#endif