]> git.sur5r.net Git - openldap/blob - include/ldap_pvt_thread.h
cleanup old TOOLID macro
[openldap] / include / ldap_pvt_thread.h
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2000 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 #elif defined(HAVE_NT_THREADS)
141
142 LDAP_BEGIN_DECL
143
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 LIBLDAP_F( int )
179 ldap_pvt_thread_initialize LDAP_P(( void ));
180
181 LIBLDAP_F( int )
182 ldap_pvt_thread_destroy LDAP_P(( void ));
183
184 LIBLDAP_F( unsigned int )
185 ldap_pvt_thread_sleep LDAP_P(( unsigned int s ));
186
187 #ifdef HAVE_GETCONCURRENCY
188 LIBLDAP_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 LIBLDAP_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 LIBLDAP_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 LIBLDAP_F( void ) 
212 ldap_pvt_thread_exit LDAP_P(( void *retval ));
213
214 LIBLDAP_F( int )
215 ldap_pvt_thread_join LDAP_P(( ldap_pvt_thread_t thread, void **status ));
216
217 LIBLDAP_F( int )
218 ldap_pvt_thread_kill LDAP_P(( ldap_pvt_thread_t thread, int signo ));
219
220 LIBLDAP_F( int )
221 ldap_pvt_thread_yield LDAP_P(( void ));
222
223 LIBLDAP_F( int )
224 ldap_pvt_thread_cond_init LDAP_P(( ldap_pvt_thread_cond_t *cond ));
225
226 LIBLDAP_F( int )
227 ldap_pvt_thread_cond_destroy LDAP_P(( ldap_pvt_thread_cond_t *cond ));
228
229 LIBLDAP_F( int )
230 ldap_pvt_thread_cond_signal LDAP_P(( ldap_pvt_thread_cond_t *cond ));
231
232 LIBLDAP_F( int )
233 ldap_pvt_thread_cond_broadcast LDAP_P(( ldap_pvt_thread_cond_t *cond ));
234
235 LIBLDAP_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 LIBLDAP_F( int )
241 ldap_pvt_thread_mutex_init LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
242
243 LIBLDAP_F( int )
244 ldap_pvt_thread_mutex_destroy LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
245
246 LIBLDAP_F( int )
247 ldap_pvt_thread_mutex_lock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
248
249 LIBLDAP_F( int )
250 ldap_pvt_thread_mutex_trylock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
251
252 LIBLDAP_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 LIBLDAP_F( int )
268 ldap_pvt_thread_rdwr_init LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
269
270 LIBLDAP_F( int )
271 ldap_pvt_thread_rdwr_destroy LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
272
273 LIBLDAP_F( int )
274 ldap_pvt_thread_rdwr_rlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
275
276 LIBLDAP_F( int )
277 ldap_pvt_thread_rdwr_rtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
278
279 LIBLDAP_F( int )
280 ldap_pvt_thread_rdwr_runlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
281
282 LIBLDAP_F( int )
283 ldap_pvt_thread_rdwr_wlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
284
285 LIBLDAP_F( int )
286 ldap_pvt_thread_rdwr_wtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
287
288 LIBLDAP_F( int )
289 ldap_pvt_thread_rdwr_wunlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
290
291 #ifdef LDAP_DEBUG
292 LIBLDAP_F( int )
293 ldap_pvt_thread_rdwr_readers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
294
295 LIBLDAP_F( int )
296 ldap_pvt_thread_rdwr_writers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
297
298 LIBLDAP_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 */