linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V10 2/7] locking/percpu-rwsem: Add guard support
       [not found] <20250314172700.438923-1-kan.liang@linux.intel.com>
@ 2025-03-14 17:26 ` kan.liang
  0 siblings, 0 replies; only message in thread
From: kan.liang @ 2025-03-14 17:26 UTC (permalink / raw)
  To: peterz, mingo, tglx, bp, acme, namhyung, irogers, linux-kernel
  Cc: ak, eranian, Kan Liang, Dennis Zhou, Tejun Heo,
	Christoph Lameter, linux-mm

From: "Peter Zijlstra (Intel)" <peterz@infradead.org>

To simplify the usage of the percpu rw semaphore.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Christoph Lameter <cl@linux.com>
Cc: linux-mm@kvack.org
---

No changes since V9

 include/linux/percpu-rwsem.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h
index c012df33a9f0..af7d75ede619 100644
--- a/include/linux/percpu-rwsem.h
+++ b/include/linux/percpu-rwsem.h
@@ -8,6 +8,7 @@
 #include <linux/wait.h>
 #include <linux/rcu_sync.h>
 #include <linux/lockdep.h>
+#include <linux/cleanup.h>
 
 struct percpu_rw_semaphore {
 	struct rcu_sync		rss;
@@ -125,6 +126,13 @@ extern bool percpu_is_read_locked(struct percpu_rw_semaphore *);
 extern void percpu_down_write(struct percpu_rw_semaphore *);
 extern void percpu_up_write(struct percpu_rw_semaphore *);
 
+DEFINE_GUARD(percpu_read, struct percpu_rw_semaphore *,
+	     percpu_down_read(_T), percpu_up_read(_T))
+DEFINE_GUARD_COND(percpu_read, _try, percpu_down_read_trylock(_T))
+
+DEFINE_GUARD(percpu_write, struct percpu_rw_semaphore *,
+	     percpu_down_write(_T), percpu_up_write(_T))
+
 static inline bool percpu_is_write_locked(struct percpu_rw_semaphore *sem)
 {
 	return atomic_read(&sem->block);
-- 
2.38.1



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-03-14 17:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20250314172700.438923-1-kan.liang@linux.intel.com>
2025-03-14 17:26 ` [PATCH V10 2/7] locking/percpu-rwsem: Add guard support kan.liang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox