libstdc++
gthr-single.h
00001 /* Threads compatibility routines for libgcc2 and libobjc.  */
00002 /* Compile this one with gcc.  */
00003 /* Copyright (C) 1997, 1999, 2000, 2004, 2008, 2009
00004    Free Software Foundation, Inc.
00005 
00006 This file is part of GCC.
00007 
00008 GCC is free software; you can redistribute it and/or modify it under
00009 the terms of the GNU General Public License as published by the Free
00010 Software Foundation; either version 3, or (at your option) any later
00011 version.
00012 
00013 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
00014 WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 Under Section 7 of GPL version 3, you are granted additional
00019 permissions described in the GCC Runtime Library Exception, version
00020 3.1, as published by the Free Software Foundation.
00021 
00022 You should have received a copy of the GNU General Public License and
00023 a copy of the GCC Runtime Library Exception along with this program;
00024 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00025 <http://www.gnu.org/licenses/>.  */
00026 
00027 #ifndef _GLIBCXX_GCC_GTHR_SINGLE_H
00028 #define _GLIBCXX_GCC_GTHR_SINGLE_H
00029 
00030 /* Just provide compatibility for mutex handling.  */
00031 
00032 typedef int __gthread_key_t;
00033 typedef int __gthread_once_t;
00034 typedef int __gthread_mutex_t;
00035 typedef int __gthread_recursive_mutex_t;
00036 
00037 #define __GTHREAD_ONCE_INIT 0
00038 #define __GTHREAD_MUTEX_INIT 0
00039 #define __GTHREAD_RECURSIVE_MUTEX_INIT 0
00040 
00041 #define _GLIBCXX_UNUSED __attribute__((unused))
00042 
00043 #ifdef _LIBOBJC
00044 
00045 /* Thread local storage for a single thread */
00046 static void *thread_local_storage = NULL;
00047 
00048 /* Backend initialization functions */
00049 
00050 /* Initialize the threads subsystem.  */
00051 static inline int
00052 __gthread_objc_init_thread_system (void)
00053 {
00054   /* No thread support available */
00055   return -1;
00056 }
00057 
00058 /* Close the threads subsystem.  */
00059 static inline int
00060 __gthread_objc_close_thread_system (void)
00061 {
00062   /* No thread support available */
00063   return -1;
00064 }
00065 
00066 /* Backend thread functions */
00067 
00068 /* Create a new thread of execution.  */
00069 static inline objc_thread_t
00070 __gthread_objc_thread_detach (void (* func)(void *), void * arg _GLIBCXX_UNUSED)
00071 {
00072   /* No thread support available */
00073   return NULL;
00074 }
00075 
00076 /* Set the current thread's priority.  */
00077 static inline int
00078 __gthread_objc_thread_set_priority (int priority _GLIBCXX_UNUSED)
00079 {
00080   /* No thread support available */
00081   return -1;
00082 }
00083 
00084 /* Return the current thread's priority.  */
00085 static inline int
00086 __gthread_objc_thread_get_priority (void)
00087 {
00088   return OBJC_THREAD_INTERACTIVE_PRIORITY;
00089 }
00090 
00091 /* Yield our process time to another thread.  */
00092 static inline void
00093 __gthread_objc_thread_yield (void)
00094 {
00095   return;
00096 }
00097 
00098 /* Terminate the current thread.  */
00099 static inline int
00100 __gthread_objc_thread_exit (void)
00101 {
00102   /* No thread support available */
00103   /* Should we really exit the program */
00104   /* exit (&__objc_thread_exit_status); */
00105   return -1;
00106 }
00107 
00108 /* Returns an integer value which uniquely describes a thread.  */
00109 static inline objc_thread_t
00110 __gthread_objc_thread_id (void)
00111 {
00112   /* No thread support, use 1.  */
00113   return (objc_thread_t) 1;
00114 }
00115 
00116 /* Sets the thread's local storage pointer.  */
00117 static inline int
00118 __gthread_objc_thread_set_data (void *value)
00119 {
00120   thread_local_storage = value;
00121   return 0;
00122 }
00123 
00124 /* Returns the thread's local storage pointer.  */
00125 static inline void *
00126 __gthread_objc_thread_get_data (void)
00127 {
00128   return thread_local_storage;
00129 }
00130 
00131 /* Backend mutex functions */
00132 
00133 /* Allocate a mutex.  */
00134 static inline int
00135 __gthread_objc_mutex_allocate (objc_mutex_t mutex _GLIBCXX_UNUSED)
00136 {
00137   return 0;
00138 }
00139 
00140 /* Deallocate a mutex.  */
00141 static inline int
00142 __gthread_objc_mutex_deallocate (objc_mutex_t mutex _GLIBCXX_UNUSED)
00143 {
00144   return 0;
00145 }
00146 
00147 /* Grab a lock on a mutex.  */
00148 static inline int
00149 __gthread_objc_mutex_lock (objc_mutex_t mutex _GLIBCXX_UNUSED)
00150 {
00151   /* There can only be one thread, so we always get the lock */
00152   return 0;
00153 }
00154 
00155 /* Try to grab a lock on a mutex.  */
00156 static inline int
00157 __gthread_objc_mutex_trylock (objc_mutex_t mutex _GLIBCXX_UNUSED)
00158 {
00159   /* There can only be one thread, so we always get the lock */
00160   return 0;
00161 }
00162 
00163 /* Unlock the mutex */
00164 static inline int
00165 __gthread_objc_mutex_unlock (objc_mutex_t mutex _GLIBCXX_UNUSED)
00166 {
00167   return 0;
00168 }
00169 
00170 /* Backend condition mutex functions */
00171 
00172 /* Allocate a condition.  */
00173 static inline int
00174 __gthread_objc_condition_allocate (objc_condition_t condition _GLIBCXX_UNUSED)
00175 {
00176   return 0;
00177 }
00178 
00179 /* Deallocate a condition.  */
00180 static inline int
00181 __gthread_objc_condition_deallocate (objc_condition_t condition _GLIBCXX_UNUSED)
00182 {
00183   return 0;
00184 }
00185 
00186 /* Wait on the condition */
00187 static inline int
00188 __gthread_objc_condition_wait (objc_condition_t condition _GLIBCXX_UNUSED,
00189                    objc_mutex_t mutex _GLIBCXX_UNUSED)
00190 {
00191   return 0;
00192 }
00193 
00194 /* Wake up all threads waiting on this condition.  */
00195 static inline int
00196 __gthread_objc_condition_broadcast (objc_condition_t condition _GLIBCXX_UNUSED)
00197 {
00198   return 0;
00199 }
00200 
00201 /* Wake up one thread waiting on this condition.  */
00202 static inline int
00203 __gthread_objc_condition_signal (objc_condition_t condition _GLIBCXX_UNUSED)
00204 {
00205   return 0;
00206 }
00207 
00208 #else /* _LIBOBJC */
00209 
00210 static inline int
00211 __gthread_active_p (void)
00212 {
00213   return 0;
00214 }
00215 
00216 static inline int
00217 __gthread_once (__gthread_once_t *__once _GLIBCXX_UNUSED, void (*__func) (void) _GLIBCXX_UNUSED)
00218 {
00219   return 0;
00220 }
00221 
00222 static inline int _GLIBCXX_UNUSED
00223 __gthread_key_create (__gthread_key_t *__key _GLIBCXX_UNUSED, void (*__func) (void *) _GLIBCXX_UNUSED)
00224 {
00225   return 0;
00226 }
00227 
00228 static int _GLIBCXX_UNUSED
00229 __gthread_key_delete (__gthread_key_t __key _GLIBCXX_UNUSED)
00230 {
00231   return 0;
00232 }
00233 
00234 static inline void *
00235 __gthread_getspecific (__gthread_key_t __key _GLIBCXX_UNUSED)
00236 {
00237   return 0;
00238 }
00239 
00240 static inline int
00241 __gthread_setspecific (__gthread_key_t __key _GLIBCXX_UNUSED, const void *__v _GLIBCXX_UNUSED)
00242 {
00243   return 0;
00244 }
00245 
00246 static inline int
00247 __gthread_mutex_destroy (__gthread_mutex_t *__mutex _GLIBCXX_UNUSED)
00248 {
00249   return 0;
00250 }
00251 
00252 static inline int
00253 __gthread_mutex_lock (__gthread_mutex_t *__mutex _GLIBCXX_UNUSED)
00254 {
00255   return 0;
00256 }
00257 
00258 static inline int
00259 __gthread_mutex_trylock (__gthread_mutex_t *__mutex _GLIBCXX_UNUSED)
00260 {
00261   return 0;
00262 }
00263 
00264 static inline int
00265 __gthread_mutex_unlock (__gthread_mutex_t *__mutex _GLIBCXX_UNUSED)
00266 {
00267   return 0;
00268 }
00269 
00270 static inline int
00271 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
00272 {
00273   return __gthread_mutex_lock (__mutex);
00274 }
00275 
00276 static inline int
00277 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
00278 {
00279   return __gthread_mutex_trylock (__mutex);
00280 }
00281 
00282 static inline int
00283 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
00284 {
00285   return __gthread_mutex_unlock (__mutex);
00286 }
00287 
00288 #endif /* _LIBOBJC */
00289 
00290 #undef _GLIBCXX_UNUSED
00291 
00292 #endif /* ! _GLIBCXX_GCC_GTHR_SINGLE_H */