1/* Threads compatibility routines for libgcc2. */ 2/* Compile this one with gcc. */ 3/* Copyright (C) 1997, 1998, 2004, 2008, 2009 Free Software Foundation, Inc. 4 5This file is part of GCC. 6 7GCC is free software; you can redistribute it and/or modify it under 8the terms of the GNU General Public License as published by the Free 9Software Foundation; either version 3, or (at your option) any later 10version. 11 12GCC is distributed in the hope that it will be useful, but WITHOUT ANY 13WARRANTY; without even the implied warranty of MERCHANTABILITY or 14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15for more details. 16 17Under Section 7 of GPL version 3, you are granted additional 18permissions described in the GCC Runtime Library Exception, version 193.1, as published by the Free Software Foundation. 20 21You should have received a copy of the GNU General Public License and 22a copy of the GCC Runtime Library Exception along with this program; 23see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 24<http://www.gnu.org/licenses/>. */ 25 26#ifndef _GLIBCXX_GCC_GTHR_H 27#define _GLIBCXX_GCC_GTHR_H 28 29#ifndef _GLIBCXX_HIDE_EXPORTS 30#pragma GCC visibility push(default) 31#endif 32 33/* If this file is compiled with threads support, it must 34 #define __GTHREADS 1 35 to indicate that threads support is present. Also it has define 36 function 37 int __gthread_active_p () 38 that returns 1 if thread system is active, 0 if not. 39 40 The threads interface must define the following types: 41 __gthread_key_t 42 __gthread_once_t 43 __gthread_mutex_t 44 __gthread_recursive_mutex_t 45 46 The threads interface must define the following macros: 47 48 __GTHREAD_ONCE_INIT 49 to initialize __gthread_once_t 50 __GTHREAD_MUTEX_INIT 51 to initialize __gthread_mutex_t to get a fast 52 non-recursive mutex. 53 __GTHREAD_MUTEX_INIT_FUNCTION 54 some systems can't initialize a mutex without a 55 function call. On such systems, define this to a 56 function which looks like this: 57 void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *) 58 Don't define __GTHREAD_MUTEX_INIT in this case 59 __GTHREAD_RECURSIVE_MUTEX_INIT 60 __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION 61 as above, but for a recursive mutex. 62 63 The threads interface must define the following static functions: 64 65 int __gthread_once (__gthread_once_t *once, void (*func) ()) 66 67 int __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *)) 68 int __gthread_key_delete (__gthread_key_t key) 69 70 void *__gthread_getspecific (__gthread_key_t key) 71 int __gthread_setspecific (__gthread_key_t key, const void *ptr) 72 73 int __gthread_mutex_destroy (__gthread_mutex_t *mutex); 74 75 int __gthread_mutex_lock (__gthread_mutex_t *mutex); 76 int __gthread_mutex_trylock (__gthread_mutex_t *mutex); 77 int __gthread_mutex_unlock (__gthread_mutex_t *mutex); 78 79 int __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex); 80 int __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex); 81 int __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex); 82 83 The following are supported in POSIX threads only. They are required to 84 fix a deadlock in static initialization inside libsupc++. The header file 85 gthr-posix.h defines a symbol __GTHREAD_HAS_COND to signify that these extra 86 features are supported. 87 88 Types: 89 __gthread_cond_t 90 91 Macros: 92 __GTHREAD_COND_INIT 93 __GTHREAD_COND_INIT_FUNCTION 94 95 Interface: 96 int __gthread_cond_broadcast (__gthread_cond_t *cond); 97 int __gthread_cond_wait (__gthread_cond_t *cond, __gthread_mutex_t *mutex); 98 int __gthread_cond_wait_recursive (__gthread_cond_t *cond, 99 __gthread_recursive_mutex_t *mutex); 100 101 All functions returning int should return zero on success or the error 102 number. If the operation is not supported, -1 is returned. 103 104 If the following are also defined, you should 105 #define __GTHREADS_CXX0X 1 106 to enable the c++0x thread library. 107 108 Types: 109 __gthread_t 110 __gthread_time_t 111 112 Interface: 113 int __gthread_create (__gthread_t *thread, void *(*func) (void*), 114 void *args); 115 int __gthread_join (__gthread_t thread, void **value_ptr); 116 int __gthread_detach (__gthread_t thread); 117 int __gthread_equal (__gthread_t t1, __gthread_t t2); 118 __gthread_t __gthread_self (void); 119 int __gthread_yield (void); 120 121 int __gthread_mutex_timedlock (__gthread_mutex_t *m, 122 const __gthread_time_t *abs_timeout); 123 int __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *m, 124 const __gthread_time_t *abs_time); 125 126 int __gthread_cond_signal (__gthread_cond_t *cond); 127 int __gthread_cond_timedwait (__gthread_cond_t *cond, 128 __gthread_mutex_t *mutex, 129 const __gthread_time_t *abs_timeout); 130 int __gthread_cond_timedwait_recursive (__gthread_cond_t *cond, 131 __gthread_recursive_mutex_t *mutex, 132 const __gthread_time_t *abs_time) 133 134 Currently supported threads packages are 135 TPF threads with -D__tpf__ 136 POSIX/Unix98 threads with -D_PTHREADS 137 POSIX/Unix95 threads with -D_PTHREADS95 138 DCE threads with -D_DCE_THREADS 139 Solaris/UI threads with -D_SOLARIS_THREADS 140 141*/ 142 143/* Check first for thread specific defines. */ 144#if defined (_GLIBCXX___tpf_GLIBCXX___) 145#include <bits/gthr-tpf.h> 146#elif _GLIBCXX__PTHREADS 147#include <bits/gthr-posix.h> 148#elif _GLIBCXX__PTHREADS95 149#include <bits/gthr-posix95.h> 150#elif _GLIBCXX__DCE_THREADS 151#include <bits/gthr-dce.h> 152#elif _GLIBCXX__SOLARIS_THREADS 153#include <bits/gthr-solaris.h> 154 155/* Include GTHREAD_FILE if one is defined. */ 156#elif defined(_GLIBCXX_HAVE_GTHR_DEFAULT) 157#if __GXX_WEAK__ 158#ifndef _GLIBCXX_GTHREAD_USE_WEAK 159#define _GLIBCXX_GTHREAD_USE_WEAK 1 160#endif 161#endif 162#include <bits/gthr-default.h> 163 164/* Fallback to single thread definitions. */ 165#else 166#include <bits/gthr-single.h> 167#endif 168 169#ifndef _GLIBCXX_HIDE_EXPORTS 170#pragma GCC visibility pop 171#endif 172 173#endif /* ! _GLIBCXX_GCC_GTHR_H */ 174