New helpers for locking two locks at a time.
Signed-off-by: Kirill Tkhai <[email protected]>
---
include/linux/spinlock.h | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h
index 3e18379..e1e3054 100644
--- a/include/linux/spinlock.h
+++ b/include/linux/spinlock.h
@@ -426,4 +426,23 @@ extern int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock);
#define atomic_dec_and_lock(atomic, lock) \
__cond_lock(lock, _atomic_dec_and_lock(atomic, lock))
+static inline void double_write_lock(rwlock_t *lock1, rwlock_t *lock2)
+{
+ if (lock1 < lock2) {
+ write_lock(lock1);
+ write_lock(lock2);
+ } else if (lock1 > lock2) {
+ write_lock(lock2);
+ write_lock(lock1);
+ } else {
+ write_lock(lock1);
+ }
+}
+static inline void double_write_unlock(rwlock_t *lock1, rwlock_t *lock2)
+{
+ if (lock2 != lock1)
+ write_unlock(lock2);
+ write_unlock(lock1);
+}
+
#endif /* __LINUX_SPINLOCK_H */