From: Mathieu Desnoyers Date: Tue, 22 Sep 2009 20:41:24 +0000 (-0400) Subject: update x86 atomic, add test atomic X-Git-Tag: v0.1~57 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a81b8e5e402188a088c28e27c5e718b691109cf2;p=urcu.git update x86 atomic, add test atomic Signed-off-by: Mathieu Desnoyers --- diff --git a/arch_atomic_x86.h b/arch_atomic_x86.h index a762a5c..3422cb4 100644 --- a/arch_atomic_x86.h +++ b/arch_atomic_x86.h @@ -159,7 +159,7 @@ unsigned long _atomic_exchange(volatile void *addr, unsigned long val, int len) /* atomic_add */ static inline __attribute__((always_inline)) -unsigned long _atomic_add(volatile void *addr, unsigned long val, int len) +void _atomic_add(volatile void *addr, unsigned long val, int len) { switch (len) { case 1: @@ -200,7 +200,7 @@ unsigned long _atomic_add(volatile void *addr, unsigned long val, int len) /* generate an illegal instruction. Cannot catch this with linker tricks * when optimizations are disabled. */ __asm__ __volatile__("ud2"); - return 0; + return; } #define atomic_add(addr, v) \ diff --git a/tests/Makefile.inc b/tests/Makefile.inc index 0d69688..ccbaad1 100644 --- a/tests/Makefile.inc +++ b/tests/Makefile.inc @@ -108,6 +108,9 @@ urcutorture: urcutorture.c rcutorture.h api.h ${URCU_SIGNAL} urcutorture-yield: urcutorture.c ${URCU_SIGNAL_YIELD} rcutorture.h api.h $(CC) -DDEBUG_YIELD ${CFLAGS} $(LDFLAGS) -o $@ $(SRC_DEP) +test_atomic: test_atomic.c ../arch_atomic.h + $(CC) ${CFLAGS} $(LDFLAGS) -o $@ $(SRC_DEP) + ,PHONY: clean clean: diff --git a/tests/test_atomic.c b/tests/test_atomic.c new file mode 100644 index 0000000..47cc319 --- /dev/null +++ b/tests/test_atomic.c @@ -0,0 +1,20 @@ +#include +#include +#include + +struct testvals { + unsigned char c; + unsigned short s; + unsigned int i; + unsigned long l; +}; + +static struct testvals vals; + +int main(int argc, void **argv) +{ + atomic_add(&vals.c, 10); + assert(vals.c == 10); + atomic_add(&vals.c, -11); + assert((char)vals.c == -1); +}