Paul Cassella wrote:
> > int atomic_read_and_clear(atomic_t *p)
> > {
> >         int n = atomic_read(p);
> >         atomic_sub(p, n);
> >         return n;
> > }
> 
> I don't think this will work; consider two callers doing the atomic_read()
> at the same time, or someone else doing an atomic_dec() after the
> atomic_read().

Oh yes, mea culpa, this is a terrible primitive, yet it works for this
application.  1) We don't have two callers 2) We only have atomic_inc
from the other processes, and it's ok for the atomic_inc to occur after
the atomic_read because that means the atomic_inc'er will then proceed
to up() the atomic_sub'ers semaphore, and it won't block.

I much preferred my original waiters = xchg(&sem.count, 0), but as noted
it doesn't work with sparc.  A satisfying approach would be to create
the new primitive up_down, which simplifies everything dramatically.

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

Reply via email to