drivers/usbhost: Use small lock to protect usbhost common function

replace critical_section with spinlock

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
This commit is contained in:
yangsong8
2025-06-17 20:45:43 +08:00
committed by Xiang Xiao
parent 52d5aeb60c
commit b9b62a9204
5 changed files with 12 additions and 7 deletions
+3 -3
View File
@@ -139,7 +139,7 @@ const struct usbhost_registry_s *usbhost_findclass(
* protected by disabling interrupts.
*/
flags = enter_critical_section();
flags = spin_lock_irqsave_nopreempt(&g_classregistry_lock);
/* Examine each register class in the linked list */
@@ -158,7 +158,7 @@ const struct usbhost_registry_s *usbhost_findclass(
{
/* Yes.. restore interrupts and return the class info */
leave_critical_section(flags);
spin_unlock_irqrestore_nopreempt(&g_classregistry_lock, flags);
return usbclass;
}
}
@@ -166,6 +166,6 @@ const struct usbhost_registry_s *usbhost_findclass(
/* Not found... restore interrupts and return NULL */
leave_critical_section(flags);
spin_unlock_irqrestore_nopreempt(&g_classregistry_lock, flags);
return NULL;
}
+2 -2
View File
@@ -91,13 +91,13 @@ int usbhost_registerclass(struct usbhost_registry_s *usbclass)
* protected by disabling interrupts.
*/
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_classregistry_lock);
/* Add the new class ID info to the head of the list */
usbclass->flink = g_classregistry;
g_classregistry = usbclass;
leave_critical_section(flags);
spin_unlock_irqrestore(&g_classregistry_lock, flags);
return OK;
}
+1
View File
@@ -57,6 +57,7 @@
*/
struct usbhost_registry_s *g_classregistry;
spinlock_t g_classregistry_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
+2
View File
@@ -28,6 +28,7 @@
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/spinlock.h>
#include <nuttx/usb/usbhost.h>
@@ -61,6 +62,7 @@ extern "C"
*/
EXTERN struct usbhost_registry_s *g_classregistry;
EXTERN spinlock_t g_classregistry_lock;
/****************************************************************************
* Public Function Prototypes
+4 -2
View File
@@ -25,6 +25,7 @@
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/spinlock.h>
#include <sys/types.h>
#include <stdint.h>
@@ -60,6 +61,7 @@
#ifdef CONFIG_USBHOST_TRACE
static uint32_t g_trace[CONFIG_USBHOST_TRACE_NRECORDS];
static spinlock_t g_usbhost_trace_lock = SP_UNLOCKED;
static volatile uint16_t g_head = 0;
static volatile uint16_t g_tail = 0;
static volatile bool g_disabled = false;
@@ -136,7 +138,7 @@ void usbhost_trace_common(uint32_t event)
/* Check if tracing is enabled for this ID */
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_usbhost_trace_lock);
if (!g_disabled)
{
/* Yes... save the new trace data at the head */
@@ -159,7 +161,7 @@ void usbhost_trace_common(uint32_t event)
}
}
leave_critical_section(flags);
spin_unlock_irqrestore(&g_usbhost_trace_lock, flags);
}
#endif /* CONFIG_USBHOST_TRACE */