]>
Commit | Line | Data |
---|---|---|
fd6481cf | 1 | /* Copyright (C) 2005, 2008 Free Software Foundation, Inc. |
1e8e9920 | 2 | Contributed by Richard Henderson <rth@redhat.com>. |
3 | ||
4 | This file is part of the GNU OpenMP Library (libgomp). | |
5 | ||
6 | Libgomp is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU Lesser General Public License as published by | |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
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 Lesser General Public License for | |
14 | more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public License | |
17 | along with libgomp; see the file COPYING.LIB. If not, write to the | |
18 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
19 | MA 02110-1301, USA. */ | |
20 | ||
21 | /* As a special exception, if you link this library with other files, some | |
22 | of which are compiled with GCC, to produce an executable, this library | |
23 | does not by itself cause the resulting executable to be covered by the | |
24 | GNU General Public License. This exception does not however invalidate | |
25 | any other reasons why the executable file might be covered by the GNU | |
26 | General Public License. */ | |
27 | ||
28 | /* Provide target-specific access to the futex system call. */ | |
29 | ||
30 | #ifndef SYS_futex | |
31 | #define SYS_futex 394 | |
32 | #endif | |
1e8e9920 | 33 | |
34 | ||
35 | static inline void | |
36 | futex_wait (int *addr, int val) | |
37 | { | |
38 | register long sc_0 __asm__("$0"); | |
39 | register long sc_16 __asm__("$16"); | |
40 | register long sc_17 __asm__("$17"); | |
41 | register long sc_18 __asm__("$18"); | |
42 | register long sc_19 __asm__("$19"); | |
43 | ||
44 | sc_0 = SYS_futex; | |
45 | sc_16 = (long) addr; | |
fd6481cf | 46 | sc_17 = gomp_futex_wait; |
1e8e9920 | 47 | sc_18 = val; |
48 | sc_19 = 0; | |
49 | __asm volatile ("callsys" | |
50 | : "=r" (sc_0), "=r"(sc_19) | |
51 | : "0"(sc_0), "r" (sc_16), "r"(sc_17), "r"(sc_18), "1"(sc_19) | |
52 | : "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", | |
53 | "$22", "$23", "$24", "$25", "$27", "$28", "memory"); | |
fd6481cf | 54 | if (__builtin_expect (sc_19, 0) && sc_0 == ENOSYS) |
55 | { | |
56 | gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG; | |
57 | gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG; | |
58 | sc_0 = SYS_futex; | |
59 | sc_17 &= ~FUTEX_PRIVATE_FLAG; | |
60 | sc_19 = 0; | |
61 | __asm volatile ("callsys" | |
62 | : "=r" (sc_0), "=r"(sc_19) | |
63 | : "0"(sc_0), "r" (sc_16), "r"(sc_17), "r"(sc_18), | |
64 | "1"(sc_19) | |
65 | : "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", | |
66 | "$22", "$23", "$24", "$25", "$27", "$28", "memory"); | |
67 | } | |
1e8e9920 | 68 | } |
69 | ||
70 | static inline void | |
71 | futex_wake (int *addr, int count) | |
72 | { | |
73 | register long sc_0 __asm__("$0"); | |
74 | register long sc_16 __asm__("$16"); | |
75 | register long sc_17 __asm__("$17"); | |
76 | register long sc_18 __asm__("$18"); | |
77 | register long sc_19 __asm__("$19"); | |
78 | ||
79 | sc_0 = SYS_futex; | |
80 | sc_16 = (long) addr; | |
fd6481cf | 81 | sc_17 = gomp_futex_wake; |
1e8e9920 | 82 | sc_18 = count; |
83 | __asm volatile ("callsys" | |
84 | : "=r" (sc_0), "=r"(sc_19) | |
85 | : "0"(sc_0), "r" (sc_16), "r"(sc_17), "r"(sc_18) | |
86 | : "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", | |
87 | "$22", "$23", "$24", "$25", "$27", "$28", "memory"); | |
fd6481cf | 88 | if (__builtin_expect (sc_19, 0) && sc_0 == ENOSYS) |
89 | { | |
90 | gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG; | |
91 | gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG; | |
92 | sc_0 = SYS_futex; | |
93 | sc_17 &= ~FUTEX_PRIVATE_FLAG; | |
94 | __asm volatile ("callsys" | |
95 | : "=r" (sc_0), "=r"(sc_19) | |
96 | : "0"(sc_0), "r" (sc_16), "r"(sc_17), "r"(sc_18) | |
97 | : "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", | |
98 | "$22", "$23", "$24", "$25", "$27", "$28", "memory"); | |
99 | } | |
100 | } | |
101 | ||
102 | static inline void | |
103 | cpu_relax (void) | |
104 | { | |
105 | __asm volatile ("" : : : "memory"); | |
106 | } | |
107 | ||
108 | static inline void | |
109 | atomic_write_barrier (void) | |
110 | { | |
111 | __asm volatile ("wmb" : : : "memory"); | |
1e8e9920 | 112 | } |