[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240821230539.168107-2-woodyzhang666@gmail.com>
Date: Thu, 22 Aug 2024 07:05:35 +0800
From: Woody Zhang <woodyzhang666@...il.com>
To: Thomas Gleixner <tglx@...utronix.de>,
Andrew Morton <akpm@...ux-foundation.org>
Cc: linux-kernel@...r.kernel.org,
Woody Zhang <woodyzhang666@...il.com>
Subject: [PATCH 1/5] bit_spinlock: add irq variant for bit spinlock API
This variant makes bit spinlock easy to be used to protect data that
can be accessed from irq context.
Signed-off-by: Woody Zhang <woodyzhang666@...il.com>
---
include/linux/bit_spinlock.h | 37 ++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/include/linux/bit_spinlock.h b/include/linux/bit_spinlock.h
index bbc4730a6505..5a176e574a8f 100644
--- a/include/linux/bit_spinlock.h
+++ b/include/linux/bit_spinlock.h
@@ -6,6 +6,9 @@
#include <linux/preempt.h>
#include <linux/atomic.h>
#include <linux/bug.h>
+#include <linux/typecheck.h>
+#include <linux/irqflags.h>
+#include <linux/processor.h>
/*
* bit-based spin_lock()
@@ -97,5 +100,39 @@ static inline int bit_spin_is_locked(int bitnum, unsigned long *addr)
#endif
}
+#define bit_spin_lock_irqsave(bitnum, addr, flags) \
+do { \
+ typecheck(int, bitnum); \
+ typecheck(unsigned long *, addr); \
+ typecheck(unsigned long, flags); \
+ local_irq_save(flags); \
+ bit_spin_lock(bitnum, addr); \
+} while (0)
+
+
+#define bit_spin_trylock_irqsave(bitnum, addr, flags) \
+({ \
+ typecheck(int, bitnum); \
+ typecheck(unsigned long *, addr); \
+ typecheck(unsigned long, flags); \
+ local_irq_save(flags); \
+ bit_spin_trylock(bitnum, addr) ? \
+ 1 : ({ local_irq_restore(flags); 0; }); \
+})
+
+static inline void bit_spin_unlock_irqrestore(int bitnum,
+ unsigned long *addr, unsigned long flags)
+{
+ bit_spin_unlock(bitnum, addr);
+ local_irq_restore(flags);
+}
+
+static inline void __bit_spin_unlock_irqrestore(int bitnum,
+ unsigned long *addr, unsigned long flags)
+{
+ __bit_spin_unlock(bitnum, addr);
+ local_irq_restore(flags);
+}
+
#endif /* __LINUX_BIT_SPINLOCK_H */
--
2.45.2
Powered by blists - more mailing lists