libstdc++: gthr-single.h Source File

libstdc++

gthr-single.h
1/* Threads compatibility routines for libgcc2 and libobjc. */
2/* Compile this one with gcc. */
3/* Copyright (C) 1997-2026 Free Software Foundation, Inc.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17Under Section 7 of GPL version 3, you are granted additional
18permissions described in the GCC Runtime Library Exception, version
193.1, as published by the Free Software Foundation.
20
21You should have received a copy of the GNU General Public License and
22a copy of the GCC Runtime Library Exception along with this program;
23see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24<http://www.gnu.org/licenses/>. */
25
26#ifndef _GLIBCXX_GCC_GTHR_SINGLE_H
27#define _GLIBCXX_GCC_GTHR_SINGLE_H
28
29/* Just provide compatibility for mutex handling. */
30
31typedef int __gthread_key_t;
32typedef int __gthread_once_t;
33typedef int __gthread_mutex_t;
34typedef int __gthread_recursive_mutex_t;
35
36#define __GTHREAD_ONCE_INIT 0
37#define __GTHREAD_MUTEX_INIT 0
38#define __GTHREAD_MUTEX_INIT_FUNCTION(mx) do {} while (0)
39#define __GTHREAD_RECURSIVE_MUTEX_INIT 0
40
41#ifdef __has_attribute
42# if __has_attribute(__always_inline__)
43# define __GTHREAD_ALWAYS_INLINE __attribute__((__always_inline__))
44# endif
45#endif
46#ifndef __GTHREAD_ALWAYS_INLINE
47# define __GTHREAD_ALWAYS_INLINE
48#endif
49
50#ifdef __cplusplus
51# define __GTHREAD_INLINE inline __GTHREAD_ALWAYS_INLINE
52#else
53# define __GTHREAD_INLINE static inline
54#endif
55
56#define _GLIBCXX_UNUSED __attribute__((__unused__))
57
58#ifdef _LIBOBJC
59
60/* Thread local storage for a single thread */
61static void *thread_local_storage = NULL;
62
63/* Backend initialization functions */
64
65/* Initialize the threads subsystem. */
66static inline int
67__gthread_objc_init_thread_system (void)
68{
69 /* No thread support available */
70 return -1;
71}
72
73/* Close the threads subsystem. */
74static inline int
75__gthread_objc_close_thread_system (void)
76{
77 /* No thread support available */
78 return -1;
79}
80
81/* Backend thread functions */
82
83/* Create a new thread of execution. */
84static inline objc_thread_t
85__gthread_objc_thread_detach (void (* func)(void *), void * arg _GLIBCXX_UNUSED)
86{
87 /* No thread support available */
88 return NULL;
89}
90
91/* Set the current thread's priority. */
92static inline int
93__gthread_objc_thread_set_priority (int priority _GLIBCXX_UNUSED)
94{
95 /* No thread support available */
96 return -1;
97}
98
99/* Return the current thread's priority. */
100static inline int
101__gthread_objc_thread_get_priority (void)
102{
103 return OBJC_THREAD_INTERACTIVE_PRIORITY;
104}
105
106/* Yield our process time to another thread. */
107static inline void
108__gthread_objc_thread_yield (void)
109{
110 return;
111}
112
113/* Terminate the current thread. */
114static inline int
115__gthread_objc_thread_exit (void)
116{
117 /* No thread support available */
118 /* Should we really exit the program */
119 /* exit (&__objc_thread_exit_status); */
120 return -1;
121}
122
123/* Returns an integer value which uniquely describes a thread. */
124static inline objc_thread_t
125__gthread_objc_thread_id (void)
126{
127 /* No thread support, use 1. */
128 return (objc_thread_t) 1;
129}
130
131/* Sets the thread's local storage pointer. */
132static inline int
133__gthread_objc_thread_set_data (void *value)
134{
135 thread_local_storage = value;
136 return 0;
137}
138
139/* Returns the thread's local storage pointer. */
140static inline void *
141__gthread_objc_thread_get_data (void)
142{
143 return thread_local_storage;
144}
145
146/* Backend mutex functions */
147
148/* Allocate a mutex. */
149static inline int
150__gthread_objc_mutex_allocate (objc_mutex_t mutex _GLIBCXX_UNUSED)
151{
152 return 0;
153}
154
155/* Deallocate a mutex. */
156static inline int
157__gthread_objc_mutex_deallocate (objc_mutex_t mutex _GLIBCXX_UNUSED)
158{
159 return 0;
160}
161
162/* Grab a lock on a mutex. */
163static inline int
164__gthread_objc_mutex_lock (objc_mutex_t mutex _GLIBCXX_UNUSED)
165{
166 /* There can only be one thread, so we always get the lock */
167 return 0;
168}
169
170/* Try to grab a lock on a mutex. */
171static inline int
172__gthread_objc_mutex_trylock (objc_mutex_t mutex _GLIBCXX_UNUSED)
173{
174 /* There can only be one thread, so we always get the lock */
175 return 0;
176}
177
178/* Unlock the mutex */
179static inline int
180__gthread_objc_mutex_unlock (objc_mutex_t mutex _GLIBCXX_UNUSED)
181{
182 return 0;
183}
184
185/* Backend condition mutex functions */
186
187/* Allocate a condition. */
188static inline int
189__gthread_objc_condition_allocate (objc_condition_t condition _GLIBCXX_UNUSED)
190{
191 return 0;
192}
193
194/* Deallocate a condition. */
195static inline int
196__gthread_objc_condition_deallocate (objc_condition_t condition _GLIBCXX_UNUSED)
197{
198 return 0;
199}
200
201/* Wait on the condition */
202static inline int
203__gthread_objc_condition_wait (objc_condition_t condition _GLIBCXX_UNUSED,
204 objc_mutex_t mutex _GLIBCXX_UNUSED)
205{
206 return 0;
207}
208
209/* Wake up all threads waiting on this condition. */
210static inline int
211__gthread_objc_condition_broadcast (objc_condition_t condition _GLIBCXX_UNUSED)
212{
213 return 0;
214}
215
216/* Wake up one thread waiting on this condition. */
217static inline int
218__gthread_objc_condition_signal (objc_condition_t condition _GLIBCXX_UNUSED)
219{
220 return 0;
221}
222
223#else /* _LIBOBJC */
224
225__GTHREAD_INLINE int
226__gthread_active_p (void)
227{
228 return 0;
229}
230
231__GTHREAD_INLINE int
232__gthread_once (__gthread_once_t *__once _GLIBCXX_UNUSED, void (*__func) (void) _GLIBCXX_UNUSED)
233{
234 return 0;
235}
236
237__GTHREAD_INLINE int _GLIBCXX_UNUSED
238__gthread_key_create (__gthread_key_t *__key _GLIBCXX_UNUSED, void (*__func) (void *) _GLIBCXX_UNUSED)
239{
240 return 0;
241}
242
243__GTHREAD_INLINE int _GLIBCXX_UNUSED
244__gthread_key_delete (__gthread_key_t __key _GLIBCXX_UNUSED)
245{
246 return 0;
247}
248
249__GTHREAD_INLINE void *
250__gthread_getspecific (__gthread_key_t __key _GLIBCXX_UNUSED)
251{
252 return 0;
253}
254
255__GTHREAD_INLINE int
256__gthread_setspecific (__gthread_key_t __key _GLIBCXX_UNUSED, const void *__v _GLIBCXX_UNUSED)
257{
258 return 0;
259}
260
261__GTHREAD_INLINE int
262__gthread_mutex_destroy (__gthread_mutex_t *__mutex _GLIBCXX_UNUSED)
263{
264 return 0;
265}
266
267__GTHREAD_INLINE int
268__gthread_mutex_lock (__gthread_mutex_t *__mutex _GLIBCXX_UNUSED)
269{
270 return 0;
271}
272
273__GTHREAD_INLINE int
274__gthread_mutex_trylock (__gthread_mutex_t *__mutex _GLIBCXX_UNUSED)
275{
276 return 0;
277}
278
279__GTHREAD_INLINE int
280__gthread_mutex_unlock (__gthread_mutex_t *__mutex _GLIBCXX_UNUSED)
281{
282 return 0;
283}
284
285__GTHREAD_INLINE int
286__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
287{
288 return __gthread_mutex_lock (__mutex);
289}
290
291__GTHREAD_INLINE int
292__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
293{
294 return __gthread_mutex_trylock (__mutex);
295}
296
297__GTHREAD_INLINE int
298__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
299{
300 return __gthread_mutex_unlock (__mutex);
301}
302
303__GTHREAD_INLINE int
304__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex)
305{
306 return __gthread_mutex_destroy (__mutex);
307}
308
309#endif /* _LIBOBJC */
310
311#undef _GLIBCXX_UNUSED
312#undef __GTHREAD_INLINE
313#undef __GTHREAD_ALWAYS_INLINE
314
315#endif /* ! _GLIBCXX_GCC_GTHR_SINGLE_H */