aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rwsem-spinlock.c
diff options
context:
space:
mode:
authorMichel Lespinasse <walken@google.com>2013-05-07 09:45:49 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-05-07 10:20:15 -0400
commite2d57f782c8a906f80d5b5f54da803c1638929d7 (patch)
tree96a3d2f26b8257d39db40ec4cd3cd52b3ef14588 /lib/rwsem-spinlock.c
parentc1be5a5b1b355d40e6cf79cc979eb66dafa24ad1 (diff)
rwsem: make the waiter type an enumeration rather than a bitmask
We are not planning to add some new waiter flags, so we can convert the waiter type into an enumeration. Background: David Howells suggested I do this back when I tried adding a new waiter type for unfair readers. However, I believe the cleanup applies regardless of that use case. Signed-off-by: Michel Lespinasse <walken@google.com> Reviewed-by: Rik van Riel <riel@redhat.com> Reviewed-by: Peter Hurley <peter@hurleysoftware.com> Acked-by: Davidlohr Bueso <davidlohr.bueso@hp.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/rwsem-spinlock.c')
-rw-r--r--lib/rwsem-spinlock.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/rwsem-spinlock.c b/lib/rwsem-spinlock.c
index 7542afbb22b3..5f117f37ac0a 100644
--- a/lib/rwsem-spinlock.c
+++ b/lib/rwsem-spinlock.c
@@ -9,12 +9,15 @@
9#include <linux/sched.h> 9#include <linux/sched.h>
10#include <linux/export.h> 10#include <linux/export.h>
11 11
12enum rwsem_waiter_type {
13 RWSEM_WAITING_FOR_WRITE,
14 RWSEM_WAITING_FOR_READ
15};
16
12struct rwsem_waiter { 17struct rwsem_waiter {
13 struct list_head list; 18 struct list_head list;
14 struct task_struct *task; 19 struct task_struct *task;
15 unsigned int flags; 20 enum rwsem_waiter_type type;
16#define RWSEM_WAITING_FOR_READ 0x00000001
17#define RWSEM_WAITING_FOR_WRITE 0x00000002
18}; 21};
19 22
20int rwsem_is_locked(struct rw_semaphore *sem) 23int rwsem_is_locked(struct rw_semaphore *sem)
@@ -68,7 +71,7 @@ __rwsem_do_wake(struct rw_semaphore *sem, int wakewrite)
68 waiter = list_entry(sem->wait_list.next, struct rwsem_waiter, list); 71 waiter = list_entry(sem->wait_list.next, struct rwsem_waiter, list);
69 72
70 if (!wakewrite) { 73 if (!wakewrite) {
71 if (waiter->flags & RWSEM_WAITING_FOR_WRITE) 74 if (waiter->type == RWSEM_WAITING_FOR_WRITE)
72 goto out; 75 goto out;
73 goto dont_wake_writers; 76 goto dont_wake_writers;
74 } 77 }
@@ -78,7 +81,7 @@ __rwsem_do_wake(struct rw_semaphore *sem, int wakewrite)
78 * to -1 here to indicate we get the lock. Instead, we wake it up 81 * to -1 here to indicate we get the lock. Instead, we wake it up
79 * to let it go get it again. 82 * to let it go get it again.
80 */ 83 */
81 if (waiter->flags & RWSEM_WAITING_FOR_WRITE) { 84 if (waiter->type == RWSEM_WAITING_FOR_WRITE) {
82 wake_up_process(waiter->task); 85 wake_up_process(waiter->task);
83 goto out; 86 goto out;
84 } 87 }
@@ -86,7 +89,7 @@ __rwsem_do_wake(struct rw_semaphore *sem, int wakewrite)
86 /* grant an infinite number of read locks to the front of the queue */ 89 /* grant an infinite number of read locks to the front of the queue */
87 dont_wake_writers: 90 dont_wake_writers:
88 woken = 0; 91 woken = 0;
89 while (waiter->flags & RWSEM_WAITING_FOR_READ) { 92 while (waiter->type == RWSEM_WAITING_FOR_READ) {
90 struct list_head *next = waiter->list.next; 93 struct list_head *next = waiter->list.next;
91 94
92 list_del(&waiter->list); 95 list_del(&waiter->list);
@@ -144,7 +147,7 @@ void __sched __down_read(struct rw_semaphore *sem)
144 147
145 /* set up my own style of waitqueue */ 148 /* set up my own style of waitqueue */
146 waiter.task = tsk; 149 waiter.task = tsk;
147 waiter.flags = RWSEM_WAITING_FOR_READ; 150 waiter.type = RWSEM_WAITING_FOR_READ;
148 get_task_struct(tsk); 151 get_task_struct(tsk);
149 152
150 list_add_tail(&waiter.list, &sem->wait_list); 153 list_add_tail(&waiter.list, &sem->wait_list);
@@ -201,7 +204,7 @@ void __sched __down_write_nested(struct rw_semaphore *sem, int subclass)
201 /* set up my own style of waitqueue */ 204 /* set up my own style of waitqueue */
202 tsk = current; 205 tsk = current;
203 waiter.task = tsk; 206 waiter.task = tsk;
204 waiter.flags = RWSEM_WAITING_FOR_WRITE; 207 waiter.type = RWSEM_WAITING_FOR_WRITE;
205 list_add_tail(&waiter.list, &sem->wait_list); 208 list_add_tail(&waiter.list, &sem->wait_list);
206 209
207 /* wait for someone to release the lock */ 210 /* wait for someone to release the lock */