libstdc++
|
00001 /* Threads compatibility routines for libgcc2. */ 00002 /* Compile this one with gcc. */ 00003 /* Copyright (C) 1997-2013 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 to initialize __gthread_mutex_t to get a fast 00055 non-recursive mutex. 00056 Define this to a function which looks like this: 00057 void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *) 00058 Some systems can't initialize a mutex without a 00059 function call. Don't define __GTHREAD_MUTEX_INIT in this case. 00060 __GTHREAD_RECURSIVE_MUTEX_INIT 00061 __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION 00062 as above, but for a recursive mutex. 00063 00064 The threads interface must define the following static functions: 00065 00066 int __gthread_once (__gthread_once_t *once, void (*func) ()) 00067 00068 int __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *)) 00069 int __gthread_key_delete (__gthread_key_t key) 00070 00071 void *__gthread_getspecific (__gthread_key_t key) 00072 int __gthread_setspecific (__gthread_key_t key, const void *ptr) 00073 00074 int __gthread_mutex_destroy (__gthread_mutex_t *mutex); 00075 int __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *mutex); 00076 00077 int __gthread_mutex_lock (__gthread_mutex_t *mutex); 00078 int __gthread_mutex_trylock (__gthread_mutex_t *mutex); 00079 int __gthread_mutex_unlock (__gthread_mutex_t *mutex); 00080 00081 int __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex); 00082 int __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex); 00083 int __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex); 00084 00085 The following are supported in POSIX threads only. They are required to 00086 fix a deadlock in static initialization inside libsupc++. The header file 00087 gthr-posix.h defines a symbol __GTHREAD_HAS_COND to signify that these extra 00088 features are supported. 00089 00090 Types: 00091 __gthread_cond_t 00092 00093 Macros: 00094 __GTHREAD_COND_INIT 00095 __GTHREAD_COND_INIT_FUNCTION 00096 00097 Interface: 00098 int __gthread_cond_broadcast (__gthread_cond_t *cond); 00099 int __gthread_cond_wait (__gthread_cond_t *cond, __gthread_mutex_t *mutex); 00100 int __gthread_cond_wait_recursive (__gthread_cond_t *cond, 00101 __gthread_recursive_mutex_t *mutex); 00102 00103 All functions returning int should return zero on success or the error 00104 number. If the operation is not supported, -1 is returned. 00105 00106 If the following are also defined, you should 00107 #define __GTHREADS_CXX0X 1 00108 to enable the c++0x thread library. 00109 00110 Types: 00111 __gthread_t 00112 __gthread_time_t 00113 00114 Interface: 00115 int __gthread_create (__gthread_t *thread, void *(*func) (void*), 00116 void *args); 00117 int __gthread_join (__gthread_t thread, void **value_ptr); 00118 int __gthread_detach (__gthread_t thread); 00119 int __gthread_equal (__gthread_t t1, __gthread_t t2); 00120 __gthread_t __gthread_self (void); 00121 int __gthread_yield (void); 00122 00123 int __gthread_mutex_timedlock (__gthread_mutex_t *m, 00124 const __gthread_time_t *abs_timeout); 00125 int __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *m, 00126 const __gthread_time_t *abs_time); 00127 00128 int __gthread_cond_signal (__gthread_cond_t *cond); 00129 int __gthread_cond_timedwait (__gthread_cond_t *cond, 00130 __gthread_mutex_t *mutex, 00131 const __gthread_time_t *abs_timeout); 00132 00133 */ 00134 00135 #if __GXX_WEAK__ 00136 /* The pe-coff weak support isn't fully compatible to ELF's weak. 00137 For static libraries it might would work, but as we need to deal 00138 with shared versions too, we disable it for mingw-targets. */ 00139 #ifdef __MINGW32__ 00140 #undef _GLIBCXX_GTHREAD_USE_WEAK 00141 #define _GLIBCXX_GTHREAD_USE_WEAK 0 00142 #endif 00143 00144 #ifndef _GLIBCXX_GTHREAD_USE_WEAK 00145 #define _GLIBCXX_GTHREAD_USE_WEAK 1 00146 #endif 00147 #endif 00148 #include <bits/gthr-default.h> 00149 00150 #ifndef _GLIBCXX_HIDE_EXPORTS 00151 #pragma GCC visibility pop 00152 #endif 00153 00154 #endif /* ! _GLIBCXX_GCC_GTHR_H */