[PATCH] futex: Add memory barrier commentary to futex_wait_queue_me()

From: Darren Hart
Date: Thu Sep 24 2009 - 14:54:47 EST


The memory barrier semantics of futex_wait_queue_me() are
non-obvious. Add some commentary to try and clarify it.

Signed-off-by: Darren Hart <dvhltc@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Eric Dumazet <eric.dumazet@xxxxxxxxx>
Cc: Dinakar Guniguntala <dino@xxxxxxxxxx>
Cc: John Stultz <johnstul@xxxxxxxxxx>
LKML-Reference: <20090924185447.694.38948.stgit@Aeon>
Signed-off-by: Ingo Molnar <mingo@xxxxxxx>
---
kernel/futex.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index 5978a84..61761ef 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -1638,6 +1638,12 @@ out:
static void futex_wait_queue_me(struct futex_hash_bucket *hb, struct futex_q *q,
struct hrtimer_sleeper *timeout)
{
+ /*
+ * The task state is guaranteed to be set before another task can
+ * wake it. set_current_state() is implemented using set_mb() and
+ * queue_me() calls spin_unlock() upon completion, both serializing
+ * access to the hash list and forcing another memory barrier.
+ */
set_current_state(TASK_INTERRUPTIBLE);
queue_me(q, hb);

--
1.6.0.6