libstdc++
gthr.h
00001 /* Threads compatibility routines for libgcc2.  */
00002 /* Compile this one with gcc.  */
00003 /* Copyright (C) 1997, 1998, 2004, 2008, 2009, 2011
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_H
00028 #define _GLIBCXX_GCC_GTHR_H
00029 
00030 #ifndef _GLIBCXX_HIDE_EXPORTS
00031 #pragma GCC visibility push(default)
00032 #endif
00033 
00034 /* If this file is compiled with threads support, it must
00035        #define __GTHREADS 1
00036    to indicate that threads support is present.  Also it has define
00037    function
00038      int __gthread_active_p ()
00039    that returns 1 if thread system is active, 0 if not.
00040 
00041    The threads interface must define the following types:
00042      __gthread_key_t
00043      __gthread_once_t
00044      __gthread_mutex_t
00045      __gthread_recursive_mutex_t
00046 
00047    The threads interface must define the following macros:
00048 
00049      __GTHREAD_ONCE_INIT
00050             to initialize __gthread_once_t
00051      __GTHREAD_MUTEX_INIT
00052             to initialize __gthread_mutex_t to get a fast
00053         non-recursive mutex.
00054      __GTHREAD_MUTEX_INIT_FUNCTION
00055         to initialize __gthread_mutex_t to get a fast
00056         non-recursive mutex.
00057         Define this to a function which looks like this:
00058           void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *)
00059             Some systems can't initialize a mutex without a
00060         function call.  Don't define __GTHREAD_MUTEX_INIT in this case.
00061      __GTHREAD_RECURSIVE_MUTEX_INIT
00062      __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION
00063             as above, but for a recursive mutex.
00064 
00065    The threads interface must define the following static functions:
00066 
00067      int __gthread_once (__gthread_once_t *once, void (*func) ())
00068 
00069      int __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *))
00070      int __gthread_key_delete (__gthread_key_t key)
00071 
00072      void *__gthread_getspecific (__gthread_key_t key)
00073      int __gthread_setspecific (__gthread_key_t key, const void *ptr)
00074 
00075      int __gthread_mutex_destroy (__gthread_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      int __gthread_cond_timedwait_recursive (__gthread_cond_t *cond,
00133                                              __gthread_recursive_mutex_t *mutex,
00134                                              const __gthread_time_t *abs_time)
00135 
00136 */
00137 
00138 #if __GXX_WEAK__
00139 /* The pe-coff weak support isn't fully compatible to ELF's weak.
00140    For static libraries it might would work, but as we need to deal
00141    with shared versions too, we disable it for mingw-targets.  */
00142 #ifdef _GLIBCXX___MINGW32_GLIBCXX___
00143 #undef _GLIBCXX_GTHREAD_USE_WEAK
00144 #define _GLIBCXX_GTHREAD_USE_WEAK 0
00145 #endif
00146 
00147 #ifndef _GLIBCXX_GTHREAD_USE_WEAK
00148 #define _GLIBCXX_GTHREAD_USE_WEAK 1
00149 #endif
00150 #endif
00151 #include <bits/gthr-default.h>
00152 
00153 #ifndef _GLIBCXX_HIDE_EXPORTS
00154 #pragma GCC visibility pop
00155 #endif
00156 
00157 #endif /* ! _GLIBCXX_GCC_GTHR_H */