140711Swollman/* Threads compatibility routines for libgcc2 and libobjc. */ 240711Swollman/* Compile this one with gcc. */ 340711Swollman/* Copyright (C) 1997, 1999, 2000, 2004 Free Software Foundation, Inc. 440711Swollman 540711SwollmanThis file is part of GCC. 640711Swollman 740711SwollmanGCC is free software; you can redistribute it and/or modify it under 840711Swollmanthe terms of the GNU General Public License as published by the Free 940711SwollmanSoftware Foundation; either version 2, or (at your option) any later 1040711Swollmanversion. 1140711Swollman 1240711SwollmanGCC is distributed in the hope that it will be useful, but WITHOUT ANY 1340711SwollmanWARRANTY; without even the implied warranty of MERCHANTABILITY or 1440711SwollmanFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1540711Swollmanfor more details. 1640711Swollman 1740711SwollmanYou should have received a copy of the GNU General Public License 1840711Swollmanalong with GCC; see the file COPYING. If not, write to the Free 1940711SwollmanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 2040711Swollman02110-1301, USA. */ 2140711Swollman 2240711Swollman/* As a special exception, if you link this library with other files, 2340711Swollman some of which are compiled with GCC, to produce an executable, 2440711Swollman this library does not by itself cause the resulting executable 2540711Swollman to be covered by the GNU General Public License. 2640711Swollman This exception does not however invalidate any other reasons why 2740711Swollman the executable file might be covered by the GNU General Public License. */ 2840711Swollman 2950477Speter#ifndef GCC_GTHR_SINGLE_H 3040711Swollman#define GCC_GTHR_SINGLE_H 3140711Swollman 3240711Swollman/* Just provide compatibility for mutex handling. */ 3340711Swollman 3440711Swollmantypedef int __gthread_mutex_t; 3555205Spetertypedef int __gthread_recursive_mutex_t; 3640711Swollman 3755205Speter#define __GTHREAD_MUTEX_INIT 0 3840711Swollman 3968522Smsmith#ifdef __cplusplus 4068522Smsmith#define UNUSED(x) 4168522Smsmith#else 4268522Smsmith#define UNUSED(x) x __attribute__((unused)) 4368522Smsmith#endif 4468522Smsmith 4568522Smsmith#ifdef _LIBOBJC 4668522Smsmith 4768522Smsmith/* Thread local storage for a single thread */ 4868522Smsmithstatic void *thread_local_storage = NULL; 4968522Smsmith 5068522Smsmith/* Backend initialization functions */ 5168522Smsmith 5268522Smsmith/* Initialize the threads subsystem. */ 5368522Smsmithstatic inline int 5440711Swollman__gthread_objc_init_thread_system (void) 5568522Smsmith{ 5668522Smsmith /* No thread support available */ 5768522Smsmith return -1; 5868522Smsmith} 5968522Smsmith 6068522Smsmith/* Close the threads subsystem. */ 6168522Smsmithstatic inline int 6268522Smsmith__gthread_objc_close_thread_system (void) 6368522Smsmith{ 6468522Smsmith /* No thread support available */ 6568522Smsmith return -1; 6668522Smsmith} 6768522Smsmith 6868522Smsmith/* Backend thread functions */ 6968522Smsmith 7068522Smsmith/* Create a new thread of execution. */ 7168522Smsmithstatic inline objc_thread_t 7268522Smsmith__gthread_objc_thread_detach (void (* func)(void *), void * UNUSED(arg)) 7368522Smsmith{ 7468522Smsmith /* No thread support available */ 7568522Smsmith return NULL; 7668522Smsmith} 7768522Smsmith 7868522Smsmith/* Set the current thread's priority. */ 7968522Smsmithstatic inline int 8068522Smsmith__gthread_objc_thread_set_priority (int UNUSED(priority)) 8168522Smsmith{ 8268522Smsmith /* No thread support available */ 8368522Smsmith return -1; 8440711Swollman} 8540711Swollman 8640711Swollman/* Return the current thread's priority. */ 8768527Swollmanstatic inline int 8868527Swollman__gthread_objc_thread_get_priority (void) 8968527Swollman{ 9068527Swollman return OBJC_THREAD_INTERACTIVE_PRIORITY; 9140711Swollman} 9268727Smckusick 9340711Swollman/* Yield our process time to another thread. */ 9468727Smckusickstatic inline void 9560938Sjake__gthread_objc_thread_yield (void) 9660938Sjake{ 9740711Swollman return; 9840711Swollman} 9940711Swollman 10040711Swollman/* Terminate the current thread. */ 10145720Speterstatic inline int 10245720Speter__gthread_objc_thread_exit (void) 10340711Swollman{ 10440711Swollman /* No thread support available */ 10540711Swollman /* Should we really exit the program */ 10640711Swollman /* exit (&__objc_thread_exit_status); */ 10740711Swollman return -1; 10840711Swollman} 10940711Swollman 11060938Sjake/* Returns an integer value which uniquely describes a thread. */ 11140711Swollmanstatic inline objc_thread_t 11240711Swollman__gthread_objc_thread_id (void) 11340711Swollman{ 11440711Swollman /* No thread support, use 1. */ 11540711Swollman return (objc_thread_t) 1; 11660938Sjake} 11740711Swollman 11840711Swollman/* Sets the thread's local storage pointer. */ 11940711Swollmanstatic inline int 12040711Swollman__gthread_objc_thread_set_data (void *value) 12140711Swollman{ 12240711Swollman thread_local_storage = value; 12340711Swollman return 0; 12440711Swollman} 12540711Swollman 12640711Swollman/* Returns the thread's local storage pointer. */ 12740711Swollmanstatic inline void * 12867261Simp__gthread_objc_thread_get_data (void) 12940711Swollman{ 13045720Speter return thread_local_storage; 13145720Speter} 13267267Smdodd 13345720Speter/* Backend mutex functions */ 13440711Swollman 13540711Swollman/* Allocate a mutex. */ 13645720Speterstatic inline int 13745720Speter__gthread_objc_mutex_allocate (objc_mutex_t UNUSED(mutex)) 13845720Speter{ 13945720Speter return 0; 14040711Swollman} 14140711Swollman 14255205Speter/* Deallocate a mutex. */ 14340711Swollmanstatic inline int 14440711Swollman__gthread_objc_mutex_deallocate (objc_mutex_t UNUSED(mutex)) 145{ 146 return 0; 147} 148 149/* Grab a lock on a mutex. */ 150static inline int 151__gthread_objc_mutex_lock (objc_mutex_t UNUSED(mutex)) 152{ 153 /* There can only be one thread, so we always get the lock */ 154 return 0; 155} 156 157/* Try to grab a lock on a mutex. */ 158static inline int 159__gthread_objc_mutex_trylock (objc_mutex_t UNUSED(mutex)) 160{ 161 /* There can only be one thread, so we always get the lock */ 162 return 0; 163} 164 165/* Unlock the mutex */ 166static inline int 167__gthread_objc_mutex_unlock (objc_mutex_t UNUSED(mutex)) 168{ 169 return 0; 170} 171 172/* Backend condition mutex functions */ 173 174/* Allocate a condition. */ 175static inline int 176__gthread_objc_condition_allocate (objc_condition_t UNUSED(condition)) 177{ 178 return 0; 179} 180 181/* Deallocate a condition. */ 182static inline int 183__gthread_objc_condition_deallocate (objc_condition_t UNUSED(condition)) 184{ 185 return 0; 186} 187 188/* Wait on the condition */ 189static inline int 190__gthread_objc_condition_wait (objc_condition_t UNUSED(condition), 191 objc_mutex_t UNUSED(mutex)) 192{ 193 return 0; 194} 195 196/* Wake up all threads waiting on this condition. */ 197static inline int 198__gthread_objc_condition_broadcast (objc_condition_t UNUSED(condition)) 199{ 200 return 0; 201} 202 203/* Wake up one thread waiting on this condition. */ 204static inline int 205__gthread_objc_condition_signal (objc_condition_t UNUSED(condition)) 206{ 207 return 0; 208} 209 210#else /* _LIBOBJC */ 211 212static inline int 213__gthread_active_p (void) 214{ 215 return 0; 216} 217 218static inline int 219__gthread_mutex_lock (__gthread_mutex_t * UNUSED(mutex)) 220{ 221 return 0; 222} 223 224static inline int 225__gthread_mutex_trylock (__gthread_mutex_t * UNUSED(mutex)) 226{ 227 return 0; 228} 229 230static inline int 231__gthread_mutex_unlock (__gthread_mutex_t * UNUSED(mutex)) 232{ 233 return 0; 234} 235 236static inline int 237__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex) 238{ 239 return __gthread_mutex_lock (mutex); 240} 241 242static inline int 243__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex) 244{ 245 return __gthread_mutex_trylock (mutex); 246} 247 248static inline int 249__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex) 250{ 251 return __gthread_mutex_unlock (mutex); 252} 253 254#endif /* _LIBOBJC */ 255 256#undef UNUSED 257 258#endif /* ! GCC_GTHR_SINGLE_H */ 259