update x86 atomic, add test atomic
authorMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Tue, 22 Sep 2009 20:41:24 +0000 (16:41 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Tue, 22 Sep 2009 20:41:24 +0000 (16:41 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
arch_atomic_x86.h
tests/Makefile.inc
tests/test_atomic.c [new file with mode: 0644]

index a762a5ce8b366b74bbff3333607f776c0d18fbcb..3422cb4734a0a5e2dd57ff2147f86cd783b58c97 100644 (file)
@@ -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)                                               \
index 0d696887d0259fa922bfe91bbff91d5cc1675ed2..ccbaad1fd92be590b960a1a978f072947f1a5077 100644 (file)
@@ -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 (file)
index 0000000..47cc319
--- /dev/null
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <arch_atomic.h>
+#include <assert.h>
+
+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);
+}
This page took 0.033626 seconds and 4 git commands to generate.