[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <149789540861.9059.16507519363746458694.stgit@localhost.localdomain>
Date: Mon, 19 Jun 2017 21:03:28 +0300
From: Kirill Tkhai <ktkhai@...tuozzo.com>
To: linux-ia64@...r.kernel.org, avagin@...tuozzo.com,
peterz@...radead.org, heiko.carstens@...ibm.com, hpa@...or.com,
gorcunov@...tuozzo.com, linux-arch@...r.kernel.org,
linux-s390@...r.kernel.org, x86@...nel.org, mingo@...hat.com,
mattst88@...il.com, fenghua.yu@...el.com, arnd@...db.de,
ktkhai@...tuozzo.com, ink@...assic.park.msu.ru, tglx@...utronix.de,
rth@...ddle.net, tony.luck@...el.com, linux-kernel@...r.kernel.org,
linux-alpha@...r.kernel.org, schwidefsky@...ibm.com,
davem@...emloft.net
Subject: [PATCH 7/7] rwsem: Add down_read_killable()
Similar to down_read() and down_write_killable(),
add killable version of down_read(), based on
__down_read_killable() function, added in previous
patches.
Signed-off-by: Kirill Tkhai <ktkhai@...tuozzo.com>
---
include/asm-generic/rwsem.h | 8 ++++++++
include/linux/rwsem.h | 1 +
kernel/locking/rwsem.c | 16 ++++++++++++++++
3 files changed, 25 insertions(+)
diff --git a/include/asm-generic/rwsem.h b/include/asm-generic/rwsem.h
index 6c6a2141f271..2f71b913b555 100644
--- a/include/asm-generic/rwsem.h
+++ b/include/asm-generic/rwsem.h
@@ -37,6 +37,14 @@ static inline void __down_read(struct rw_semaphore *sem)
rwsem_down_read_failed(sem);
}
+static inline int __down_read_killable(struct rw_semaphore *sem)
+{
+ if (unlikely(atomic_long_inc_return_acquire(&sem->count) <= 0))
+ if (IS_ERR(rwsem_down_read_failed_killable(sem)))
+ return -EINTR;
+ return 0;
+}
+
static inline int __down_read_trylock(struct rw_semaphore *sem)
{
long tmp;
diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h
index 0ad7318ff299..6ac8ee5f15dd 100644
--- a/include/linux/rwsem.h
+++ b/include/linux/rwsem.h
@@ -111,6 +111,7 @@ static inline int rwsem_is_contended(struct rw_semaphore *sem)
* lock for reading
*/
extern void down_read(struct rw_semaphore *sem);
+extern int __must_check down_read_killable(struct rw_semaphore *sem);
/*
* trylock for reading -- returns 1 if successful, 0 if contention
diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
index 4d48b1c4870d..e53f7746d9fd 100644
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -28,6 +28,22 @@ void __sched down_read(struct rw_semaphore *sem)
EXPORT_SYMBOL(down_read);
+int __sched down_read_killable(struct rw_semaphore *sem)
+{
+ might_sleep();
+ rwsem_acquire_read(&sem->dep_map, 0, 0, _RET_IP_);
+
+ if (LOCK_CONTENDED_RETURN(sem, __down_read_trylock, __down_read_killable)) {
+ rwsem_release(&sem->dep_map, 1, _RET_IP_);
+ return -EINTR;
+ }
+
+ rwsem_set_reader_owned(sem);
+ return 0;
+}
+
+EXPORT_SYMBOL(down_read_killable);
+
/*
* trylock for reading -- returns 1 if successful, 0 if contention
*/
Powered by blists - more mailing lists