This is an automated email from the ASF dual-hosted git repository.
ligd pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new f909c9205e4 notifier: remove critical section
f909c9205e4 is described below
commit f909c9205e469c839f0e6702df8508a365f69a1a
Author: hujun5 <[email protected]>
AuthorDate: Sat Mar 8 13:02:01 2025 +0800
notifier: remove critical section
The notifier doesn't need to hold the critical section for the entire
operation, allowing for better performance and reduced lock contention
on multi-core systems.
Signed-off-by: hujun5 <[email protected]>
---
include/nuttx/notifier.h | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/include/nuttx/notifier.h b/include/nuttx/notifier.h
index 7fdbdbdb79f..9afe8457f39 100644
--- a/include/nuttx/notifier.h
+++ b/include/nuttx/notifier.h
@@ -41,7 +41,7 @@
* Pre-processor Definitions
****************************************************************************/
-#define ATOMIC_NOTIFIER_INIT(name) {NULL}
+#define ATOMIC_NOTIFIER_INIT(name) {NULL, RSPINLOCK_INITIALIZER}
#define ATOMIC_NOTIFIER_HEAD(name) \
struct atomic_notifier_head name = ATOMIC_NOTIFIER_INIT(name)
@@ -81,6 +81,7 @@ struct notifier_block
struct atomic_notifier_head
{
FAR struct notifier_block *head;
+ rspinlock_t lock;
};
struct blocking_notifier_head
@@ -179,9 +180,9 @@ extern "C"
{ \
FAR struct atomic_notifier_head *nh = (nhead); \
irqstate_t flags; \
- flags = enter_critical_section(); \
+ flags = rspin_lock_irqsave_nopreempt(&nh->lock); \
notifier_chain_register(nh->head, (nb), false); \
- leave_critical_section(flags); \
+ rspin_unlock_irqrestore_nopreempt(&nh->lock, flags); \
} \
while(0)
@@ -190,9 +191,9 @@ extern "C"
{ \
FAR struct atomic_notifier_head *nh = (nhead); \
irqstate_t flags; \
- flags = enter_critical_section(); \
+ flags = rspin_lock_irqsave_nopreempt(&nh->lock); \
notifier_chain_register(nh->head, (nb), true); \
- leave_critical_section(flags); \
+ rspin_unlock_irqrestore_nopreempt(&nh->lock, flags); \
} \
while(0)
@@ -201,9 +202,9 @@ extern "C"
{ \
FAR struct atomic_notifier_head *nh = (nhead); \
irqstate_t flags; \
- flags = enter_critical_section(); \
+ flags = rspin_lock_irqsave_nopreempt(&nh->lock); \
notifier_chain_unregister(nh->head, (nb)); \
- leave_critical_section(flags); \
+ rspin_unlock_irqrestore_nopreempt(&nh->lock, flags); \
} \
while(0)
@@ -212,9 +213,9 @@ extern "C"
{ \
FAR struct atomic_notifier_head *nh = (nhead); \
irqstate_t flags; \
- flags = enter_critical_section(); \
+ flags = rspin_lock_irqsave_nopreempt(&nh->lock); \
notifier_call_chain(nh->head, (val), (v), -1, NULL); \
- leave_critical_section(flags); \
+ rspin_unlock_irqrestore_nopreempt(&nh->lock, flags); \
} \
while(0)