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