On 11/27, Oleg Nesterov wrote:
>
> so synchronize_xxx() should be
> 
>       void synchronize_xxx(struct xxx_struct *sp)
>       {
>               int idx;
> 
>               smp_mb();
>               mutex_lock(&sp->mutex);
> 
>               idx = sp->completed & 0x1;
>               if (atomic_read(sp->ctr + idx) == 1)
>                       goto out;
> 
>               atomic_inc(sp->ctr + (idx ^ 0x1));
>               sp->completed++;
> 
>               atomic_dec(sp->ctr + idx);
>               wait_event(sp->wq, !atomic_read(sp->ctr + idx));
>       out:
>               mutex_unlock(&sp->mutex);
>       }
> 
> Yes, Alan was right, spinlock_t makes the code simpler.

Damn, it needs another mb() at the end,

        void synchronize_xxx(struct xxx_struct *sp)
        {
                int idx;

                smp_mb();
                mutex_lock(&sp->mutex);

                idx = sp->completed & 0x1;
                if (atomic_read(sp->ctr + idx) == 1)
                        goto out;

                atomic_inc(sp->ctr + (idx ^ 0x1));
                sp->completed++;

                atomic_dec(sp->ctr + idx);
                wait_event(sp->wq, !atomic_read(sp->ctr + idx));
        out:
                mutex_unlock(&sp->mutex);
                smp_mb();
        }

Oleg.

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

Reply via email to