/** Only gcc 4.1.0 and later have atomic builtins. */
-#ifndef HAVE_BUILTIN_ATOMIC
+#if defined(HAVE_BUILTIN_ATOMIC)
static __inline__
-int __sync_add_and_fetch(int* p, int i)
+int sync_add_and_fetch(int* p, int i)
+{
+ return __sync_add_and_fetch(p, i);
+}
+#else
+static __inline__
+int sync_add_and_fetch(int* p, int i)
{
if (i == 0)
return *p;
static void* thread_func_1(void* arg)
{
s_y = 1;
- (void) __sync_add_and_fetch(&s_x, 1);
+ (void) sync_add_and_fetch(&s_x, 1);
return 0;
}
static void* thread_func_2(void* arg)
{
- while (__sync_add_and_fetch(&s_x, 0) == 0)
+ while (sync_add_and_fetch(&s_x, 0) == 0)
;
fprintf(stderr, "y = %d\n", s_y);
return 0;