3 #include <urcu/uatomic_arch.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 uatomic_add(ptr, 10); \
28 assert(uatomic_read(ptr) == 10); \
29 uatomic_add(ptr, -11UL); \
30 assert(uatomic_read(ptr) == (__typeof__(*(ptr)))-1UL); \
31 v = uatomic_cmpxchg(ptr, -1UL, 22); \
32 assert(uatomic_read(ptr) == 22); \
33 assert(v == (__typeof__(*(ptr)))-1UL); \
34 v = uatomic_cmpxchg(ptr, 33, 44); \
35 assert(uatomic_read(ptr) == 22); \
37 v = uatomic_xchg(ptr, 55); \
38 assert(uatomic_read(ptr) == 55); \
40 uatomic_set(ptr, 22); \
42 assert(uatomic_read(ptr) == 23); \
44 assert(uatomic_read(ptr) == 22); \
45 v = uatomic_add_return(ptr, 100); \
47 assert(uatomic_read(ptr) == 122); \
48 v = uatomic_sub_return(ptr, 1); \
50 assert(uatomic_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.031073 seconds and 4 git commands to generate.