2 #include <arch_atomic.h>
5 #if (defined(__i386__) || defined(__x86_64__))
6 #define HAS_ATOMIC_BYTE
7 #define HAS_ATOMIC_SHORT
11 #ifdef HAS_ATOMIC_BYTE
14 #ifdef HAS_ATOMIC_SHORT
21 static struct testvals vals
;
23 #define do_test(ptr) \
25 __typeof__(*(ptr)) v; \
27 atomic_add(ptr, 10); \
28 assert(atomic_read(ptr) == 10); \
29 atomic_add(ptr, -11UL); \
30 assert(atomic_read(ptr) == (__typeof__(*(ptr)))-1UL); \
31 v = cmpxchg(ptr, -1UL, 22); \
32 assert(atomic_read(ptr) == 22); \
33 assert(v == (__typeof__(*(ptr)))-1UL); \
34 v = cmpxchg(ptr, 33, 44); \
35 assert(atomic_read(ptr) == 22); \
38 assert(atomic_read(ptr) == 55); \
40 atomic_set(ptr, 22); \
42 assert(atomic_read(ptr) == 23); \
44 assert(atomic_read(ptr) == 22); \
45 v = atomic_add_return(ptr, 100); \
47 assert(atomic_read(ptr) == 122); \
48 v = atomic_sub_return(ptr, 1); \
50 assert(atomic_read(ptr) == 121); \
53 int main(int argc
, char **argv
)
55 #ifdef HAS_ATOMIC_BYTE
58 #ifdef HAS_ATOMIC_SHORT
63 printf("Atomic ops test OK\n");
This page took 0.038141 seconds and 4 git commands to generate.