1 /* Copyright (C) 2005-2015 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@redhat.com>.
4 This file is part of the GNU Offloading and Multi Processing Library
7 Libgomp is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 /* Provide target-specific access to the futex system call. */
30 # define SYS_futex 202
34 futex_wait (int *addr
, int val
)
36 register long r10
__asm__("%r10");
40 __asm
volatile ("syscall"
42 : "0" (SYS_futex
), "D" (addr
), "S" (gomp_futex_wait
),
44 : "r11", "rcx", "memory");
45 if (__builtin_expect (res
== -ENOSYS
, 0))
47 gomp_futex_wait
&= ~FUTEX_PRIVATE_FLAG
;
48 gomp_futex_wake
&= ~FUTEX_PRIVATE_FLAG
;
50 __asm
volatile ("syscall"
52 : "0" (SYS_futex
), "D" (addr
), "S" (gomp_futex_wait
),
54 : "r11", "rcx", "memory");
59 futex_wake (int *addr
, int count
)
63 __asm
volatile ("syscall"
65 : "0" (SYS_futex
), "D" (addr
), "S" (gomp_futex_wake
),
67 : "r11", "rcx", "memory");
68 if (__builtin_expect (res
== -ENOSYS
, 0))
70 gomp_futex_wait
&= ~FUTEX_PRIVATE_FLAG
;
71 gomp_futex_wake
&= ~FUTEX_PRIVATE_FLAG
;
72 __asm
volatile ("syscall"
74 : "0" (SYS_futex
), "D" (addr
), "S" (gomp_futex_wake
),
76 : "r11", "rcx", "memory");
81 # define SYS_futex 240
85 sys_futex0 (int *addr
, int op
, int val
)
89 __asm
volatile ("int $0x80"
91 : "0"(SYS_futex
), "b" (addr
), "c"(op
),
98 futex_wait (int *addr
, int val
)
100 long res
= sys_futex0 (addr
, gomp_futex_wait
, val
);
101 if (__builtin_expect (res
== -ENOSYS
, 0))
103 gomp_futex_wait
&= ~FUTEX_PRIVATE_FLAG
;
104 gomp_futex_wake
&= ~FUTEX_PRIVATE_FLAG
;
105 sys_futex0 (addr
, gomp_futex_wait
, val
);
110 futex_wake (int *addr
, int count
)
112 long res
= sys_futex0 (addr
, gomp_futex_wake
, count
);
113 if (__builtin_expect (res
== -ENOSYS
, 0))
115 gomp_futex_wait
&= ~FUTEX_PRIVATE_FLAG
;
116 gomp_futex_wake
&= ~FUTEX_PRIVATE_FLAG
;
117 sys_futex0 (addr
, gomp_futex_wake
, count
);
121 #endif /* __x86_64__ */
126 __builtin_ia32_pause ();