-/* Copyright (C) 2005 Free Software Foundation, Inc.
+/* Copyright (C) 2005, 2008 Free Software Foundation, Inc.
Contributed by Jakub Jelinek <jakub@redhat.com>.
This file is part of the GNU OpenMP Library (libgomp).
/* Provide target-specific access to the futex system call. */
#include <sys/syscall.h>
-#define FUTEX_WAIT 0
-#define FUTEX_WAKE 1
-static inline void
+static inline long
sys_futex0 (int *addr, int op, int val)
{
register long int g1 __asm__ ("g1");
o3 = 0;
#ifdef __arch64__
-# define SYSCALL_STRING "ta\t0x6d"
+# define SYSCALL_STRING "ta\t0x6d; bcs,a,pt %%xcc, 1f; sub %%g0, %%o0, %%o0; 1:"
#else
-# define SYSCALL_STRING "ta\t0x10"
+# define SYSCALL_STRING "ta\t0x10; bcs,a 1f; sub %%g0, %%o0, %%o0; 1:"
#endif
__asm volatile (SYSCALL_STRING
"f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62",
#endif
"cc", "memory");
+ return o0;
}
static inline void
futex_wait (int *addr, int val)
{
- sys_futex0 (addr, FUTEX_WAIT, val);
+ long err = sys_futex0 (addr, gomp_futex_wait, val);
+ if (__builtin_expect (err == ENOSYS, 0))
+ {
+ gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
+ gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
+ sys_futex0 (addr, gomp_futex_wait, val);
+ }
}
static inline void
futex_wake (int *addr, int count)
{
- sys_futex0 (addr, FUTEX_WAKE, count);
+ long err = sys_futex0 (addr, gomp_futex_wake, count);
+ if (__builtin_expect (err == ENOSYS, 0))
+ {
+ gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
+ gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
+ sys_futex0 (addr, gomp_futex_wake, count);
+ }
+}
+
+static inline void
+cpu_relax (void)
+{
+#if defined __arch64__ || defined __sparc_v9__
+ __asm volatile ("membar #LoadLoad" : : : "memory");
+#else
+ __asm volatile ("" : : : "memory");
+#endif
+}
+
+static inline void
+atomic_write_barrier (void)
+{
+#if defined __arch64__ || defined __sparc_v9__
+ __asm volatile ("membar #StoreStore" : : : "memory");
+#else
+ __sync_synchronize ();
+#endif
}