esp_hw_support: Fix misuse of spinlocks as critical sections

Spinlocks themselves do not constitute critical sections as after a spinlock is acquired, interrupts
can remain enabled. However, there are some places where spinlocks are used direclty instead of using
the portMUX_TYPE and portENTER_CRITICAL_...() APIs. This commit fixes those calls.
This commit is contained in:
Darian Leung 2022-07-28 17:22:02 +08:00
parent e7e350d439
commit 05ff1039dc
2 changed files with 5 additions and 5 deletions

View File

@ -53,7 +53,7 @@ static esp_usb_console_cb_t s_tx_cb;
static void *s_cb_arg;
#ifdef CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF
static spinlock_t s_write_lock = SPINLOCK_INITIALIZER;
static portMUX_TYPE s_write_lock = portMUX_INITIALIZER_UNLOCKED;
void esp_usb_console_write_char(char c);
#define ISR_FLAG ESP_INTR_FLAG_IRAM
#else
@ -399,11 +399,11 @@ void esp_usb_console_write_char(char c)
}
static inline void write_lock_acquire(void)
{
spinlock_acquire(&s_write_lock, SPINLOCK_WAIT_FOREVER);
portENTER_CRITICAL_SAFE(&s_write_lock);
}
static inline void write_lock_release(void)
{
spinlock_release(&s_write_lock);
portEXIT_CRITICAL_SAFE(&s_write_lock);
}
#else // CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF

View File

@ -61,7 +61,7 @@ typedef struct {
event_select_args_t *select_args;
_lock_t lock;
// only for event fds that support ISR.
spinlock_t data_spin_lock;
portMUX_TYPE data_spin_lock;
} event_context_t;
esp_vfs_id_t s_eventfd_vfs_id = -1;
@ -421,7 +421,7 @@ int eventfd(unsigned int initval, int flags)
fd = i;
s_events[i].fd = i;
s_events[i].support_isr = support_isr;
spinlock_initialize(&s_events[i].data_spin_lock);
portMUX_INITIALIZE(&s_events[i].data_spin_lock);
if (support_isr) {
portENTER_CRITICAL(&s_events[i].data_spin_lock);