lkml.org 
[lkml]   [2003]   [Jun]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] udev enhancements to use kernel event queue
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/

\
 
 \ /
  Last update: 2005-03-22 13:36    [from the cache]
©2003-2011 Jasper Spaans