lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <1382394808-20611-3-git-send-email-dh.herrmann@gmail.com>
Date:	Tue, 22 Oct 2013 00:33:24 +0200
From:	David Herrmann <dh.herrmann@...il.com>
To:	dri-devel@...ts.freedesktop.org
Cc:	linux-kernel@...r.kernel.org, Dave Airlie <airlied@...il.com>,
	David Herrmann <dh.herrmann@...il.com>
Subject: [RFC v2 2/6] percpu_rw_semaphore: add percpu_down_read_trylock()

This is basically a copy of percpu_down_read() but does not sleep if a
writer is already active. Same semantics as classic down_read_trylock().

Signed-off-by: David Herrmann <dh.herrmann@...il.com>
---
 include/linux/percpu-rwsem.h |  1 +
 lib/percpu-rwsem.c           | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h
index 3e88c9a..2f752bd 100644
--- a/include/linux/percpu-rwsem.h
+++ b/include/linux/percpu-rwsem.h
@@ -16,6 +16,7 @@ struct percpu_rw_semaphore {
 };
 
 extern void percpu_down_read(struct percpu_rw_semaphore *);
+extern int percpu_down_read_trylock(struct percpu_rw_semaphore *);
 extern void percpu_up_read(struct percpu_rw_semaphore *);
 
 extern void percpu_down_write(struct percpu_rw_semaphore *);
diff --git a/lib/percpu-rwsem.c b/lib/percpu-rwsem.c
index 893586c..596f44b 100644
--- a/lib/percpu-rwsem.c
+++ b/lib/percpu-rwsem.c
@@ -92,6 +92,26 @@ void percpu_down_read(struct percpu_rw_semaphore *brw)
 }
 EXPORT_SYMBOL(percpu_down_read);
 
+int percpu_down_read_trylock(struct percpu_rw_semaphore *brw)
+{
+	int r;
+
+	if (likely(update_fast_ctr(brw, +1))) {
+		rwsem_acquire_read(&brw->rw_sem.dep_map, 0, 0, _RET_IP_);
+		return 1;
+	}
+
+	r = down_read_trylock(&brw->rw_sem);
+	if (r) {
+		atomic_inc(&brw->slow_read_ctr);
+		/* avoid up_read()->rwsem_release() */
+		__up_read(&brw->rw_sem);
+	}
+
+	return r;
+}
+EXPORT_SYMBOL(percpu_down_read_trylock);
+
 void percpu_up_read(struct percpu_rw_semaphore *brw)
 {
 	rwsem_release(&brw->rw_sem.dep_map, 1, _RET_IP_);
-- 
1.8.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ