gthr-single.h revision 117395
1/* Threads compatibility routines for libgcc2 and libobjc.  */
2/* Compile this one with gcc.  */
3/* Copyright (C) 1997, 1999, 2000 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 2, 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
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING.  If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA.  */
21
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.  */
28
29#ifndef GCC_GTHR_SINGLE_H
30#define GCC_GTHR_SINGLE_H
31
32/* Just provide compatibility for mutex handling.  */
33
34typedef int __gthread_mutex_t;
35
36#define __GTHREAD_MUTEX_INIT 0
37
38#ifdef __cplusplus
39#define UNUSED(x)
40#else
41#define UNUSED(x) x __attribute__((unused))
42#endif
43
44#ifdef _LIBOBJC
45
46/* Thread local storage for a single thread */
47static void *thread_local_storage = NULL;
48
49/* Backend initialization functions */
50
51/* Initialize the threads subsystem.  */
52static inline int
53__gthread_objc_init_thread_system (void)
54{
55  /* No thread support available */
56  return -1;
57}
58
59/* Close the threads subsystem.  */
60static inline int
61__gthread_objc_close_thread_system (void)
62{
63  /* No thread support available */
64  return -1;
65}
66
67/* Backend thread functions */
68
69/* Create a new thread of execution.  */
70static inline objc_thread_t
71__gthread_objc_thread_detach (void (* func)(void *), void * UNUSED(arg))
72{
73  /* No thread support available */
74  return NULL;
75}
76
77/* Set the current thread's priority.  */
78static inline int
79__gthread_objc_thread_set_priority (int UNUSED(priority))
80{
81  /* No thread support available */
82  return -1;
83}
84
85/* Return the current thread's priority.  */
86static inline int
87__gthread_objc_thread_get_priority (void)
88{
89  return OBJC_THREAD_INTERACTIVE_PRIORITY;
90}
91
92/* Yield our process time to another thread.  */
93static inline void
94__gthread_objc_thread_yield (void)
95{
96  return;
97}
98
99/* Terminate the current thread.  */
100static inline int
101__gthread_objc_thread_exit (void)
102{
103  /* No thread support available */
104  /* Should we really exit the program */
105  /* exit (&__objc_thread_exit_status); */
106  return -1;
107}
108
109/* Returns an integer value which uniquely describes a thread.  */
110static inline objc_thread_t
111__gthread_objc_thread_id (void)
112{
113  /* No thread support, use 1.  */
114  return (objc_thread_t) 1;
115}
116
117/* Sets the thread's local storage pointer.  */
118static inline int
119__gthread_objc_thread_set_data (void *value)
120{
121  thread_local_storage = value;
122  return 0;
123}
124
125/* Returns the thread's local storage pointer.  */
126static inline void *
127__gthread_objc_thread_get_data (void)
128{
129  return thread_local_storage;
130}
131
132/* Backend mutex functions */
133
134/* Allocate a mutex.  */
135static inline int
136__gthread_objc_mutex_allocate (objc_mutex_t UNUSED(mutex))
137{
138  return 0;
139}
140
141/* Deallocate a mutex.  */
142static inline int
143__gthread_objc_mutex_deallocate (objc_mutex_t UNUSED(mutex))
144{
145  return 0;
146}
147
148/* Grab a lock on a mutex.  */
149static inline int
150__gthread_objc_mutex_lock (objc_mutex_t UNUSED(mutex))
151{
152  /* There can only be one thread, so we always get the lock */
153  return 0;
154}
155
156/* Try to grab a lock on a mutex.  */
157static inline int
158__gthread_objc_mutex_trylock (objc_mutex_t UNUSED(mutex))
159{
160  /* There can only be one thread, so we always get the lock */
161  return 0;
162}
163
164/* Unlock the mutex */
165static inline int
166__gthread_objc_mutex_unlock (objc_mutex_t UNUSED(mutex))
167{
168  return 0;
169}
170
171/* Backend condition mutex functions */
172
173/* Allocate a condition.  */
174static inline int
175__gthread_objc_condition_allocate (objc_condition_t UNUSED(condition))
176{
177  return 0;
178}
179
180/* Deallocate a condition.  */
181static inline int
182__gthread_objc_condition_deallocate (objc_condition_t UNUSED(condition))
183{
184  return 0;
185}
186
187/* Wait on the condition */
188static inline int
189__gthread_objc_condition_wait (objc_condition_t UNUSED(condition),
190			       objc_mutex_t UNUSED(mutex))
191{
192  return 0;
193}
194
195/* Wake up all threads waiting on this condition.  */
196static inline int
197__gthread_objc_condition_broadcast (objc_condition_t UNUSED(condition))
198{
199  return 0;
200}
201
202/* Wake up one thread waiting on this condition.  */
203static inline int
204__gthread_objc_condition_signal (objc_condition_t UNUSED(condition))
205{
206  return 0;
207}
208
209#else /* _LIBOBJC */
210
211static inline int
212__gthread_active_p (void)
213{
214  return 0;
215}
216
217static inline int
218__gthread_mutex_lock (__gthread_mutex_t * UNUSED(mutex))
219{
220  return 0;
221}
222
223static inline int
224__gthread_mutex_trylock (__gthread_mutex_t * UNUSED(mutex))
225{
226  return 0;
227}
228
229static inline int
230__gthread_mutex_unlock (__gthread_mutex_t * UNUSED(mutex))
231{
232  return 0;
233}
234
235#endif /* _LIBOBJC */
236
237#undef UNUSED
238
239#endif /* ! GCC_GTHR_SINGLE_H */
240