Commit 00261a94 authored by Thomas Gleixner's avatar Thomas Gleixner

rt: Fix rwlocks/rwsem rt_[down_]read_trylock()

rt_read_trylock() and rt_down_read_trylock() take the lock / semaphore
unconditionally when it is write locked. Check read_depth if current
owns the lock. If it's 0 we know it is write locked and return 0.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 0188eb59
...@@ -204,10 +204,14 @@ int __lockfunc rt_read_trylock(rwlock_t *rwlock) ...@@ -204,10 +204,14 @@ int __lockfunc rt_read_trylock(rwlock_t *rwlock)
int ret = 1; int ret = 1;
/* /*
* recursive read locks succeed when current owns the lock * recursive read locks succeed when current owns the lock,
* but not when read_depth == 0 which means that the lock is
* write locked.
*/ */
if (rt_mutex_real_owner(lock) != current) if (rt_mutex_real_owner(lock) != current)
ret = rt_mutex_trylock(lock); ret = rt_mutex_trylock(lock);
else if (!rwlock->read_depth)
ret = 0;
if (ret) { if (ret) {
rwlock->read_depth++; rwlock->read_depth++;
...@@ -348,8 +352,15 @@ int rt_down_read_trylock(struct rw_semaphore *rwsem) ...@@ -348,8 +352,15 @@ int rt_down_read_trylock(struct rw_semaphore *rwsem)
struct rt_mutex *lock = &rwsem->lock; struct rt_mutex *lock = &rwsem->lock;
int ret = 1; int ret = 1;
/*
* recursive read locks succeed when current owns the rwsem,
* but not when read_depth == 0 which means that the rwsem is
* write locked.
*/
if (rt_mutex_real_owner(lock) != current) if (rt_mutex_real_owner(lock) != current)
ret = rt_mutex_trylock(&rwsem->lock); ret = rt_mutex_trylock(&rwsem->lock);
else if (!rwsem->read_depth)
ret = 0;
if (ret) { if (ret) {
rwsem->read_depth++; rwsem->read_depth++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment