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