mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 02:48:37 +08:00
xtensa/esp32: 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.
adapt based on: 10a1d17a85
This commit is contained in:
parent
c55c2511ad
commit
da845163a3
1 changed files with 9 additions and 0 deletions
|
@ -348,6 +348,7 @@ static struct esp32_spiflash_s g_esp32_spiflash1_encrypt =
|
|||
static mutex_t g_lock = NXMUTEX_INITIALIZER;
|
||||
#ifdef CONFIG_ESP32_SPI_FLASH_SUPPORT_PSRAM_STACK
|
||||
static struct work_s g_work;
|
||||
static mutex_t g_work_lock = NXMUTEX_INITIALIZER;
|
||||
#endif
|
||||
|
||||
static volatile bool g_flash_op_can_start = false;
|
||||
|
@ -1717,6 +1718,12 @@ static int esp32_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, esp32_spiflash_work, &work_arg, 0);
|
||||
if (ret == 0)
|
||||
{
|
||||
|
@ -1724,6 +1731,8 @@ static int esp32_async_op(enum spiflash_op_code_e opcode,
|
|||
ret = work_arg.ret;
|
||||
}
|
||||
|
||||
nxmutex_unlock(&g_work_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue