summaryrefslogtreecommitdiffstats
path: root/kernel/locking/percpu-rwsem.c
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2015-07-21 17:45:57 +0200
committerOleg Nesterov <oleg@redhat.com>2015-08-15 13:52:10 +0200
commit9287f6925ad9d8fb8c6283066b4f77fd87f123a9 (patch)
tree45da8cd0ac42defea9ca9e1efee0dc6daf4189b4 /kernel/locking/percpu-rwsem.c
parentdocument rwsem_release() in sb_wait_write() (diff)
downloadlinux-9287f6925ad9d8fb8c6283066b4f77fd87f123a9.tar.xz
linux-9287f6925ad9d8fb8c6283066b4f77fd87f123a9.zip
percpu-rwsem: introduce percpu_down_read_trylock()
Add percpu_down_read_trylock(), it will have the user soon. Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Diffstat (limited to 'kernel/locking/percpu-rwsem.c')
-rw-r--r--kernel/locking/percpu-rwsem.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/kernel/locking/percpu-rwsem.c b/kernel/locking/percpu-rwsem.c
index 652a8ee8efe9..f32567254867 100644
--- a/kernel/locking/percpu-rwsem.c
+++ b/kernel/locking/percpu-rwsem.c
@@ -88,6 +88,19 @@ void percpu_down_read(struct percpu_rw_semaphore *brw)
__up_read(&brw->rw_sem);
}
+int percpu_down_read_trylock(struct percpu_rw_semaphore *brw)
+{
+ if (unlikely(!update_fast_ctr(brw, +1))) {
+ if (!__down_read_trylock(&brw->rw_sem))
+ return 0;
+ atomic_inc(&brw->slow_read_ctr);
+ __up_read(&brw->rw_sem);
+ }
+
+ rwsem_acquire_read(&brw->rw_sem.dep_map, 0, 1, _RET_IP_);
+ return 1;
+}
+
void percpu_up_read(struct percpu_rw_semaphore *brw)
{
rwsem_release(&brw->rw_sem.dep_map, 1, _RET_IP_);