Re: [PATCH] udev enhancements to use kernel event queue

Paul Mackerras (paulus@samba.org)
Fri, 13 Jun 2003 09:40:23 +1000 (EST)


Patrick Mochel writes:

> It seems like the following should work. Would someone mind commenting on
> it?

> +/**
> + * atomic_inc_and_read - increment atomic variable and return new value
> + * @v: pointer of type atomic_t
> + *
> + * Atomically increments @v by 1. Note that the guaranteed
> + * useful range of an atomic_t is only 24 bits.
> + */
> +static inline int atomic_inc_and_read(atomic_t *v)
> +{
> + __asm__ __volatile__(
> + LOCK "incl %0"
> + :"=m" (v->counter)
> + :"m" (v->counter));
> + return v->counter;
> +}

BZZZT. If another CPU is also doing atomic_inc_and_read you could end
up with both calls returning the same value.

You can't do atomic_inc_and_read on 386. You can on cpus that have
cmpxchg (e.g. later x86). You can also on machines with load-locked
and store-conditional instructions (alpha, ppc, probably most other
RISCs).

Paul.

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