]> git.sur5r.net Git - openldap/blob - include/ldap_pvt_thread.h
before including <pth.h>:
[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 #define PTH_SYSCALL_SOFT 1
79 #include <pth.h>
80
81 LDAP_BEGIN_DECL
82
83 typedef pth_t           ldap_pvt_thread_t;
84 typedef pth_mutex_t     ldap_pvt_thread_mutex_t;
85 typedef pth_cond_t      ldap_pvt_thread_cond_t;
86
87 LDAP_END_DECL
88
89
90 #elif defined( HAVE_THR )
91 /********************************************
92  *                                          *
93  * thread definitions for Solaris LWP (THR) *
94  *                                          *
95  ********************************************/
96
97 #include <thread.h>
98 #include <synch.h>
99
100 LDAP_BEGIN_DECL
101
102 typedef thread_t                ldap_pvt_thread_t;
103 typedef mutex_t                 ldap_pvt_thread_mutex_t;
104 typedef cond_t                  ldap_pvt_thread_cond_t;
105
106 #define HAVE_REENTRANT_FUNCTIONS 1
107
108 #ifdef HAVE_THR_GETCONCURRENCY
109 #define HAVE_GETCONCURRENCY 1
110 #endif
111 #ifdef HAVE_THR_SETCONCURRENCY
112 #define HAVE_SETCONCURRENCY 1
113 #endif
114
115 LDAP_END_DECL
116
117 #elif defined( HAVE_LWP )
118 /*************************************
119  *                                   *
120  * thread definitions for SunOS LWP  *
121  *                                   *
122  *************************************/
123
124 #include <lwp/lwp.h>
125 #include <lwp/stackdep.h>
126
127 LDAP_BEGIN_DECL
128
129 typedef thread_t                ldap_pvt_thread_t;
130 typedef mon_t                   ldap_pvt_thread_mutex_t;
131 struct ldap_pvt_thread_lwp_cv {
132         int             lcv_created;
133         cv_t            lcv_cv;
134 };
135 typedef struct ldap_pvt_thread_lwp_cv ldap_pvt_thread_cond_t;
136
137 #define HAVE_REENTRANT_FUNCTIONS 1
138
139 LDAP_END_DECL
140
141 #elif defined(HAVE_NT_THREADS)
142
143 LDAP_BEGIN_DECL
144
145 #include <process.h>
146 #include <windows.h>
147
148 typedef unsigned long   ldap_pvt_thread_t;
149 typedef HANDLE  ldap_pvt_thread_mutex_t;
150 typedef HANDLE  ldap_pvt_thread_cond_t;
151
152 LDAP_END_DECL
153
154 #else
155
156 /***********************************
157  *                                 *
158  * thread definitions for no       *
159  * underlying library support      *
160  *                                 *
161  ***********************************/
162
163 LDAP_BEGIN_DECL
164
165 #ifndef NO_THREADS
166 #define NO_THREADS 1
167 #endif
168
169 typedef int                     ldap_pvt_thread_t;
170 typedef int                     ldap_pvt_thread_mutex_t;
171 typedef int                     ldap_pvt_thread_cond_t;
172
173 LDAP_END_DECL
174
175 #endif /* no threads support */
176
177 LDAP_BEGIN_DECL
178
179 LIBLDAP_F( int )
180 ldap_pvt_thread_initialize LDAP_P(( void ));
181
182 LIBLDAP_F( int )
183 ldap_pvt_thread_destroy LDAP_P(( void ));
184
185 LIBLDAP_F( unsigned int )
186 ldap_pvt_thread_sleep LDAP_P(( unsigned int s ));
187
188 #ifdef HAVE_GETCONCURRENCY
189 LIBLDAP_F( int )
190 ldap_pvt_thread_get_concurrency LDAP_P(( void ));
191 #endif
192
193 #ifdef HAVE_SETCONCURRENCY
194 #       ifndef LDAP_THREAD_CONCURRENCY
195         /* three concurrent threads should be enough */
196 #       define LDAP_THREAD_CONCURRENCY  3
197 #       endif
198 LIBLDAP_F( int )
199 ldap_pvt_thread_set_concurrency LDAP_P(( int ));
200 #endif
201
202 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
203 #define LDAP_PVT_THREAD_CREATE_DETACHED 1
204
205 LIBLDAP_F( int ) 
206 ldap_pvt_thread_create LDAP_P((
207         ldap_pvt_thread_t * thread, 
208         int     detach,
209         void *(*start_routine)( void * ), 
210         void *arg));
211
212 LIBLDAP_F( void ) 
213 ldap_pvt_thread_exit LDAP_P(( void *retval ));
214
215 LIBLDAP_F( int )
216 ldap_pvt_thread_join LDAP_P(( ldap_pvt_thread_t thread, void **status ));
217
218 LIBLDAP_F( int )
219 ldap_pvt_thread_kill LDAP_P(( ldap_pvt_thread_t thread, int signo ));
220
221 LIBLDAP_F( int )
222 ldap_pvt_thread_yield LDAP_P(( void ));
223
224 LIBLDAP_F( int )
225 ldap_pvt_thread_cond_init LDAP_P(( ldap_pvt_thread_cond_t *cond ));
226
227 LIBLDAP_F( int )
228 ldap_pvt_thread_cond_destroy LDAP_P(( ldap_pvt_thread_cond_t *cond ));
229
230 LIBLDAP_F( int )
231 ldap_pvt_thread_cond_signal LDAP_P(( ldap_pvt_thread_cond_t *cond ));
232
233 LIBLDAP_F( int )
234 ldap_pvt_thread_cond_broadcast LDAP_P(( ldap_pvt_thread_cond_t *cond ));
235
236 LIBLDAP_F( int )
237 ldap_pvt_thread_cond_wait LDAP_P((
238         ldap_pvt_thread_cond_t *cond, 
239         ldap_pvt_thread_mutex_t *mutex ));
240
241 LIBLDAP_F( int )
242 ldap_pvt_thread_mutex_init LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
243
244 LIBLDAP_F( int )
245 ldap_pvt_thread_mutex_destroy LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
246
247 LIBLDAP_F( int )
248 ldap_pvt_thread_mutex_lock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
249
250 LIBLDAP_F( int )
251 ldap_pvt_thread_mutex_trylock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
252
253 LIBLDAP_F( int )
254 ldap_pvt_thread_mutex_unlock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
255
256 typedef struct ldap_pvt_thread_rdwr_var {
257         ldap_pvt_thread_mutex_t ltrw_mutex;     
258         ldap_pvt_thread_cond_t ltrw_read;       /* wait for read */
259         ldap_pvt_thread_cond_t ltrw_write;      /* wait for write */
260         int ltrw_valid;
261 #define LDAP_PVT_THREAD_RDWR_VALID 0x0bad
262         int ltrw_r_active;
263         int ltrw_w_active;
264         int ltrw_r_wait;
265         int ltrw_w_wait;
266 } ldap_pvt_thread_rdwr_t;
267
268 LIBLDAP_F( int )
269 ldap_pvt_thread_rdwr_init LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
270
271 LIBLDAP_F( int )
272 ldap_pvt_thread_rdwr_destroy LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
273
274 LIBLDAP_F( int )
275 ldap_pvt_thread_rdwr_rlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
276
277 LIBLDAP_F( int )
278 ldap_pvt_thread_rdwr_rtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
279
280 LIBLDAP_F( int )
281 ldap_pvt_thread_rdwr_runlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
282
283 LIBLDAP_F( int )
284 ldap_pvt_thread_rdwr_wlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
285
286 LIBLDAP_F( int )
287 ldap_pvt_thread_rdwr_wtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
288
289 LIBLDAP_F( int )
290 ldap_pvt_thread_rdwr_wunlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
291
292 #ifdef LDAP_DEBUG
293 LIBLDAP_F( int )
294 ldap_pvt_thread_rdwr_readers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
295
296 LIBLDAP_F( int )
297 ldap_pvt_thread_rdwr_writers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
298
299 LIBLDAP_F( int )
300 ldap_pvt_thread_rdwr_active LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
301 #endif /* LDAP_DEBUG */
302
303 #define LDAP_PVT_THREAD_EINVAL EINVAL
304 #define LDAP_PVT_THREAD_EBUSY EINVAL
305
306 LDAP_END_DECL
307
308 #endif /* _LDAP_THREAD_H */