locking/percpu-rwsem: Add DEFINE_STATIC_PERCPU_RWSEMand percpu_rwsem_assert_held()
authorPeter Zijlstra <peterz@infradead.org>
Mon, 22 Jun 2015 12:16:31 +0000 (14:16 +0200)
committerIngo Molnar <mingo@kernel.org>
Thu, 22 Sep 2016 13:25:52 +0000 (15:25 +0200)
Provide a static init and a standard locking assertion method.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: dave@stgolabs.net
Cc: der.herr@hofr.at
Cc: oleg@redhat.com
Cc: paulmck@linux.vnet.ibm.com
Cc: riel@redhat.com
Cc: tj@kernel.org
Cc: viro@ZenIV.linux.org.uk
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
include/linux/percpu-rwsem.h

index 146efefde2a157008fce62fcdaa376f13e2c7682..d402d3924a911da7641bc9bb53d20688b2354601 100644 (file)
@@ -16,6 +16,15 @@ struct percpu_rw_semaphore {
        int                     readers_block;
 };
 
+#define DEFINE_STATIC_PERCPU_RWSEM(name)                               \
+static DEFINE_PER_CPU(unsigned int, __percpu_rwsem_rc_##name);         \
+static struct percpu_rw_semaphore name = {                             \
+       .rss = __RCU_SYNC_INITIALIZER(name.rss, RCU_SCHED_SYNC),        \
+       .read_count = &__percpu_rwsem_rc_##name,                        \
+       .rw_sem = __RWSEM_INITIALIZER(name.rw_sem),                     \
+       .writer = __WAIT_QUEUE_HEAD_INITIALIZER(name.writer),           \
+}
+
 extern int __percpu_down_read(struct percpu_rw_semaphore *, int);
 extern void __percpu_up_read(struct percpu_rw_semaphore *);
 
@@ -102,6 +111,9 @@ extern void percpu_free_rwsem(struct percpu_rw_semaphore *);
 
 #define percpu_rwsem_is_held(sem) lockdep_is_held(&(sem)->rw_sem)
 
+#define percpu_rwsem_assert_held(sem)                          \
+       lockdep_assert_held(&(sem)->rw_sem)
+
 static inline void percpu_rwsem_release(struct percpu_rw_semaphore *sem,
                                        bool read, unsigned long ip)
 {