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