Skip to content

Commit cd27e3c

Browse files
Kirill TkhaiNagarathnam Muthusamy
authored andcommitted
locking/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 <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/150670119884.23930.2585570605960763239.stgit@localhost.localdomain Signed-off-by: Ingo Molnar <[email protected]> (cherry picked from commit 76f8507) Orabug: 28900385 Signed-off-by: Nagarathnam Muthusamy <[email protected]> Reviewed-by: Darren Kenny <[email protected]>
1 parent 64f3807 commit cd27e3c

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

include/asm-generic/rwsem.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ static inline void __down_read(struct rw_semaphore *sem)
3838
rwsem_down_read_failed(sem);
3939
}
4040

41+
static inline int __down_read_killable(struct rw_semaphore *sem)
42+
{
43+
if (unlikely(atomic_long_inc_return_acquire(&sem->count) <= 0)) {
44+
if (IS_ERR(rwsem_down_read_failed_killable(sem)))
45+
return -EINTR;
46+
}
47+
48+
return 0;
49+
}
50+
4151
static inline int __down_read_trylock(struct rw_semaphore *sem)
4252
{
4353
long tmp;

include/linux/rwsem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ static inline int rwsem_is_contended(struct rw_semaphore *sem)
118118
* lock for reading
119119
*/
120120
extern void down_read(struct rw_semaphore *sem);
121+
extern int __must_check down_read_killable(struct rw_semaphore *sem);
121122

122123
/*
123124
* trylock for reading -- returns 1 if successful, 0 if contention

kernel/locking/rwsem.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ void __sched down_read(struct rw_semaphore *sem)
2929

3030
EXPORT_SYMBOL(down_read);
3131

32+
int __sched down_read_killable(struct rw_semaphore *sem)
33+
{
34+
might_sleep();
35+
rwsem_acquire_read(&sem->dep_map, 0, 0, _RET_IP_);
36+
37+
if (LOCK_CONTENDED_RETURN(sem, __down_read_trylock, __down_read_killable)) {
38+
rwsem_release(&sem->dep_map, 1, _RET_IP_);
39+
return -EINTR;
40+
}
41+
42+
rwsem_set_reader_owned(sem);
43+
return 0;
44+
}
45+
46+
EXPORT_SYMBOL(down_read_killable);
47+
3248
/*
3349
* trylock for reading -- returns 1 if successful, 0 if contention
3450
*/

0 commit comments

Comments
 (0)