1 /* Threads compatibility routines for libgcc2 and libobjc. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1997, 1999, 2000, 2004, 2008 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 2, or (at your option) any later
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
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
22 /* As a special exception, if you link this library with other files,
23 some of which are compiled with GCC, to produce an executable,
24 this library does not by itself cause the resulting executable
25 to be covered by the GNU General Public License.
26 This exception does not however invalidate any other reasons why
27 the executable file might be covered by the GNU General Public License. */
29 #ifndef GCC_GTHR_SINGLE_H
30 #define GCC_GTHR_SINGLE_H
32 /* Just provide compatibility for mutex handling. */
34 typedef int __gthread_key_t
;
35 typedef int __gthread_once_t
;
36 typedef int __gthread_mutex_t
;
37 typedef int __gthread_recursive_mutex_t
;
39 #define __GTHREAD_ONCE_INIT 0
40 #define __GTHREAD_MUTEX_INIT 0
41 #define __GTHREAD_RECURSIVE_MUTEX_INIT 0
43 #define UNUSED __attribute__((unused))
47 /* Thread local storage for a single thread */
48 static void *thread_local_storage
= NULL
;
50 /* Backend initialization functions */
52 /* Initialize the threads subsystem. */
54 __gthread_objc_init_thread_system (void)
56 /* No thread support available */
60 /* Close the threads subsystem. */
62 __gthread_objc_close_thread_system (void)
64 /* No thread support available */
68 /* Backend thread functions */
70 /* Create a new thread of execution. */
71 static inline objc_thread_t
72 __gthread_objc_thread_detach (void (* func
)(void *), void * arg UNUSED
)
74 /* No thread support available */
78 /* Set the current thread's priority. */
80 __gthread_objc_thread_set_priority (int priority UNUSED
)
82 /* No thread support available */
86 /* Return the current thread's priority. */
88 __gthread_objc_thread_get_priority (void)
90 return OBJC_THREAD_INTERACTIVE_PRIORITY
;
93 /* Yield our process time to another thread. */
95 __gthread_objc_thread_yield (void)
100 /* Terminate the current thread. */
102 __gthread_objc_thread_exit (void)
104 /* No thread support available */
105 /* Should we really exit the program */
106 /* exit (&__objc_thread_exit_status); */
110 /* Returns an integer value which uniquely describes a thread. */
111 static inline objc_thread_t
112 __gthread_objc_thread_id (void)
114 /* No thread support, use 1. */
115 return (objc_thread_t
) 1;
118 /* Sets the thread's local storage pointer. */
120 __gthread_objc_thread_set_data (void *value
)
122 thread_local_storage
= value
;
126 /* Returns the thread's local storage pointer. */
128 __gthread_objc_thread_get_data (void)
130 return thread_local_storage
;
133 /* Backend mutex functions */
135 /* Allocate a mutex. */
137 __gthread_objc_mutex_allocate (objc_mutex_t mutex UNUSED
)
142 /* Deallocate a mutex. */
144 __gthread_objc_mutex_deallocate (objc_mutex_t mutex UNUSED
)
149 /* Grab a lock on a mutex. */
151 __gthread_objc_mutex_lock (objc_mutex_t mutex UNUSED
)
153 /* There can only be one thread, so we always get the lock */
157 /* Try to grab a lock on a mutex. */
159 __gthread_objc_mutex_trylock (objc_mutex_t mutex UNUSED
)
161 /* There can only be one thread, so we always get the lock */
165 /* Unlock the mutex */
167 __gthread_objc_mutex_unlock (objc_mutex_t mutex UNUSED
)
172 /* Backend condition mutex functions */
174 /* Allocate a condition. */
176 __gthread_objc_condition_allocate (objc_condition_t condition UNUSED
)
181 /* Deallocate a condition. */
183 __gthread_objc_condition_deallocate (objc_condition_t condition UNUSED
)
188 /* Wait on the condition */
190 __gthread_objc_condition_wait (objc_condition_t condition UNUSED
,
191 objc_mutex_t mutex UNUSED
)
196 /* Wake up all threads waiting on this condition. */
198 __gthread_objc_condition_broadcast (objc_condition_t condition UNUSED
)
203 /* Wake up one thread waiting on this condition. */
205 __gthread_objc_condition_signal (objc_condition_t condition UNUSED
)
213 __gthread_active_p (void)
219 __gthread_once (__gthread_once_t
*once UNUSED
, void (*func
) (void) UNUSED
)
224 static inline int UNUSED
225 __gthread_key_create (__gthread_key_t
*key UNUSED
, void (*func
) (void *) UNUSED
)
231 __gthread_key_delete (__gthread_key_t key UNUSED
)
237 __gthread_getspecific (__gthread_key_t key UNUSED
)
243 __gthread_setspecific (__gthread_key_t key UNUSED
, const void *v UNUSED
)
249 __gthread_mutex_destroy (__gthread_mutex_t
*mutex UNUSED
)
255 __gthread_mutex_lock (__gthread_mutex_t
*mutex UNUSED
)
261 __gthread_mutex_trylock (__gthread_mutex_t
*mutex UNUSED
)
267 __gthread_mutex_unlock (__gthread_mutex_t
*mutex UNUSED
)
273 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t
*mutex
)
275 return __gthread_mutex_lock (mutex
);
279 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t
*mutex
)
281 return __gthread_mutex_trylock (mutex
);
285 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t
*mutex
)
287 return __gthread_mutex_unlock (mutex
);
290 #endif /* _LIBOBJC */
294 #endif /* ! GCC_GTHR_SINGLE_H */