Skip to content

Commit fdfda86

Browse files
author
Peter Zijlstra (Intel)
committed
locking/percpu-rwsem: Add guard support
To simplify the usage of the percpu rw semaphore. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent cb43691 commit fdfda86

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/linux/percpu-rwsem.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/wait.h>
99
#include <linux/rcu_sync.h>
1010
#include <linux/lockdep.h>
11+
#include <linux/cleanup.h>
1112

1213
struct percpu_rw_semaphore {
1314
struct rcu_sync rss;
@@ -125,6 +126,13 @@ extern bool percpu_is_read_locked(struct percpu_rw_semaphore *);
125126
extern void percpu_down_write(struct percpu_rw_semaphore *);
126127
extern void percpu_up_write(struct percpu_rw_semaphore *);
127128

129+
DEFINE_GUARD(percpu_read, struct percpu_rw_semaphore *,
130+
percpu_down_read(_T), percpu_up_read(_T))
131+
DEFINE_GUARD_COND(percpu_read, _try, percpu_down_read_trylock(_T))
132+
133+
DEFINE_GUARD(percpu_write, struct percpu_rw_semaphore *,
134+
percpu_down_write(_T), percpu_up_write(_T))
135+
128136
static inline bool percpu_is_write_locked(struct percpu_rw_semaphore *sem)
129137
{
130138
return atomic_read(&sem->block);

0 commit comments

Comments
 (0)