1 /* Copyright (C) 2005, 2008, 2009 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@redhat.com>.
4 This file is part of the GNU OpenMP Library (libgomp).
6 Libgomp is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
25 /* Provide target-specific access to the futex system call. */
29 # define SYS_futex 202
33 futex_wait (int *addr
, int val
)
35 register long r10
__asm__("%r10");
39 __asm
volatile ("syscall"
41 : "0" (SYS_futex
), "D" (addr
), "S" (gomp_futex_wait
),
43 : "r11", "rcx", "memory");
44 if (__builtin_expect (res
== -ENOSYS
, 0))
46 gomp_futex_wait
&= ~FUTEX_PRIVATE_FLAG
;
47 gomp_futex_wake
&= ~FUTEX_PRIVATE_FLAG
;
49 __asm
volatile ("syscall"
51 : "0" (SYS_futex
), "D" (addr
), "S" (gomp_futex_wait
),
53 : "r11", "rcx", "memory");
58 futex_wake (int *addr
, int count
)
62 __asm
volatile ("syscall"
64 : "0" (SYS_futex
), "D" (addr
), "S" (gomp_futex_wake
),
66 : "r11", "rcx", "memory");
67 if (__builtin_expect (res
== -ENOSYS
, 0))
69 gomp_futex_wait
&= ~FUTEX_PRIVATE_FLAG
;
70 gomp_futex_wake
&= ~FUTEX_PRIVATE_FLAG
;
71 __asm
volatile ("syscall"
73 : "0" (SYS_futex
), "D" (addr
), "S" (gomp_futex_wake
),
75 : "r11", "rcx", "memory");
80 # define SYS_futex 240
86 sys_futex0 (int *addr
, int op
, int val
)
90 __asm
volatile ("xchgl\t%%ebx, %2\n\t"
94 : "0"(SYS_futex
), "r" (addr
), "c"(op
),
103 sys_futex0 (int *addr
, int op
, int val
)
107 __asm
volatile ("int $0x80"
109 : "0"(SYS_futex
), "b" (addr
), "c"(op
),
115 # endif /* __PIC__ */
118 futex_wait (int *addr
, int val
)
120 long res
= sys_futex0 (addr
, gomp_futex_wait
, val
);
121 if (__builtin_expect (res
== -ENOSYS
, 0))
123 gomp_futex_wait
&= ~FUTEX_PRIVATE_FLAG
;
124 gomp_futex_wake
&= ~FUTEX_PRIVATE_FLAG
;
125 sys_futex0 (addr
, gomp_futex_wait
, val
);
130 futex_wake (int *addr
, int count
)
132 long res
= sys_futex0 (addr
, gomp_futex_wake
, count
);
133 if (__builtin_expect (res
== -ENOSYS
, 0))
135 gomp_futex_wait
&= ~FUTEX_PRIVATE_FLAG
;
136 gomp_futex_wake
&= ~FUTEX_PRIVATE_FLAG
;
137 sys_futex0 (addr
, gomp_futex_wake
, count
);
141 #endif /* __x86_64__ */
146 __asm
volatile ("rep; nop" : : : "memory");