]> git.sur5r.net Git - openldap/blob - include/ldap_pvt_thread.h
Fix broken MSVC builds. The previous round of Mingw32 patches changed some
[openldap] / include / ldap_pvt_thread.h
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms are permitted only
7  * as authorized by the OpenLDAP Public License.  A copy of this
8  * license is available at http://www.OpenLDAP.org/license.html or
9  * in file LICENSE in the top-level directory of the distribution.
10  */
11 /* ldap_pvt_thread.h - ldap threads header file NG */
12
13 #ifndef _LDAP_PVT_THREAD_H
14 #define _LDAP_PVT_THREAD_H
15
16 #include "ldap_cdefs.h"
17
18 #if defined( HAVE_PTHREADS )
19 /**********************************
20  *                                *
21  * definitions for POSIX Threads  *
22  *                                *
23  **********************************/
24
25 #include <pthread.h>
26 #ifdef HAVE_SCHED_H
27 #include <sched.h>
28 #endif
29
30 LDAP_BEGIN_DECL
31
32 typedef pthread_t               ldap_pvt_thread_t;
33 typedef pthread_mutex_t         ldap_pvt_thread_mutex_t;
34 typedef pthread_cond_t          ldap_pvt_thread_cond_t;
35
36 #if defined( _POSIX_REENTRANT_FUNCTIONS ) || \
37         defined( _POSIX_THREAD_SAFE_FUNCTIONS ) || \
38         defined( _POSIX_THREADSAFE_FUNCTIONS )
39 #define HAVE_REENTRANT_FUNCTIONS 1
40 #endif
41
42 #if defined( HAVE_PTHREAD_GETCONCURRENCY ) || \
43         defined( HAVE_THR_GETCONCURRENCY )
44 #define HAVE_GETCONCURRENCY 1
45 #endif
46
47 #if defined( HAVE_PTHREAD_SETCONCURRENCY ) || \
48         defined( HAVE_THR_SETCONCURRENCY )
49 #define HAVE_SETCONCURRENCY 1
50 #endif
51
52 LDAP_END_DECL
53
54 #elif defined ( HAVE_MACH_CTHREADS )
55 /**********************************
56  *                                *
57  * definitions for Mach CThreads  *
58  *                                *
59  **********************************/
60
61 #include <mach/cthreads.h>
62
63 LDAP_BEGIN_DECL
64
65 typedef cthread_t               ldap_pvt_thread_t;
66 typedef struct mutex            ldap_pvt_thread_mutex_t;
67 typedef struct condition        ldap_pvt_thread_cond_t;
68
69 LDAP_END_DECL
70
71 #elif defined( HAVE_GNU_PTH )
72 /***********************************
73  *                                 *
74  * thread definitions for GNU Pth  *
75  *                                 *
76  ***********************************/
77
78 #include <pth.h>
79
80 LDAP_BEGIN_DECL
81
82 typedef pth_t           ldap_pvt_thread_t;
83 typedef pth_mutex_t     ldap_pvt_thread_mutex_t;
84 typedef pth_cond_t      ldap_pvt_thread_cond_t;
85
86 LDAP_END_DECL
87
88
89 #elif defined( HAVE_THR )
90 /********************************************
91  *                                          *
92  * thread definitions for Solaris LWP (THR) *
93  *                                          *
94  ********************************************/
95
96 #include <thread.h>
97 #include <synch.h>
98
99 LDAP_BEGIN_DECL
100
101 typedef thread_t                ldap_pvt_thread_t;
102 typedef mutex_t                 ldap_pvt_thread_mutex_t;
103 typedef cond_t                  ldap_pvt_thread_cond_t;
104
105 #define HAVE_REENTRANT_FUNCTIONS 1
106
107 #ifdef HAVE_THR_GETCONCURRENCY
108 #define HAVE_GETCONCURRENCY 1
109 #endif
110 #ifdef HAVE_THR_SETCONCURRENCY
111 #define HAVE_SETCONCURRENCY 1
112 #endif
113
114 LDAP_END_DECL
115
116 #elif defined( HAVE_LWP )
117 /*************************************
118  *                                   *
119  * thread definitions for SunOS LWP  *
120  *                                   *
121  *************************************/
122
123 #include <lwp/lwp.h>
124 #include <lwp/stackdep.h>
125
126 LDAP_BEGIN_DECL
127
128 typedef thread_t                ldap_pvt_thread_t;
129 typedef mon_t                   ldap_pvt_thread_mutex_t;
130 struct ldap_pvt_thread_lwp_cv {
131         int             lcv_created;
132         cv_t            lcv_cv;
133 };
134 typedef struct ldap_pvt_thread_lwp_cv ldap_pvt_thread_cond_t;
135
136 #define HAVE_REENTRANT_FUNCTIONS 1
137
138 LDAP_END_DECL
139
140 /* If we're in the NT env at all, we want these defs, threaded or not */
141 #elif defined(WINNT) || defined(_WINNT) || defined(_WIN32) /* HAVE_NT_THREADS */
142
143 LDAP_BEGIN_DECL
144
145 #define WIN32_LEAN_AND_MEAN
146 #include <process.h>
147 #include <windows.h>
148
149 typedef unsigned long   ldap_pvt_thread_t;
150 typedef HANDLE  ldap_pvt_thread_mutex_t;
151 typedef HANDLE  ldap_pvt_thread_cond_t;
152
153 LDAP_END_DECL
154
155 #else
156
157 /***********************************
158  *                                 *
159  * thread definitions for no       *
160  * underlying library support      *
161  *                                 *
162  ***********************************/
163
164 LDAP_BEGIN_DECL
165
166 #ifndef NO_THREADS
167 #define NO_THREADS 1
168 #endif
169
170 typedef int                     ldap_pvt_thread_t;
171 typedef int                     ldap_pvt_thread_mutex_t;
172 typedef int                     ldap_pvt_thread_cond_t;
173
174 LDAP_END_DECL
175
176 #endif /* no threads support */
177
178 LDAP_BEGIN_DECL
179
180 #ifdef __MINGW32__
181 #   undef LDAP_F_PRE
182 #   ifdef LIBLDAP_DECL
183 #       define LDAP_F_PRE       extern __declspec(LIBLDAP_DECL)
184 #   else
185 #       define LDAP_F_PRE       extern
186 #   endif
187 #endif
188
189 LDAP_F( int )
190 ldap_pvt_thread_initialize LDAP_P(( void ));
191
192 LDAP_F( int )
193 ldap_pvt_thread_destroy LDAP_P(( void ));
194
195 LDAP_F( unsigned int )
196 ldap_pvt_thread_sleep LDAP_P(( unsigned int s ));
197
198 #ifdef HAVE_GETCONCURRENCY
199 LDAP_F( int )
200 ldap_pvt_thread_get_concurrency LDAP_P(( void ));
201 #endif
202
203 #ifdef HAVE_SETCONCURRENCY
204 #       ifndef LDAP_THREAD_CONCURRENCY
205         /* three concurrent threads should be enough */
206 #       define LDAP_THREAD_CONCURRENCY  3
207 #       endif
208 LDAP_F( int )
209 ldap_pvt_thread_set_concurrency LDAP_P(( int ));
210 #endif
211
212 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
213 #define LDAP_PVT_THREAD_CREATE_DETACHED 1
214
215 LDAP_F( int ) 
216 ldap_pvt_thread_create LDAP_P((
217         ldap_pvt_thread_t * thread, 
218         int     detach,
219         void *(*start_routine)( void * ), 
220         void *arg));
221
222 LDAP_F( void ) 
223 ldap_pvt_thread_exit LDAP_P(( void *retval ));
224
225 LDAP_F( int )
226 ldap_pvt_thread_join LDAP_P(( ldap_pvt_thread_t thread, void **status ));
227
228 LDAP_F( int )
229 ldap_pvt_thread_kill LDAP_P(( ldap_pvt_thread_t thread, int signo ));
230
231 LDAP_F( int )
232 ldap_pvt_thread_yield LDAP_P(( void ));
233
234 LDAP_F( int )
235 ldap_pvt_thread_cond_init LDAP_P(( ldap_pvt_thread_cond_t *cond ));
236
237 LDAP_F( int )
238 ldap_pvt_thread_cond_destroy LDAP_P(( ldap_pvt_thread_cond_t *cond ));
239
240 LDAP_F( int )
241 ldap_pvt_thread_cond_signal LDAP_P(( ldap_pvt_thread_cond_t *cond ));
242
243 LDAP_F( int )
244 ldap_pvt_thread_cond_broadcast LDAP_P(( ldap_pvt_thread_cond_t *cond ));
245
246 LDAP_F( int )
247 ldap_pvt_thread_cond_wait LDAP_P((
248         ldap_pvt_thread_cond_t *cond, 
249         ldap_pvt_thread_mutex_t *mutex ));
250
251 LDAP_F( int )
252 ldap_pvt_thread_mutex_init LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
253
254 LDAP_F( int )
255 ldap_pvt_thread_mutex_destroy LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
256
257 LDAP_F( int )
258 ldap_pvt_thread_mutex_lock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
259
260 LDAP_F( int )
261 ldap_pvt_thread_mutex_trylock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
262
263 LDAP_F( int )
264 ldap_pvt_thread_mutex_unlock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
265
266 typedef struct ldap_pvt_thread_rdwr_var {
267         ldap_pvt_thread_mutex_t ltrw_mutex;     
268         ldap_pvt_thread_cond_t ltrw_read;       /* wait for read */
269         ldap_pvt_thread_cond_t ltrw_write;      /* wait for write */
270         int ltrw_valid;
271 #define LDAP_PVT_THREAD_RDWR_VALID 0x0bad
272         int ltrw_r_active;
273         int ltrw_w_active;
274         int ltrw_r_wait;
275         int ltrw_w_wait;
276 } ldap_pvt_thread_rdwr_t;
277
278 LDAP_F( int )
279 ldap_pvt_thread_rdwr_init LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
280
281 LDAP_F( int )
282 ldap_pvt_thread_rdwr_destroy LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
283
284 LDAP_F( int )
285 ldap_pvt_thread_rdwr_rlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
286
287 LDAP_F( int )
288 ldap_pvt_thread_rdwr_rtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
289
290 LDAP_F( int )
291 ldap_pvt_thread_rdwr_runlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
292
293 LDAP_F( int )
294 ldap_pvt_thread_rdwr_wlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
295
296 LDAP_F( int )
297 ldap_pvt_thread_rdwr_wtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
298
299 LDAP_F( int )
300 ldap_pvt_thread_rdwr_wunlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
301
302 #ifdef LDAP_DEBUG
303 LDAP_F( int )
304 ldap_pvt_thread_rdwr_readers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
305
306 LDAP_F( int )
307 ldap_pvt_thread_rdwr_writers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
308
309 LDAP_F( int )
310 ldap_pvt_thread_rdwr_active LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
311 #endif /* LDAP_DEBUG */
312
313 #define LDAP_PVT_THREAD_EINVAL EINVAL
314 #define LDAP_PVT_THREAD_EBUSY EINVAL
315
316 LDAP_END_DECL
317
318 #endif /* _LDAP_THREAD_H */