mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-05 21:54:33 +02:00
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:
@@ -53,7 +53,7 @@ static esp_usb_console_cb_t s_tx_cb;
|
|||||||
static void *s_cb_arg;
|
static void *s_cb_arg;
|
||||||
|
|
||||||
#ifdef CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF
|
#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);
|
void esp_usb_console_write_char(char c);
|
||||||
#define ISR_FLAG ESP_INTR_FLAG_IRAM
|
#define ISR_FLAG ESP_INTR_FLAG_IRAM
|
||||||
#else
|
#else
|
||||||
@@ -399,11 +399,11 @@ void esp_usb_console_write_char(char c)
|
|||||||
}
|
}
|
||||||
static inline void write_lock_acquire(void)
|
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)
|
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
|
#else // CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF
|
||||||
|
@@ -61,7 +61,7 @@ typedef struct {
|
|||||||
event_select_args_t *select_args;
|
event_select_args_t *select_args;
|
||||||
_lock_t lock;
|
_lock_t lock;
|
||||||
// only for event fds that support ISR.
|
// only for event fds that support ISR.
|
||||||
spinlock_t data_spin_lock;
|
portMUX_TYPE data_spin_lock;
|
||||||
} event_context_t;
|
} event_context_t;
|
||||||
|
|
||||||
esp_vfs_id_t s_eventfd_vfs_id = -1;
|
esp_vfs_id_t s_eventfd_vfs_id = -1;
|
||||||
@@ -421,7 +421,7 @@ int eventfd(unsigned int initval, int flags)
|
|||||||
fd = i;
|
fd = i;
|
||||||
s_events[i].fd = i;
|
s_events[i].fd = i;
|
||||||
s_events[i].support_isr = support_isr;
|
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) {
|
if (support_isr) {
|
||||||
portENTER_CRITICAL(&s_events[i].data_spin_lock);
|
portENTER_CRITICAL(&s_events[i].data_spin_lock);
|
||||||
|
Reference in New Issue
Block a user