1 /* Threads compatibility routines for libgcc2 and libobjc. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1997, 1999, 2000, 2004, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
23 /* As a special exception, if you link this library with other files,
24 some of which are compiled with GCC, to produce an executable,
25 this library does not by itself cause the resulting executable
26 to be covered by the GNU General Public License.
27 This exception does not however invalidate any other reasons why
28 the executable file might be covered by the GNU General Public License. */
30 #ifndef GCC_GTHR_SINGLE_H
31 #define GCC_GTHR_SINGLE_H
33 /* Just provide compatibility for mutex handling. */
35 typedef int __gthread_key_t
;
36 typedef int __gthread_once_t
;
37 typedef int __gthread_mutex_t
;
38 typedef int __gthread_recursive_mutex_t
;
40 #define __GTHREAD_ONCE_INIT 0
41 #define __GTHREAD_MUTEX_INIT 0
42 #define __GTHREAD_RECURSIVE_MUTEX_INIT 0
44 #define UNUSED __attribute__((unused))
48 /* Thread local storage for a single thread */
49 static void *thread_local_storage
= NULL
;
51 /* Backend initialization functions */
53 /* Initialize the threads subsystem. */
55 __gthread_objc_init_thread_system (void)
57 /* No thread support available */
61 /* Close the threads subsystem. */
63 __gthread_objc_close_thread_system (void)
65 /* No thread support available */
69 /* Backend thread functions */
71 /* Create a new thread of execution. */
72 static inline objc_thread_t
73 __gthread_objc_thread_detach (void (* func
)(void *), void * arg UNUSED
)
75 /* No thread support available */
79 /* Set the current thread's priority. */
81 __gthread_objc_thread_set_priority (int priority UNUSED
)
83 /* No thread support available */
87 /* Return the current thread's priority. */
89 __gthread_objc_thread_get_priority (void)
91 return OBJC_THREAD_INTERACTIVE_PRIORITY
;
94 /* Yield our process time to another thread. */
96 __gthread_objc_thread_yield (void)
101 /* Terminate the current thread. */
103 __gthread_objc_thread_exit (void)
105 /* No thread support available */
106 /* Should we really exit the program */
107 /* exit (&__objc_thread_exit_status); */
111 /* Returns an integer value which uniquely describes a thread. */
112 static inline objc_thread_t
113 __gthread_objc_thread_id (void)
115 /* No thread support, use 1. */
116 return (objc_thread_t
) 1;
119 /* Sets the thread's local storage pointer. */
121 __gthread_objc_thread_set_data (void *value
)
123 thread_local_storage
= value
;
127 /* Returns the thread's local storage pointer. */
129 __gthread_objc_thread_get_data (void)
131 return thread_local_storage
;
134 /* Backend mutex functions */
136 /* Allocate a mutex. */
138 __gthread_objc_mutex_allocate (objc_mutex_t mutex UNUSED
)
143 /* Deallocate a mutex. */
145 __gthread_objc_mutex_deallocate (objc_mutex_t mutex UNUSED
)
150 /* Grab a lock on a mutex. */
152 __gthread_objc_mutex_lock (objc_mutex_t mutex UNUSED
)
154 /* There can only be one thread, so we always get the lock */
158 /* Try to grab a lock on a mutex. */
160 __gthread_objc_mutex_trylock (objc_mutex_t mutex UNUSED
)
162 /* There can only be one thread, so we always get the lock */
166 /* Unlock the mutex */
168 __gthread_objc_mutex_unlock (objc_mutex_t mutex UNUSED
)
173 /* Backend condition mutex functions */
175 /* Allocate a condition. */
177 __gthread_objc_condition_allocate (objc_condition_t condition UNUSED
)
182 /* Deallocate a condition. */
184 __gthread_objc_condition_deallocate (objc_condition_t condition UNUSED
)
189 /* Wait on the condition */
191 __gthread_objc_condition_wait (objc_condition_t condition UNUSED
,
192 objc_mutex_t mutex UNUSED
)
197 /* Wake up all threads waiting on this condition. */
199 __gthread_objc_condition_broadcast (objc_condition_t condition UNUSED
)
204 /* Wake up one thread waiting on this condition. */
206 __gthread_objc_condition_signal (objc_condition_t condition UNUSED
)
214 __gthread_active_p (void)
220 __gthread_once (__gthread_once_t
*__once UNUSED
, void (*__func
) (void) UNUSED
)
225 static inline int UNUSED
226 __gthread_key_create (__gthread_key_t
*__key UNUSED
, void (*__func
) (void *) UNUSED
)
232 __gthread_key_delete (__gthread_key_t __key UNUSED
)
238 __gthread_getspecific (__gthread_key_t __key UNUSED
)
244 __gthread_setspecific (__gthread_key_t __key UNUSED
, const void *__v UNUSED
)
250 __gthread_mutex_destroy (__gthread_mutex_t
*__mutex UNUSED
)
256 __gthread_mutex_lock (__gthread_mutex_t
*__mutex UNUSED
)
262 __gthread_mutex_trylock (__gthread_mutex_t
*__mutex UNUSED
)
268 __gthread_mutex_unlock (__gthread_mutex_t
*__mutex UNUSED
)
274 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t
*__mutex
)
276 return __gthread_mutex_lock (__mutex
);
280 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t
*__mutex
)
282 return __gthread_mutex_trylock (__mutex
);
286 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t
*__mutex
)
288 return __gthread_mutex_unlock (__mutex
);
291 #endif /* _LIBOBJC */
295 #endif /* ! GCC_GTHR_SINGLE_H */