6 /* Simple test program, no race. Parent and child both modify x and
7 use the hardware bus lock. */
10 #undef PLAT_amd64_darwin
11 #undef PLAT_x86_freebsd
12 #undef PLAT_amd64_freebsd
13 #undef PLAT_arm64_freebsd
15 #undef PLAT_amd64_linux
16 #undef PLAT_ppc32_linux
17 #undef PLAT_ppc64_linux
19 #undef PLAT_arm64_linux
20 #undef PLAT_s390x_linux
21 #undef PLAT_mips32_linux
22 #undef PLAT_x86_solaris
23 #undef PLAT_amd64_solaris
25 #if defined(__APPLE__) && defined(__i386__)
26 # define PLAT_x86_darwin 1
27 #elif defined(__APPLE__) && defined(__x86_64__)
28 # define PLAT_amd64_darwin 1
29 #elif defined(__FreeBSD__) && defined(__i386__)
30 # define PLAT_x86_freebsd 1
31 #elif defined(__FreeBSD__) && defined(__amd64__)
32 # define PLAT_amd64_freebsd 1
33 #elif defined(__FreeBSD__) && defined(__aarch64__)
34 # define PLAT_arm64_freebsd 1
35 #elif defined(__linux__) && defined(__i386__)
36 # define PLAT_x86_linux 1
37 #elif defined(__linux__) && defined(__x86_64__)
38 # define PLAT_amd64_linux 1
39 #elif defined(__linux__) && defined(__powerpc__) && !defined(__powerpc64__)
40 # define PLAT_ppc32_linux 1
41 #elif defined(__linux__) && defined(__powerpc__) && defined(__powerpc64__)
42 # define PLAT_ppc64_linux 1
43 #elif defined(__linux__) && defined(__arm__) && !defined(__aarch64__)
44 # define PLAT_arm_linux 1
45 #elif defined(__linux__) && defined(__aarch64__) && !defined(__arm__)
46 # define PLAT_arm64_linux 1
47 #elif defined(__linux__) && defined(__s390x__)
48 # define PLAT_s390x_linux 1
49 #elif defined(__linux__) && defined(__mips__)
50 # define PLAT_mips32_linux 1
51 #elif defined(__linux__) && defined(__nanomips__)
52 # define PLAT_nanomips_linux 1
53 #elif defined(__sun__) && defined(__i386__)
54 # define PLAT_x86_solaris 1
55 #elif defined(__sun__) && defined(__x86_64__)
56 # define PLAT_amd64_solaris 1
59 #if defined(PLAT_amd64_linux) || defined(PLAT_x86_linux) \
60 || defined(PLAT_amd64_darwin) || defined(PLAT_x86_darwin) \
61 || defined(PLAT_amd64_solaris) || defined(PLAT_x86_solaris) \
62 || defined(PLAT_amd64_freebsd) || defined(PLAT_x86_freebsd)
63 # define INC(_lval,_lqual) \
64 __asm__ __volatile__ ( \
65 "lock ; incl (%0)" : /*out*/ : /*in*/"r"(&(_lval)) : "memory", "cc" )
66 #elif defined(PLAT_ppc32_linux) || defined(PLAT_ppc64_linux)
67 # define INC(_lval,_lqual) \
68 __asm__ __volatile__( \
74 : /*out*/ : /*in*/ "b"(&(_lval)) \
75 : /*trash*/ "r15", "cr0", "memory" \
77 #elif defined(PLAT_arm_linux)
78 # define INC(_lval,_lqual) \
79 __asm__ __volatile__( \
81 " ldrex r8, [%0, #0]\n" \
83 " strex r9, r8, [%0, #0]\n" \
86 : /*out*/ : /*in*/ "r"(&(_lval)) \
87 : /*trash*/ "r8", "r9", "cc", "memory" \
89 #elif defined(PLAT_arm64_linux) || defined(PLAT_arm64_freebsd)
90 # define INC(_lval,_lqual) \
91 __asm__ __volatile__( \
93 " ldxr w8, [%0, #0]\n" \
95 " stxr w9, w8, [%0, #0]\n" \
98 : /*out*/ : /*in*/ "r"(&(_lval)) \
99 : /*trash*/ "x8", "x9", "cc", "memory" \
101 #elif defined(PLAT_s390x_linux)
102 # define INC(_lval,_lqual) \
103 __asm__ __volatile__( \
109 : "+m" (_lval) :: "cc", "1","2" \
111 #elif defined(PLAT_mips32_linux)
112 # define INC(_lval,_lqual) \
113 __asm__ __volatile__ ( \
117 " addiu $9, $9, 1\n" \
120 " bne $9, $10, 1b\n" \
122 : /*out*/ : /*in*/ "r"(&(_lval)) \
123 : /*trash*/ "$8", "$9", "$10", "cc", "memory" \
125 #elif defined(PLAT_nanomips_linux)
126 # define INC(_lval,_lqual) \
127 __asm__ __volatile__ ( \
130 " ll $t1, 0($t0)\n" \
131 " addiu $t1, $t1, 1\n" \
132 " sc $t1, 0($t0)\n" \
133 " beqc $t1, $zero, 1b\n" \
134 : /*out*/ : /*in*/ "r"(&(_lval)) \
135 : /*trash*/ "$t0", "$t1", "memory" \
138 # error "Fix Me for this platform"
144 void* child_fn ( void* arg
)
154 if (pthread_create(&child
, NULL
, child_fn
, NULL
)) {
155 perror("pthread_create");
161 if (pthread_join(child
, NULL
)) {
162 perror("pthread join");
166 printf("x = %d\n", x
);