Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 207354
b: refs/heads/master
c: 424acaa
h: refs/heads/master
v: v3
  • Loading branch information
Michel Lespinasse authored and Linus Torvalds committed Aug 10, 2010
1 parent 3f409a2 commit 8153511
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: fd41b33435ada87323cc86b50959fbffe35192c8
refs/heads/master: 424acaaeb3a3932d64a9b4bd59df6cf72c22d8f3
19 changes: 15 additions & 4 deletions trunk/lib/rwsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ __rwsem_do_wake(struct rw_semaphore *sem, int wake_type)
goto readers_only;

if (wake_type == RWSEM_WAKE_READ_OWNED)
/* Another active reader was observed, so wakeup is not
* likely to succeed. Save the atomic op.
*/
goto out;

/* There's a writer at the front of the queue - try to grant it the
Expand Down Expand Up @@ -111,8 +114,8 @@ __rwsem_do_wake(struct rw_semaphore *sem, int wake_type)
* count adjustment pretty soon.
*/
if (wake_type == RWSEM_WAKE_ANY &&
(rwsem_atomic_update(0, sem) & RWSEM_ACTIVE_MASK))
/* Someone grabbed the sem already */
rwsem_atomic_update(0, sem) < RWSEM_WAITING_BIAS)
/* Someone grabbed the sem for write already */
goto out;

/* Grant an infinite number of read locks to the readers at the front
Expand Down Expand Up @@ -187,9 +190,17 @@ rwsem_down_failed_common(struct rw_semaphore *sem,
/* we're now waiting on the lock, but no longer actively locking */
count = rwsem_atomic_update(adjustment, sem);

/* if there are no active locks, wake the front queued process(es) up */
if (!(count & RWSEM_ACTIVE_MASK))
/* If there are no active locks, wake the front queued process(es) up.
*
* Alternatively, if we're called from a failed down_write(), there
* were already threads queued before us and there are no active
* writers, the lock must be read owned; so we try to wake any read
* locks that were queued ahead of us. */
if (count == RWSEM_WAITING_BIAS)
sem = __rwsem_do_wake(sem, RWSEM_WAKE_NO_ACTIVE);
else if (count > RWSEM_WAITING_BIAS &&
adjustment == -RWSEM_ACTIVE_WRITE_BIAS)
sem = __rwsem_do_wake(sem, RWSEM_WAKE_READ_OWNED);

spin_unlock_irq(&sem->wait_lock);

Expand Down

0 comments on commit 8153511

Please sign in to comment.