On Mon, 06 Jun 2016, Sebastian Andrzej Siewior wrote:

-static void expunge_all(struct msg_queue *msq, int res)
+static void expunge_all(struct msg_queue *msq, int res,
+                       struct wake_q_head *wake_q)
{
        struct msg_receiver *msr, *t;

        list_for_each_entry_safe(msr, t, &msq->q_receivers, r_list) {
-               msr->r_msg = NULL; /* initialize expunge ordering */
-               wake_up_process(msr->r_tsk);
-               /*
-                * Ensure that the wakeup is visible before setting r_msg as
-                * the receiving end depends on it: either spinning on a nil,
-                * or dealing with -EAGAIN cases. See lockless receive part 1
-                * and 2 in do_msgrcv().
-                */
+
+               WRITE_ONCE(msr->r_msg, ERR_PTR(res));
                smp_wmb(); /* barrier (B) */
-               msr->r_msg = ERR_PTR(res);
+               wake_q_add(wake_q, msr->r_tsk);

Given that wake_q_add() implies barriers on both sides (cmpxchg), I think we
can rely on that instead of the explicit smp_wmb() for barrier B. While a failed
call doesn't imply the barriers, we're already in a world of trouble _anyways_
if that's the case. Same for pipelined_send, obviously.

Thanks,
Davidlohr

Reply via email to