]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/gthr.h
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / gcc / gthr.h
CommitLineData
899905f6 1/* Threads compatibility routines for libgcc2. */
f24af81b 2/* Compile this one with gcc. */
748086b7 3/* Copyright (C) 1997, 1998, 2004, 2008, 2009 Free Software Foundation, Inc.
f24af81b 4
1322177d 5This file is part of GCC.
f24af81b 6
1322177d
LB
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
748086b7 9Software Foundation; either version 3, or (at your option) any later
1322177d 10version.
f24af81b 11
1322177d
LB
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.
f24af81b 16
748086b7
JJ
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/>. */
f24af81b 25
88657302
RH
26#ifndef GCC_GTHR_H
27#define GCC_GTHR_H
f24af81b 28
7370bebd 29#ifndef HIDE_EXPORTS
3fc1f660 30#pragma GCC visibility push(default)
7370bebd 31#endif
3fc1f660 32
f24af81b
TT
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
589005ff 36 function
f24af81b
TT
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
40aac948 44 __gthread_recursive_mutex_t
f24af81b
TT
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.
3e2a2957 53 __GTHREAD_MUTEX_INIT_FUNCTION
f63d1bf7 54 some systems can't initialize a mutex without a
3e2a2957
TT
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
40aac948
JM
59 __GTHREAD_RECURSIVE_MUTEX_INIT
60 __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION
61 as above, but for a recursive mutex.
f24af81b
TT
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
f24af81b
TT
70 void *__gthread_getspecific (__gthread_key_t key)
71 int __gthread_setspecific (__gthread_key_t key, const void *ptr)
72
4dabf736
JB
73 int __gthread_mutex_destroy (__gthread_mutex_t *mutex);
74
f24af81b
TT
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
40aac948
JM
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);
afd82ef5
DK
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);
40aac948 100
754d1a92
TT
101 All functions returning int should return zero on success or the error
102 number. If the operation is not supported, -1 is returned.
f24af81b 103
a75150ae
CF
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
f24af81b 134 Currently supported threads packages are
18167442
EB
135 TPF threads with -D__tpf__
136 POSIX/Unix98 threads with -D_PTHREADS
137 POSIX/Unix95 threads with -D_PTHREADS95
f24af81b
TT
138 DCE threads with -D_DCE_THREADS
139 Solaris/UI threads with -D_SOLARIS_THREADS
a75150ae 140
f24af81b
TT
141*/
142
19eb1ad7 143/* Check first for thread specific defines. */
512baaea
D
144#if defined (__tpf__)
145#include "gthr-tpf.h"
146#elif _PTHREADS
f24af81b 147#include "gthr-posix.h"
18167442
EB
148#elif _PTHREADS95
149#include "gthr-posix95.h"
f24af81b
TT
150#elif _DCE_THREADS
151#include "gthr-dce.h"
152#elif _SOLARIS_THREADS
153#include "gthr-solaris.h"
154
19eb1ad7 155/* Include GTHREAD_FILE if one is defined. */
7cc34889
MS
156#elif defined(HAVE_GTHR_DEFAULT)
157#if SUPPORTS_WEAK
f24af81b
TT
158#ifndef GTHREAD_USE_WEAK
159#define GTHREAD_USE_WEAK 1
160#endif
7cc34889 161#endif
f24af81b
TT
162#include "gthr-default.h"
163
19eb1ad7 164/* Fallback to single thread definitions. */
f24af81b
TT
165#else
166#include "gthr-single.h"
167#endif
168
7370bebd 169#ifndef HIDE_EXPORTS
b3f8d95d 170#pragma GCC visibility pop
7370bebd 171#endif
3fc1f660 172
88657302 173#endif /* ! GCC_GTHR_H */