]> git.sur5r.net Git - openldap/blob - include/ldap_int_thread.h
Fix prev commit
[openldap] / include / ldap_int_thread.h
1 /* ldap_int_thread.h - ldap internal thread wrappers header file */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  * 
5  * Copyright 1998-2008 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17
18 LDAP_BEGIN_DECL
19
20 /* Can be done twice in libldap_r.  See libldap_r/ldap_thr_debug.h. */
21 LDAP_F(int) ldap_int_thread_initialize LDAP_P(( void ));
22 LDAP_F(int) ldap_int_thread_destroy    LDAP_P(( void ));
23
24 LDAP_END_DECL
25
26
27 #ifndef _LDAP_INT_THREAD_H
28 #define _LDAP_INT_THREAD_H
29
30 #if defined( HAVE_PTHREADS )
31 /**********************************
32  *                                *
33  * definitions for POSIX Threads  *
34  *                                *
35  **********************************/
36
37 #include <pthread.h>
38 #ifdef HAVE_SCHED_H
39 #include <sched.h>
40 #endif
41
42 LDAP_BEGIN_DECL
43
44 typedef pthread_t               ldap_int_thread_t;
45 typedef pthread_mutex_t         ldap_int_thread_mutex_t;
46 typedef pthread_cond_t          ldap_int_thread_cond_t;
47
48 #define ldap_int_thread_equal(a, b)     pthread_equal((a), (b))
49
50 #if defined( _POSIX_REENTRANT_FUNCTIONS ) || \
51         defined( _POSIX_THREAD_SAFE_FUNCTIONS ) || \
52         defined( _POSIX_THREADSAFE_FUNCTIONS )
53 #define HAVE_REENTRANT_FUNCTIONS 1
54 #endif
55
56 #if defined( HAVE_PTHREAD_GETCONCURRENCY ) || \
57         defined( HAVE_THR_GETCONCURRENCY )
58 #define LDAP_THREAD_HAVE_GETCONCURRENCY 1
59 #endif
60
61 #if defined( HAVE_PTHREAD_SETCONCURRENCY ) || \
62         defined( HAVE_THR_SETCONCURRENCY )
63 #define LDAP_THREAD_HAVE_SETCONCURRENCY 1
64 #endif
65
66 #if 0 && defined( HAVE_PTHREAD_RWLOCK_DESTROY )
67 #define LDAP_THREAD_HAVE_RDWR 1
68 typedef pthread_rwlock_t ldap_int_thread_rdwr_t;
69 #endif
70
71 LDAP_END_DECL
72
73 #elif defined ( HAVE_MACH_CTHREADS )
74 /**********************************
75  *                                *
76  * definitions for Mach CThreads  *
77  *                                *
78  **********************************/
79
80 #if defined( HAVE_MACH_CTHREADS_H )
81 #       include <mach/cthreads.h>
82 #elif defined( HAVE_CTHREAD_H
83 #       include <cthreads.h>
84 #endif
85
86 LDAP_BEGIN_DECL
87
88 typedef cthread_t               ldap_int_thread_t;
89 typedef struct mutex            ldap_int_thread_mutex_t;
90 typedef struct condition        ldap_int_thread_cond_t;
91
92 LDAP_END_DECL
93
94 #elif defined( HAVE_GNU_PTH )
95 /***********************************
96  *                                 *
97  * thread definitions for GNU Pth  *
98  *                                 *
99  ***********************************/
100
101 #define PTH_SYSCALL_SOFT 1
102 #include <pth.h>
103
104 LDAP_BEGIN_DECL
105
106 typedef pth_t           ldap_int_thread_t;
107 typedef pth_mutex_t     ldap_int_thread_mutex_t;
108 typedef pth_cond_t      ldap_int_thread_cond_t;
109
110 #if 0
111 #define LDAP_THREAD_HAVE_RDWR 1
112 typedef pth_rwlock_t ldap_int_thread_rdwr_t;
113 #endif
114
115 LDAP_END_DECL
116
117 #elif defined( HAVE_THR )
118 /********************************************
119  *                                          *
120  * thread definitions for Solaris LWP (THR) *
121  *                                          *
122  ********************************************/
123
124 #include <thread.h>
125 #include <synch.h>
126
127 LDAP_BEGIN_DECL
128
129 typedef thread_t                ldap_int_thread_t;
130 typedef mutex_t                 ldap_int_thread_mutex_t;
131 typedef cond_t                  ldap_int_thread_cond_t;
132
133 #define HAVE_REENTRANT_FUNCTIONS 1
134
135 #ifdef HAVE_THR_GETCONCURRENCY
136 #define LDAP_THREAD_HAVE_GETCONCURRENCY 1
137 #endif
138 #ifdef HAVE_THR_SETCONCURRENCY
139 #define LDAP_THREAD_HAVE_SETCONCURRENCY 1
140 #endif
141
142 LDAP_END_DECL
143
144 #elif defined( HAVE_LWP )
145 /*************************************
146  *                                   *
147  * thread definitions for SunOS LWP  *
148  *                                   *
149  *************************************/
150
151 #include <lwp/lwp.h>
152 #include <lwp/stackdep.h>
153 #define LDAP_THREAD_HAVE_SLEEP 1
154
155 LDAP_BEGIN_DECL
156
157 typedef thread_t                ldap_int_thread_t;
158 typedef mon_t                   ldap_int_thread_mutex_t;
159 struct ldap_int_thread_lwp_cv {
160         int             lcv_created;
161         cv_t            lcv_cv;
162 };
163 typedef struct ldap_int_thread_lwp_cv ldap_int_thread_cond_t;
164
165 #define HAVE_REENTRANT_FUNCTIONS 1
166
167 LDAP_END_DECL
168
169 #elif defined(HAVE_NT_THREADS)
170 /*************************************
171  *                                   *
172  * thread definitions for NT threads *
173  *                                   *
174  *************************************/
175
176 #include <process.h>
177 #include <windows.h>
178
179 LDAP_BEGIN_DECL
180
181 typedef unsigned long   ldap_int_thread_t;
182 typedef HANDLE  ldap_int_thread_mutex_t;
183 typedef HANDLE  ldap_int_thread_cond_t;
184
185 LDAP_END_DECL
186
187 #else
188 /***********************************
189  *                                 *
190  * thread definitions for no       *
191  * underlying library support      *
192  *                                 *
193  ***********************************/
194
195 #ifndef NO_THREADS
196 #define NO_THREADS 1
197 #endif
198
199 LDAP_BEGIN_DECL
200
201 typedef int                     ldap_int_thread_t;
202 typedef int                     ldap_int_thread_mutex_t;
203 typedef int                     ldap_int_thread_cond_t;
204
205 #define LDAP_THREAD_HAVE_TPOOL 1
206 typedef int                     ldap_int_thread_pool_t;
207
208 LDAP_END_DECL
209
210 #endif /* no threads support */
211
212
213 LDAP_BEGIN_DECL
214
215 #ifndef ldap_int_thread_equal
216 #define ldap_int_thread_equal(a, b)     ((a) == (b))
217 #endif
218
219 #ifndef LDAP_THREAD_HAVE_RDWR
220 typedef struct ldap_int_thread_rdwr_s * ldap_int_thread_rdwr_t;
221 #endif
222
223 LDAP_F(int) ldap_int_thread_pool_startup ( void );
224 LDAP_F(int) ldap_int_thread_pool_shutdown ( void );
225
226 #ifndef LDAP_THREAD_HAVE_TPOOL
227 typedef struct ldap_int_thread_pool_s * ldap_int_thread_pool_t;
228 #endif
229
230 LDAP_END_DECL
231
232
233 #if defined(LDAP_THREAD_DEBUG) && !((LDAP_THREAD_DEBUG +0) & 2U)
234 #define LDAP_THREAD_DEBUG_WRAP 1
235 #endif
236
237 #ifdef LDAP_THREAD_DEBUG_WRAP
238 /**************************************
239  *                                    *
240  * definitions for type-wrapped debug *
241  *                                    *
242  **************************************/
243
244 LDAP_BEGIN_DECL
245
246 #ifndef LDAP_UINTPTR_T  /* May be configured in CPPFLAGS */
247 #define LDAP_UINTPTR_T  unsigned long
248 #endif
249
250 typedef union {
251         unsigned char                   *ptr;
252         LDAP_UINTPTR_T                  num;
253 } ldap_debug_usage_info_t;
254
255 typedef struct {
256         ldap_int_thread_mutex_t wrapped;
257         ldap_debug_usage_info_t usage;
258 } ldap_debug_thread_mutex_t;
259
260 typedef struct {
261         ldap_int_thread_cond_t  wrapped;
262         ldap_debug_usage_info_t usage;
263 } ldap_debug_thread_cond_t;
264
265 typedef struct {
266         ldap_int_thread_rdwr_t  wrapped;
267         ldap_debug_usage_info_t usage;
268 } ldap_debug_thread_rdwr_t;
269
270 LDAP_END_DECL
271
272 #endif /* LDAP_THREAD_DEBUG_WRAP */
273
274 #endif /* _LDAP_INT_THREAD_H */