1 /* Threads compatibility routines for libgcc2 and libobjc. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1997, 1999, 2000 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, 59 Temple Place - Suite 330, 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_mutex_t
;
35 typedef int __gthread_recursive_mutex_t
;
37 #define __GTHREAD_MUTEX_INIT 0
42 #define UNUSED(x) x __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 * UNUSED(arg
))
74 /* No thread support available */
78 /* Set the current thread's priority. */
80 __gthread_objc_thread_set_priority (int UNUSED(priority
))
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
UNUSED(mutex
))
142 /* Deallocate a mutex. */
144 __gthread_objc_mutex_deallocate (objc_mutex_t
UNUSED(mutex
))
149 /* Grab a lock on a mutex. */
151 __gthread_objc_mutex_lock (objc_mutex_t
UNUSED(mutex
))
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
UNUSED(mutex
))
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
UNUSED(mutex
))
172 /* Backend condition mutex functions */
174 /* Allocate a condition. */
176 __gthread_objc_condition_allocate (objc_condition_t
UNUSED(condition
))
181 /* Deallocate a condition. */
183 __gthread_objc_condition_deallocate (objc_condition_t
UNUSED(condition
))
188 /* Wait on the condition */
190 __gthread_objc_condition_wait (objc_condition_t
UNUSED(condition
),
191 objc_mutex_t
UNUSED(mutex
))
196 /* Wake up all threads waiting on this condition. */
198 __gthread_objc_condition_broadcast (objc_condition_t
UNUSED(condition
))
203 /* Wake up one thread waiting on this condition. */
205 __gthread_objc_condition_signal (objc_condition_t
UNUSED(condition
))
213 __gthread_active_p (void)
219 __gthread_mutex_lock (__gthread_mutex_t
* UNUSED(mutex
))
225 __gthread_mutex_trylock (__gthread_mutex_t
* UNUSED(mutex
))
231 __gthread_mutex_unlock (__gthread_mutex_t
* UNUSED(mutex
))
237 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t
*mutex
)
239 return __gthread_mutex_lock (mutex
);
243 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t
*mutex
)
245 return __gthread_mutex_trylock (mutex
);
249 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t
*mutex
)
251 return __gthread_mutex_unlock (mutex
);
254 #endif /* _LIBOBJC */
258 #endif /* ! GCC_GTHR_SINGLE_H */