libstdc++
|
00001 /* Threads compatibility routines for libgcc2. */ 00002 /* Compile this one with gcc. */ 00003 /* Copyright (C) 1997, 1998, 2004, 2008, 2009 Free Software Foundation, Inc. 00004 00005 This file is part of GCC. 00006 00007 GCC is free software; you can redistribute it and/or modify it under 00008 the terms of the GNU General Public License as published by the Free 00009 Software Foundation; either version 3, or (at your option) any later 00010 version. 00011 00012 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 00013 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00015 for more details. 00016 00017 Under Section 7 of GPL version 3, you are granted additional 00018 permissions described in the GCC Runtime Library Exception, version 00019 3.1, as published by the Free Software Foundation. 00020 00021 You should have received a copy of the GNU General Public License and 00022 a copy of the GCC Runtime Library Exception along with this program; 00023 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00024 <http://www.gnu.org/licenses/>. */ 00025 00026 #ifndef _GLIBCXX_GCC_GTHR_H 00027 #define _GLIBCXX_GCC_GTHR_H 00028 00029 #ifndef _GLIBCXX_HIDE_EXPORTS 00030 #pragma GCC visibility push(default) 00031 #endif 00032 00033 /* If this file is compiled with threads support, it must 00034 #define __GTHREADS 1 00035 to indicate that threads support is present. Also it has define 00036 function 00037 int __gthread_active_p () 00038 that returns 1 if thread system is active, 0 if not. 00039 00040 The threads interface must define the following types: 00041 __gthread_key_t 00042 __gthread_once_t 00043 __gthread_mutex_t 00044 __gthread_recursive_mutex_t 00045 00046 The threads interface must define the following macros: 00047 00048 __GTHREAD_ONCE_INIT 00049 to initialize __gthread_once_t 00050 __GTHREAD_MUTEX_INIT 00051 to initialize __gthread_mutex_t to get a fast 00052 non-recursive mutex. 00053 __GTHREAD_MUTEX_INIT_FUNCTION 00054 some systems can't initialize a mutex without a 00055 function call. On such systems, define this to a 00056 function which looks like this: 00057 void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *) 00058 Don't define __GTHREAD_MUTEX_INIT in this case 00059 __GTHREAD_RECURSIVE_MUTEX_INIT 00060 __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION 00061 as above, but for a recursive mutex. 00062 00063 The threads interface must define the following static functions: 00064 00065 int __gthread_once (__gthread_once_t *once, void (*func) ()) 00066 00067 int __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *)) 00068 int __gthread_key_delete (__gthread_key_t key) 00069 00070 void *__gthread_getspecific (__gthread_key_t key) 00071 int __gthread_setspecific (__gthread_key_t key, const void *ptr) 00072 00073 int __gthread_mutex_destroy (__gthread_mutex_t *mutex); 00074 00075 int __gthread_mutex_lock (__gthread_mutex_t *mutex); 00076 int __gthread_mutex_trylock (__gthread_mutex_t *mutex); 00077 int __gthread_mutex_unlock (__gthread_mutex_t *mutex); 00078 00079 int __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex); 00080 int __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex); 00081 int __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex); 00082 00083 The following are supported in POSIX threads only. They are required to 00084 fix a deadlock in static initialization inside libsupc++. The header file 00085 gthr-posix.h defines a symbol __GTHREAD_HAS_COND to signify that these extra 00086 features are supported. 00087 00088 Types: 00089 __gthread_cond_t 00090 00091 Macros: 00092 __GTHREAD_COND_INIT 00093 __GTHREAD_COND_INIT_FUNCTION 00094 00095 Interface: 00096 int __gthread_cond_broadcast (__gthread_cond_t *cond); 00097 int __gthread_cond_wait (__gthread_cond_t *cond, __gthread_mutex_t *mutex); 00098 int __gthread_cond_wait_recursive (__gthread_cond_t *cond, 00099 __gthread_recursive_mutex_t *mutex); 00100 00101 All functions returning int should return zero on success or the error 00102 number. If the operation is not supported, -1 is returned. 00103 00104 If the following are also defined, you should 00105 #define __GTHREADS_CXX0X 1 00106 to enable the c++0x thread library. 00107 00108 Types: 00109 __gthread_t 00110 __gthread_time_t 00111 00112 Interface: 00113 int __gthread_create (__gthread_t *thread, void *(*func) (void*), 00114 void *args); 00115 int __gthread_join (__gthread_t thread, void **value_ptr); 00116 int __gthread_detach (__gthread_t thread); 00117 int __gthread_equal (__gthread_t t1, __gthread_t t2); 00118 __gthread_t __gthread_self (void); 00119 int __gthread_yield (void); 00120 00121 int __gthread_mutex_timedlock (__gthread_mutex_t *m, 00122 const __gthread_time_t *abs_timeout); 00123 int __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *m, 00124 const __gthread_time_t *abs_time); 00125 00126 int __gthread_cond_signal (__gthread_cond_t *cond); 00127 int __gthread_cond_timedwait (__gthread_cond_t *cond, 00128 __gthread_mutex_t *mutex, 00129 const __gthread_time_t *abs_timeout); 00130 int __gthread_cond_timedwait_recursive (__gthread_cond_t *cond, 00131 __gthread_recursive_mutex_t *mutex, 00132 const __gthread_time_t *abs_time) 00133 00134 Currently supported threads packages are 00135 TPF threads with -D__tpf__ 00136 POSIX/Unix98 threads with -D_PTHREADS 00137 POSIX/Unix95 threads with -D_PTHREADS95 00138 DCE threads with -D_DCE_THREADS 00139 Solaris/UI threads with -D_SOLARIS_THREADS 00140 00141 */ 00142 00143 /* Check first for thread specific defines. */ 00144 #if defined (_GLIBCXX___tpf_GLIBCXX___) 00145 #include <bits/gthr-tpf.h> 00146 #elif _GLIBCXX__PTHREADS 00147 #include <bits/gthr-posix.h> 00148 #elif _GLIBCXX__PTHREADS95 00149 #include <bits/gthr-posix95.h> 00150 #elif _GLIBCXX__DCE_THREADS 00151 #include <bits/gthr-dce.h> 00152 #elif _GLIBCXX__SOLARIS_THREADS 00153 #include <bits/gthr-solaris.h> 00154 00155 /* Include GTHREAD_FILE if one is defined. */ 00156 #elif defined(_GLIBCXX_HAVE_GTHR_DEFAULT) 00157 #if __GXX_WEAK__ 00158 #ifndef _GLIBCXX_GTHREAD_USE_WEAK 00159 #define _GLIBCXX_GTHREAD_USE_WEAK 1 00160 #endif 00161 #endif 00162 #include <bits/gthr-default.h> 00163 00164 /* Fallback to single thread definitions. */ 00165 #else 00166 #include <bits/gthr-single.h> 00167 #endif 00168 00169 #ifndef _GLIBCXX_HIDE_EXPORTS 00170 #pragma GCC visibility pop 00171 #endif 00172 00173 #endif /* ! _GLIBCXX_GCC_GTHR_H */