]>
Commit | Line | Data |
---|---|---|
76d46331 KCY |
1 | /* Threads compatibility routines for libgcc2 and libobjc. */ |
2 | /* Compile this one with gcc. */ | |
99dee823 | 3 | /* Copyright (C) 2019-2021 Free Software Foundation, Inc. |
76d46331 KCY |
4 | |
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify it under | |
8 | the terms of the GNU General Public License as published by the Free | |
9 | Software Foundation; either version 3, or (at your option) any later | |
10 | version. | |
11 | ||
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
16 | ||
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. | |
20 | ||
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/>. */ | |
25 | ||
26 | /* AMD GCN does not support dynamic creation of threads. There may be many | |
27 | hardware threads, but they're all created simultaneously at launch time. | |
28 | ||
29 | This implementation is intended to provide mutexes for libgfortran, etc. | |
30 | It is not intended to provide a TLS implementation at this time, | |
31 | although that may be added later if needed. | |
32 | ||
33 | __gthread_active_p returns "1" to ensure that mutexes are used, and that | |
34 | programs attempting to use emutls will fail with the appropriate abort. | |
35 | It is expected that the TLS tests will fail. */ | |
36 | ||
37 | #ifndef GCC_GTHR_GCN_H | |
38 | #define GCC_GTHR_GCN_H | |
39 | ||
40 | #define __GTHREADS 1 | |
41 | ||
42 | #ifdef __cplusplus | |
43 | extern "C" { | |
44 | #endif | |
45 | ||
46 | #ifdef _LIBOBJC | |
47 | #error "Objective C is not supported on AMD GCN" | |
48 | #else | |
49 | ||
50 | static inline int | |
51 | __gthread_active_p (void) | |
52 | { | |
53 | return 1; | |
54 | } | |
55 | ||
56 | typedef int __gthread_key_t; | |
57 | typedef int __gthread_once_t; | |
58 | typedef int __gthread_mutex_t; | |
59 | typedef int __gthread_recursive_mutex_t; | |
60 | ||
61 | #define __GTHREAD_ONCE_INIT 0 | |
62 | #define __GTHREAD_MUTEX_INIT 0 | |
63 | #define __GTHREAD_RECURSIVE_MUTEX_INIT 0 | |
64 | ||
65 | static inline int | |
66 | __gthread_once (__gthread_once_t *__once __attribute__((unused)), | |
67 | void (*__func) (void) __attribute__((unused))) | |
68 | { | |
69 | return 0; | |
70 | } | |
71 | ||
72 | static inline int | |
73 | __gthread_key_create (__gthread_key_t *__key __attribute__((unused)), | |
74 | void (*__dtor) (void *) __attribute__((unused))) | |
75 | { | |
76 | /* Operation is not supported. */ | |
77 | return -1; | |
78 | } | |
79 | ||
80 | static inline int | |
81 | __gthread_key_delete (__gthread_key_t __key __attribute__ ((__unused__))) | |
82 | { | |
83 | /* Operation is not supported. */ | |
84 | return -1; | |
85 | } | |
86 | ||
87 | static inline void * | |
88 | __gthread_getspecific (__gthread_key_t __key __attribute__((unused))) | |
89 | { | |
90 | return NULL; | |
91 | } | |
92 | ||
93 | static inline int | |
94 | __gthread_setspecific (__gthread_key_t __key __attribute__((unused)), | |
95 | const void *__ptr __attribute__((unused))) | |
96 | { | |
97 | /* Operation is not supported. */ | |
98 | return -1; | |
99 | } | |
100 | ||
101 | static inline int | |
102 | __gthread_mutex_destroy (__gthread_mutex_t *__mutex __attribute__((unused))) | |
103 | { | |
104 | return 0; | |
105 | } | |
106 | ||
107 | static inline int | |
108 | __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex __attribute__((unused))) | |
109 | { | |
110 | return 0; | |
111 | } | |
112 | ||
113 | ||
114 | static inline int | |
115 | __gthread_mutex_lock (__gthread_mutex_t *__mutex) | |
116 | { | |
117 | while (__sync_lock_test_and_set (__mutex, 1)) | |
118 | asm volatile ("s_sleep\t1" ::: "memory"); | |
119 | ||
120 | return 0; | |
121 | } | |
122 | ||
123 | static inline int | |
124 | __gthread_mutex_trylock (__gthread_mutex_t *__mutex) | |
125 | { | |
126 | return __sync_lock_test_and_set (__mutex, 1); | |
127 | } | |
128 | ||
129 | static inline int | |
130 | __gthread_mutex_unlock (__gthread_mutex_t *__mutex) | |
131 | { | |
132 | __sync_lock_release (__mutex); | |
133 | ||
134 | return 0; | |
135 | } | |
136 | ||
137 | static inline int | |
138 | __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex __attribute__((unused))) | |
139 | { | |
140 | /* Operation is not supported. */ | |
141 | return -1; | |
142 | } | |
143 | ||
144 | static inline int | |
145 | __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex __attribute__((unused))) | |
146 | { | |
147 | /* Operation is not supported. */ | |
148 | return -1; | |
149 | } | |
150 | ||
151 | static inline int | |
152 | __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex __attribute__((unused))) | |
153 | { | |
154 | /* Operation is not supported. */ | |
155 | return -1; | |
156 | } | |
157 | #endif /* _LIBOBJC */ | |
158 | ||
159 | #ifdef __cplusplus | |
160 | } | |
161 | #endif | |
162 | ||
163 | #endif /* ! GCC_GTHR_GCN_H */ |