[RHEL7,COMMIT] locking: Add LOCK_CONTENDED_RETURN

Submitted by Konstantin Khorenko on May 25, 2020, 2:56 p.m.

Details

Message ID 202005251456.04PEu0Yk005279@finist-ce7.sw.ru
State New
Series "Introduce down_read_killable()"
Headers show

Commit Message

Konstantin Khorenko May 25, 2020, 2:56 p.m.
The commit is pushed to "branch-rh7-3.10.0-1127.8.2.vz7.161.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.8.2.vz7.161.1
------>
commit 2be9326b9b38cb78dab05006822dd151df3646cf
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Mon May 25 17:55:59 2020 +0300

    locking: Add LOCK_CONTENDED_RETURN
    
    >From ms commit 916633a40370 "locking/rwsem: Provide down_write_killable()"
    
    Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
    
    =====================
    Patchset description:
    
    This ports support for down_read_killable(),
    which is a prerequisite for pernet_ops_rwsem.
    
    https://jira.sw.ru/browse/PSBM-104158
---
 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 1c49aac45896e..242f69bddecfe 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