[PATCH 2/2] futex: add plist_del + atomic_dec helper

From: Davidlohr Bueso
Date: Sun Mar 30 2014 - 19:09:10 EST


When removing a waiter from the plist, we always decrement the
hb waiters to reflect such logic. Add an unqueue_waiter() helper,
thus preventing any future changes that might not do so.

For the enqueuing, this isn't worth it since we will increment the
hb waiters before doing the plist_add().

Signed-off-by: Davidlohr Bueso <davidlohr@xxxxxx>
---
kernel/futex.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index 395e285..b9ef521 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -291,6 +291,13 @@ static inline int hb_waiters_pending(struct futex_hash_bucket *hb)
#endif
}

+static inline void unqueue_waiter(struct futex_q *q,
+ struct futex_hash_bucket *hb)
+{
+ plist_del(&q->list, &hb->chain);
+ hb_waiters_dec(hb);
+}
+
/*
* We hash on the keys returned from get_futex_key (see below).
*/
@@ -972,8 +979,7 @@ static void __unqueue_futex(struct futex_q *q)
return;

hb = container_of(q->lock_ptr, struct futex_hash_bucket, lock);
- plist_del(&q->list, &hb->chain);
- hb_waiters_dec(hb);
+ unqueue_waiter(q, hb);
}

/*
@@ -1276,8 +1282,7 @@ void requeue_futex(struct futex_q *q, struct futex_hash_bucket *hb1,
* requeue.
*/
if (likely(&hb1->chain != &hb2->chain)) {
- plist_del(&q->list, &hb1->chain);
- hb_waiters_dec(hb1);
+ unqueue_waiter(q, hb1);
plist_add(&q->list, &hb2->chain);
hb_waiters_inc(hb2);
q->lock_ptr = &hb2->lock;
@@ -2375,8 +2380,7 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb,
* We were woken prior to requeue by a timeout or a signal.
* Unqueue the futex_q and determine which it was.
*/
- plist_del(&q->list, &hb->chain);
- hb_waiters_dec(hb);
+ unqueue_waiter(q, hb);

/* Handle spurious wakeups gracefully */
ret = -EWOULDBLOCK;
--
1.8.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/