xref: /dflybsd-src/contrib/gcc-8.0/libgcc/gthr.h (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj /* Threads compatibility routines for libgcc2.  */
2*38fd1498Szrj /* Compile this one with gcc.  */
3*38fd1498Szrj /* Copyright (C) 1997-2018 Free Software Foundation, Inc.
4*38fd1498Szrj 
5*38fd1498Szrj This file is part of GCC.
6*38fd1498Szrj 
7*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
8*38fd1498Szrj the terms of the GNU General Public License as published by the Free
9*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
10*38fd1498Szrj version.
11*38fd1498Szrj 
12*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
14*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15*38fd1498Szrj for more details.
16*38fd1498Szrj 
17*38fd1498Szrj Under Section 7 of GPL version 3, you are granted additional
18*38fd1498Szrj permissions described in the GCC Runtime Library Exception, version
19*38fd1498Szrj 3.1, as published by the Free Software Foundation.
20*38fd1498Szrj 
21*38fd1498Szrj You should have received a copy of the GNU General Public License and
22*38fd1498Szrj a copy of the GCC Runtime Library Exception along with this program;
23*38fd1498Szrj see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24*38fd1498Szrj <http://www.gnu.org/licenses/>.  */
25*38fd1498Szrj 
26*38fd1498Szrj #ifndef GCC_GTHR_H
27*38fd1498Szrj #define GCC_GTHR_H
28*38fd1498Szrj 
29*38fd1498Szrj #ifndef HIDE_EXPORTS
30*38fd1498Szrj #pragma GCC visibility push(default)
31*38fd1498Szrj #endif
32*38fd1498Szrj 
33*38fd1498Szrj /* If this file is compiled with threads support, it must
34*38fd1498Szrj        #define __GTHREADS 1
35*38fd1498Szrj    to indicate that threads support is present.  Also it has define
36*38fd1498Szrj    function
37*38fd1498Szrj      int __gthread_active_p ()
38*38fd1498Szrj    that returns 1 if thread system is active, 0 if not.
39*38fd1498Szrj 
40*38fd1498Szrj    The threads interface must define the following types:
41*38fd1498Szrj      __gthread_key_t
42*38fd1498Szrj      __gthread_once_t
43*38fd1498Szrj      __gthread_mutex_t
44*38fd1498Szrj      __gthread_recursive_mutex_t
45*38fd1498Szrj 
46*38fd1498Szrj    The threads interface must define the following macros:
47*38fd1498Szrj 
48*38fd1498Szrj      __GTHREAD_ONCE_INIT
49*38fd1498Szrj      		to initialize __gthread_once_t
50*38fd1498Szrj      __GTHREAD_MUTEX_INIT
51*38fd1498Szrj      		to initialize __gthread_mutex_t to get a fast
52*38fd1498Szrj 		non-recursive mutex.
53*38fd1498Szrj      __GTHREAD_MUTEX_INIT_FUNCTION
54*38fd1498Szrj 		to initialize __gthread_mutex_t to get a fast
55*38fd1498Szrj 		non-recursive mutex.
56*38fd1498Szrj 		Define this to a function which looks like this:
57*38fd1498Szrj 		  void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *)
58*38fd1498Szrj      		Some systems can't initialize a mutex without a
59*38fd1498Szrj 		function call.  Don't define __GTHREAD_MUTEX_INIT in this case.
60*38fd1498Szrj      __GTHREAD_RECURSIVE_MUTEX_INIT
61*38fd1498Szrj      __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION
62*38fd1498Szrj      		as above, but for a recursive mutex.
63*38fd1498Szrj 
64*38fd1498Szrj    The threads interface must define the following static functions:
65*38fd1498Szrj 
66*38fd1498Szrj      int __gthread_once (__gthread_once_t *once, void (*func) ())
67*38fd1498Szrj 
68*38fd1498Szrj      int __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *))
69*38fd1498Szrj      int __gthread_key_delete (__gthread_key_t key)
70*38fd1498Szrj 
71*38fd1498Szrj      void *__gthread_getspecific (__gthread_key_t key)
72*38fd1498Szrj      int __gthread_setspecific (__gthread_key_t key, const void *ptr)
73*38fd1498Szrj 
74*38fd1498Szrj      int __gthread_mutex_destroy (__gthread_mutex_t *mutex);
75*38fd1498Szrj      int __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *mutex);
76*38fd1498Szrj 
77*38fd1498Szrj      int __gthread_mutex_lock (__gthread_mutex_t *mutex);
78*38fd1498Szrj      int __gthread_mutex_trylock (__gthread_mutex_t *mutex);
79*38fd1498Szrj      int __gthread_mutex_unlock (__gthread_mutex_t *mutex);
80*38fd1498Szrj 
81*38fd1498Szrj      int __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex);
82*38fd1498Szrj      int __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex);
83*38fd1498Szrj      int __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex);
84*38fd1498Szrj 
85*38fd1498Szrj    The following are supported in POSIX threads only. They are required to
86*38fd1498Szrj    fix a deadlock in static initialization inside libsupc++. The header file
87*38fd1498Szrj    gthr-posix.h defines a symbol __GTHREAD_HAS_COND to signify that these extra
88*38fd1498Szrj    features are supported.
89*38fd1498Szrj 
90*38fd1498Szrj    Types:
91*38fd1498Szrj      __gthread_cond_t
92*38fd1498Szrj 
93*38fd1498Szrj    Macros:
94*38fd1498Szrj      __GTHREAD_COND_INIT
95*38fd1498Szrj      __GTHREAD_COND_INIT_FUNCTION
96*38fd1498Szrj 
97*38fd1498Szrj    Interface:
98*38fd1498Szrj      int __gthread_cond_broadcast (__gthread_cond_t *cond);
99*38fd1498Szrj      int __gthread_cond_wait (__gthread_cond_t *cond, __gthread_mutex_t *mutex);
100*38fd1498Szrj      int __gthread_cond_wait_recursive (__gthread_cond_t *cond,
101*38fd1498Szrj 					__gthread_recursive_mutex_t *mutex);
102*38fd1498Szrj 
103*38fd1498Szrj    All functions returning int should return zero on success or the error
104*38fd1498Szrj    number.  If the operation is not supported, -1 is returned.
105*38fd1498Szrj 
106*38fd1498Szrj    If the following are also defined, you should
107*38fd1498Szrj      #define __GTHREADS_CXX0X 1
108*38fd1498Szrj    to enable the c++0x thread library.
109*38fd1498Szrj 
110*38fd1498Szrj    Types:
111*38fd1498Szrj      __gthread_t
112*38fd1498Szrj      __gthread_time_t
113*38fd1498Szrj 
114*38fd1498Szrj    Interface:
115*38fd1498Szrj      int __gthread_create (__gthread_t *thread, void *(*func) (void*),
116*38fd1498Szrj                            void *args);
117*38fd1498Szrj      int __gthread_join (__gthread_t thread, void **value_ptr);
118*38fd1498Szrj      int __gthread_detach (__gthread_t thread);
119*38fd1498Szrj      int __gthread_equal (__gthread_t t1, __gthread_t t2);
120*38fd1498Szrj      __gthread_t __gthread_self (void);
121*38fd1498Szrj      int __gthread_yield (void);
122*38fd1498Szrj 
123*38fd1498Szrj      int __gthread_mutex_timedlock (__gthread_mutex_t *m,
124*38fd1498Szrj                                     const __gthread_time_t *abs_timeout);
125*38fd1498Szrj      int __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *m,
126*38fd1498Szrj                                           const __gthread_time_t *abs_time);
127*38fd1498Szrj 
128*38fd1498Szrj      int __gthread_cond_signal (__gthread_cond_t *cond);
129*38fd1498Szrj      int __gthread_cond_timedwait (__gthread_cond_t *cond,
130*38fd1498Szrj                                    __gthread_mutex_t *mutex,
131*38fd1498Szrj                                    const __gthread_time_t *abs_timeout);
132*38fd1498Szrj 
133*38fd1498Szrj */
134*38fd1498Szrj 
135*38fd1498Szrj #if SUPPORTS_WEAK
136*38fd1498Szrj /* The pe-coff weak support isn't fully compatible to ELF's weak.
137*38fd1498Szrj    For static libraries it might would work, but as we need to deal
138*38fd1498Szrj    with shared versions too, we disable it for mingw-targets.  */
139*38fd1498Szrj #ifdef __MINGW32__
140*38fd1498Szrj #undef GTHREAD_USE_WEAK
141*38fd1498Szrj #define GTHREAD_USE_WEAK 0
142*38fd1498Szrj #endif
143*38fd1498Szrj 
144*38fd1498Szrj #ifndef GTHREAD_USE_WEAK
145*38fd1498Szrj #define GTHREAD_USE_WEAK 1
146*38fd1498Szrj #endif
147*38fd1498Szrj #endif
148*38fd1498Szrj #include "gthr-default.h"
149*38fd1498Szrj 
150*38fd1498Szrj #ifndef HIDE_EXPORTS
151*38fd1498Szrj #pragma GCC visibility pop
152*38fd1498Szrj #endif
153*38fd1498Szrj 
154*38fd1498Szrj #endif /* ! GCC_GTHR_H */
155