2 /* FIXME: this is basically a bad test as it is scheduling-
3 sensitive. Sometimes the output is:
20 /* Simple test program, no race. Parent writes atomically to a counter
21 whilst child reads it. When counter reaches a prearranged value,
22 child joins back to parent. Parent (writer) uses hardware bus lock;
23 child is only reading and so does not need to use a bus lock. */
25 #undef PLAT_ppc64_aix5
26 #undef PLAT_ppc32_aix5
27 #undef PLAT_x86_darwin
28 #undef PLAT_amd64_darwin
30 #undef PLAT_amd64_linux
31 #undef PLAT_ppc32_linux
32 #undef PLAT_ppc64_linux
34 #undef PLAT_s390x_linux
36 #if defined(_AIX) && defined(__64BIT__)
37 # define PLAT_ppc64_aix5 1
38 #elif defined(_AIX) && !defined(__64BIT__)
39 # define PLAT_ppc32_aix5 1
40 #elif defined(__APPLE__) && defined(__i386__)
41 # define PLAT_x86_darwin 1
42 #elif defined(__APPLE__) && defined(__x86_64__)
43 # define PLAT_amd64_darwin 1
44 #elif defined(__linux__) && defined(__i386__)
45 # define PLAT_x86_linux 1
46 #elif defined(__linux__) && defined(__x86_64__)
47 # define PLAT_amd64_linux 1
48 #elif defined(__linux__) && defined(__powerpc__) && !defined(__powerpc64__)
49 # define PLAT_ppc32_linux 1
50 #elif defined(__linux__) && defined(__powerpc__) && defined(__powerpc64__)
51 # define PLAT_ppc64_linux 1
52 #elif defined(__linux__) && defined(__arm__)
53 # define PLAT_arm_linux 1
54 #elif defined(__linux__) && defined(__s390x__)
55 # define PLAT_s390x_linux 1
59 #if defined(PLAT_amd64_linux) || defined(PLAT_x86_linux) \
60 || defined(PLAT_amd64_darwin) || defined(PLAT_x86_darwin)
61 # define INC(_lval,_lqual) \
62 __asm__ __volatile__ ( \
63 "lock ; incl (%0)" : /*out*/ : /*in*/"r"(&(_lval)) : "memory", "cc" )
64 #elif defined(PLAT_ppc32_linux) || defined(PLAT_ppc64_linux) \
65 || defined(PLAT_ppc32_aix5) || defined(PLAT_ppc64_aix5)
66 # define INC(_lval,_lqual) \
67 __asm__ __volatile__( \
73 : /*out*/ : /*in*/ "b"(&(_lval)) \
74 : /*trash*/ "r15", "cr0", "memory" \
76 #elif defined(PLAT_arm_linux)
77 # define INC(_lval,_lqual) \
78 __asm__ __volatile__( \
80 " ldrex r8, [%0, #0]\n" \
82 " strex r9, r8, [%0, #0]\n" \
85 : /*out*/ : /*in*/ "r"(&(_lval)) \
86 : /*trash*/ "r8", "r9", "cc", "memory" \
88 #elif defined(PLAT_s390x_linux)
89 # define INC(_lval,_lqual) \
90 __asm__ __volatile__( \
96 : "+m" (_lval) :: "cc", "0","1" \
99 # error "Fix Me for this platform"
108 void* child_fn ( void* arg )
117 printf("child: new value %d\n", oldx);
121 /* Make sure the parent doesn't starve. Seems to be a problem
122 on very slow machines. */
124 if (ctr == 2000000) sleep(1);
134 if (pthread_create(&child, NULL, child_fn, NULL)) {
135 perror("pthread_create");
139 for (i = 0; i < LIMIT; i++) {
141 if (i == 5) sleep(1); /* make sure child doesn't starve */
144 if (pthread_join(child, NULL)) {
145 perror("pthread join");
149 printf("done, x = %d\n", x);