aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/rt.c
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2009-09-14 13:01:21 -0400
committerThomas Gleixner <tglx@linutronix.de>2009-09-15 11:28:33 -0400
commit00261a9426ed50016e07cbef028578e93589761c (patch)
treead17506dd480e686ebd40610391099b7a143b457 /kernel/rt.c
parent0188eb5994a27527b0ed2770df56ca6565486713 (diff)
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: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/rt.c')
-rw-r--r--kernel/rt.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/kernel/rt.c b/kernel/rt.c
index 710cef59ee8a..fd033a9bd7c2 100644
--- a/kernel/rt.c
+++ b/kernel/rt.c
@@ -204,10 +204,14 @@ int __lockfunc rt_read_trylock(rwlock_t *rwlock)
204 int ret = 1; 204 int ret = 1;
205 205
206 /* 206 /*
207 * recursive read locks succeed when current owns the lock 207 * recursive read locks succeed when current owns the lock,
208 * but not when read_depth == 0 which means that the lock is
209 * write locked.
208 */ 210 */
209 if (rt_mutex_real_owner(lock) != current) 211 if (rt_mutex_real_owner(lock) != current)
210 ret = rt_mutex_trylock(lock); 212 ret = rt_mutex_trylock(lock);
213 else if (!rwlock->read_depth)
214 ret = 0;
211 215
212 if (ret) { 216 if (ret) {
213 rwlock->read_depth++; 217 rwlock->read_depth++;
@@ -348,8 +352,15 @@ int rt_down_read_trylock(struct rw_semaphore *rwsem)
348 struct rt_mutex *lock = &rwsem->lock; 352 struct rt_mutex *lock = &rwsem->lock;
349 int ret = 1; 353 int ret = 1;
350 354
355 /*
356 * recursive read locks succeed when current owns the rwsem,
357 * but not when read_depth == 0 which means that the rwsem is
358 * write locked.
359 */
351 if (rt_mutex_real_owner(lock) != current) 360 if (rt_mutex_real_owner(lock) != current)
352 ret = rt_mutex_trylock(&rwsem->lock); 361 ret = rt_mutex_trylock(&rwsem->lock);
362 else if (!rwsem->read_depth)
363 ret = 0;
353 364
354 if (ret) { 365 if (ret) {
355 rwsem->read_depth++; 366 rwsem->read_depth++;