This is not a test and set operation.
atomic_t atomic_exchange (atomic_t i, atomic_t *v)
asm volatile("xchgl %0,%1" : "+m" (*v), "+r" (i));
> atomic_t test_then_add (int i, atomic_t* v)
> atomic_t old = *v;
> v->counter += i;
> return old;
There is no way to do this (without waiting and trying again type
code) that I know of on i386. However, you can test for zeroness of
the result, or for <= 0, or a few other options.
int test_and_add (atomic_t i, atomic_t *v)
char was_nonzero; /* MUST BE CHAR!!! */
asm volatile("lock; addl %2,%0; setz %1"
: "+m" (*v), "=rm" (was_nonzero)
: "g" (i));
-- <email@example.com> at work, <firstname.lastname@example.org> in private! "Unix gives you enough rope to shoot yourself in the foot." http://www.zytor.com/~hpa/puzzle.txt <email@example.com> - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to firstname.lastname@example.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/