Match: Refactor the unsigned SAT_ADD match pattern [NFC]
[gcc.git] / libgcc / gthr-single.h
blob2a799ad3d3ac3726ca9fa76572a08bcc19f6f7dd
1 /* Threads compatibility routines for libgcc2 and libobjc. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1997-2024 Free Software Foundation, Inc.
5 This file is part of GCC.
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.
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.
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 #ifndef GCC_GTHR_SINGLE_H
27 #define GCC_GTHR_SINGLE_H
29 /* Just provide compatibility for mutex handling. */
31 typedef int __gthread_key_t;
32 typedef int __gthread_once_t;
33 typedef int __gthread_mutex_t;
34 typedef int __gthread_recursive_mutex_t;
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
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
50 #ifdef __cplusplus
51 # define __GTHREAD_INLINE inline __GTHREAD_ALWAYS_INLINE
52 #else
53 # define __GTHREAD_INLINE static inline
54 #endif
56 #define UNUSED __attribute__((__unused__))
58 #ifdef _LIBOBJC
60 /* Thread local storage for a single thread */
61 static void *thread_local_storage = NULL;
63 /* Backend initialization functions */
65 /* Initialize the threads subsystem. */
66 static inline int
67 __gthread_objc_init_thread_system (void)
69 /* No thread support available */
70 return -1;
73 /* Close the threads subsystem. */
74 static inline int
75 __gthread_objc_close_thread_system (void)
77 /* No thread support available */
78 return -1;
81 /* Backend thread functions */
83 /* Create a new thread of execution. */
84 static inline objc_thread_t
85 __gthread_objc_thread_detach (void (* func)(void *), void * arg UNUSED)
87 /* No thread support available */
88 return NULL;
91 /* Set the current thread's priority. */
92 static inline int
93 __gthread_objc_thread_set_priority (int priority UNUSED)
95 /* No thread support available */
96 return -1;
99 /* Return the current thread's priority. */
100 static inline int
101 __gthread_objc_thread_get_priority (void)
103 return OBJC_THREAD_INTERACTIVE_PRIORITY;
106 /* Yield our process time to another thread. */
107 static inline void
108 __gthread_objc_thread_yield (void)
110 return;
113 /* Terminate the current thread. */
114 static inline int
115 __gthread_objc_thread_exit (void)
117 /* No thread support available */
118 /* Should we really exit the program */
119 /* exit (&__objc_thread_exit_status); */
120 return -1;
123 /* Returns an integer value which uniquely describes a thread. */
124 static inline objc_thread_t
125 __gthread_objc_thread_id (void)
127 /* No thread support, use 1. */
128 return (objc_thread_t) 1;
131 /* Sets the thread's local storage pointer. */
132 static inline int
133 __gthread_objc_thread_set_data (void *value)
135 thread_local_storage = value;
136 return 0;
139 /* Returns the thread's local storage pointer. */
140 static inline void *
141 __gthread_objc_thread_get_data (void)
143 return thread_local_storage;
146 /* Backend mutex functions */
148 /* Allocate a mutex. */
149 static inline int
150 __gthread_objc_mutex_allocate (objc_mutex_t mutex UNUSED)
152 return 0;
155 /* Deallocate a mutex. */
156 static inline int
157 __gthread_objc_mutex_deallocate (objc_mutex_t mutex UNUSED)
159 return 0;
162 /* Grab a lock on a mutex. */
163 static inline int
164 __gthread_objc_mutex_lock (objc_mutex_t mutex UNUSED)
166 /* There can only be one thread, so we always get the lock */
167 return 0;
170 /* Try to grab a lock on a mutex. */
171 static inline int
172 __gthread_objc_mutex_trylock (objc_mutex_t mutex UNUSED)
174 /* There can only be one thread, so we always get the lock */
175 return 0;
178 /* Unlock the mutex */
179 static inline int
180 __gthread_objc_mutex_unlock (objc_mutex_t mutex UNUSED)
182 return 0;
185 /* Backend condition mutex functions */
187 /* Allocate a condition. */
188 static inline int
189 __gthread_objc_condition_allocate (objc_condition_t condition UNUSED)
191 return 0;
194 /* Deallocate a condition. */
195 static inline int
196 __gthread_objc_condition_deallocate (objc_condition_t condition UNUSED)
198 return 0;
201 /* Wait on the condition */
202 static inline int
203 __gthread_objc_condition_wait (objc_condition_t condition UNUSED,
204 objc_mutex_t mutex UNUSED)
206 return 0;
209 /* Wake up all threads waiting on this condition. */
210 static inline int
211 __gthread_objc_condition_broadcast (objc_condition_t condition UNUSED)
213 return 0;
216 /* Wake up one thread waiting on this condition. */
217 static inline int
218 __gthread_objc_condition_signal (objc_condition_t condition UNUSED)
220 return 0;
223 #else /* _LIBOBJC */
225 __GTHREAD_INLINE int
226 __gthread_active_p (void)
228 return 0;
231 __GTHREAD_INLINE int
232 __gthread_once (__gthread_once_t *__once UNUSED, void (*__func) (void) UNUSED)
234 return 0;
237 __GTHREAD_INLINE int UNUSED
238 __gthread_key_create (__gthread_key_t *__key UNUSED, void (*__func) (void *) UNUSED)
240 return 0;
243 __GTHREAD_INLINE int UNUSED
244 __gthread_key_delete (__gthread_key_t __key UNUSED)
246 return 0;
249 __GTHREAD_INLINE void *
250 __gthread_getspecific (__gthread_key_t __key UNUSED)
252 return 0;
255 __GTHREAD_INLINE int
256 __gthread_setspecific (__gthread_key_t __key UNUSED, const void *__v UNUSED)
258 return 0;
261 __GTHREAD_INLINE int
262 __gthread_mutex_destroy (__gthread_mutex_t *__mutex UNUSED)
264 return 0;
267 __GTHREAD_INLINE int
268 __gthread_mutex_lock (__gthread_mutex_t *__mutex UNUSED)
270 return 0;
273 __GTHREAD_INLINE int
274 __gthread_mutex_trylock (__gthread_mutex_t *__mutex UNUSED)
276 return 0;
279 __GTHREAD_INLINE int
280 __gthread_mutex_unlock (__gthread_mutex_t *__mutex UNUSED)
282 return 0;
285 __GTHREAD_INLINE int
286 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
288 return __gthread_mutex_lock (__mutex);
291 __GTHREAD_INLINE int
292 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
294 return __gthread_mutex_trylock (__mutex);
297 __GTHREAD_INLINE int
298 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
300 return __gthread_mutex_unlock (__mutex);
303 __GTHREAD_INLINE int
304 __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex)
306 return __gthread_mutex_destroy (__mutex);
309 #endif /* _LIBOBJC */
311 #undef UNUSED
312 #undef __GTHREAD_INLINE
313 #undef __GTHREAD_ALWAYS_INLINE
315 #endif /* ! GCC_GTHR_SINGLE_H */