[RH7,5/6] locking: Add LOCK_CONTENDED_RETURN

Submitted by Kirill Tkhai on May 22, 2020, 5:03 p.m.

Details

Message ID 159016699353.337057.122242456960893495.stgit@localhost.localdomain
State New
Series "Introduce down_read_killable()"
Headers show

Commit Message

Kirill Tkhai May 22, 2020, 5:03 p.m.
From ms commit 916633a40370 "locking/rwsem: Provide down_write_killable()"

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 include/linux/lockdep.h |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

Patch hide | download patch | download mbox

diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index 1c49aac45896..242f69bddecf 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -457,6 +457,18 @@  do {								\
 	lock_acquired(&(_lock)->dep_map, _RET_IP_);			\
 } while (0)
 
+#define LOCK_CONTENDED_RETURN(_lock, try, lock)			\
+({								\
+	int ____err = 0;					\
+	if (!try(_lock)) {					\
+		lock_contended(&(_lock)->dep_map, _RET_IP_);	\
+		____err = lock(_lock);				\
+	}							\
+	if (!____err)						\
+		lock_acquired(&(_lock)->dep_map, _RET_IP_);	\
+	____err;						\
+})
+
 #else /* CONFIG_LOCK_STAT */
 
 #define lock_contended(lockdep_map, ip) do {} while (0)
@@ -465,6 +477,9 @@  do {								\
 #define LOCK_CONTENDED(_lock, try, lock) \
 	lock(_lock)
 
+#define LOCK_CONTENDED_RETURN(_lock, try, lock) \
+	lock(_lock)
+
 #endif /* CONFIG_LOCK_STAT */
 
 #ifdef CONFIG_LOCKDEP