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             some systems can't initialize a mutex without a
00056         function call.  On such systems, define this to a
00057         function which looks like this:
00058           void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *)
00059         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 
00076      int __gthread_mutex_lock (__gthread_mutex_t *mutex);
00077      int __gthread_mutex_trylock (__gthread_mutex_t *mutex);
00078      int __gthread_mutex_unlock (__gthread_mutex_t *mutex);
00079 
00080      int __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex);
00081      int __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex);
00082      int __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex);
00083 
00084    The following are supported in POSIX threads only. They are required to
00085    fix a deadlock in static initialization inside libsupc++. The header file
00086    gthr-posix.h defines a symbol __GTHREAD_HAS_COND to signify that these extra
00087    features are supported.
00088 
00089    Types:
00090      __gthread_cond_t
00091 
00092    Macros:
00093      __GTHREAD_COND_INIT
00094      __GTHREAD_COND_INIT_FUNCTION
00095 
00096    Interface:
00097      int __gthread_cond_broadcast (__gthread_cond_t *cond);
00098      int __gthread_cond_wait (__gthread_cond_t *cond, __gthread_mutex_t *mutex);
00099      int __gthread_cond_wait_recursive (__gthread_cond_t *cond,
00100                     __gthread_recursive_mutex_t *mutex);
00101 
00102    All functions returning int should return zero on success or the error
00103    number.  If the operation is not supported, -1 is returned.
00104 
00105    If the following are also defined, you should
00106      #define __GTHREADS_CXX0X 1
00107    to enable the c++0x thread library.
00108 
00109    Types:
00110      __gthread_t
00111      __gthread_time_t
00112 
00113    Interface:
00114      int __gthread_create (__gthread_t *thread, void *(*func) (void*),
00115                            void *args);
00116      int __gthread_join (__gthread_t thread, void **value_ptr);
00117      int __gthread_detach (__gthread_t thread);
00118      int __gthread_equal (__gthread_t t1, __gthread_t t2);
00119      __gthread_t __gthread_self (void);
00120      int __gthread_yield (void);
00121 
00122      int __gthread_mutex_timedlock (__gthread_mutex_t *m,
00123                                     const __gthread_time_t *abs_timeout);
00124      int __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *m,
00125                                           const __gthread_time_t *abs_time);
00126 
00127      int __gthread_cond_signal (__gthread_cond_t *cond);
00128      int __gthread_cond_timedwait (__gthread_cond_t *cond,
00129                                    __gthread_mutex_t *mutex,
00130                                    const __gthread_time_t *abs_timeout);
00131      int __gthread_cond_timedwait_recursive (__gthread_cond_t *cond,
00132                                              __gthread_recursive_mutex_t *mutex,
00133                                              const __gthread_time_t *abs_time)
00134 
00135 */
00136 
00137 #if __GXX_WEAK__
00138 /* The pe-coff weak support isn't fully compatible to ELF's weak.
00139    For static libraries it might would work, but as we need to deal
00140    with shared versions too, we disable it for mingw-targets.  */
00141 #ifdef _GLIBCXX___MINGW32_GLIBCXX___
00142 #undef _GLIBCXX_GTHREAD_USE_WEAK
00143 #define _GLIBCXX_GTHREAD_USE_WEAK 0
00144 #endif
00145 
00146 #ifndef _GLIBCXX_GTHREAD_USE_WEAK
00147 #define _GLIBCXX_GTHREAD_USE_WEAK 1
00148 #endif
00149 #endif
00150 #include <bits/gthr-default.h>
00151 
00152 #ifndef _GLIBCXX_HIDE_EXPORTS
00153 #pragma GCC visibility pop
00154 #endif
00155 
00156 #endif /* ! _GLIBCXX_GCC_GTHR_H */