]> git.sur5r.net Git - openldap/blob - include/ldap_pvt_thread.h
Clean up valid flag: _VALUE -> _VALID.
[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 #include <windows.h>
124 #include <process.h>
125
126 LDAP_BEGIN_DECL
127
128 typedef HANDLE                  ldap_pvt_thread_t;
129 typedef HANDLE                  ldap_pvt_thread_mutex_t;
130 typedef HANDLE                  ldap_pvt_thread_cond_t;
131
132 LDAP_END_DECL
133
134 #else
135
136 /***********************************
137  *                                 *
138  * thread definitions for no       *
139  * underlying library support      *
140  *                                 *
141  ***********************************/
142
143 LDAP_BEGIN_DECL
144
145 #ifndef NO_THREADS
146 #define NO_THREADS 1
147 #endif
148
149 typedef int                     ldap_pvt_thread_t;
150 typedef int                     ldap_pvt_thread_mutex_t;
151 typedef int                     ldap_pvt_thread_cond_t;
152
153 LDAP_END_DECL
154
155 #endif /* no threads support */
156
157 #ifndef NO_THREADS
158 #       define HAVE_THREADS 1
159
160 #endif
161
162 LDAP_BEGIN_DECL
163
164 LDAP_F int
165 ldap_pvt_thread_initialize LDAP_P(( void ));
166 LDAP_F int
167 ldap_pvt_thread_destroy LDAP_P(( void ));
168
169 LDAP_F unsigned int
170 ldap_pvt_thread_sleep LDAP_P(( unsigned int s ));
171
172 #ifdef HAVE_GETCONCURRENCY
173 LDAP_F int
174 ldap_pvt_thread_get_concurrency LDAP_P(( void ));
175 #endif
176 #ifdef HAVE_SETCONCURRENCY
177 #       ifndef LDAP_THREAD_CONCURRENCY
178         /* three concurrent threads should be enough */
179 #       define LDAP_THREAD_CONCURRENCY  3
180 #       endif
181 LDAP_F int
182 ldap_pvt_thread_set_concurrency LDAP_P(( int ));
183 #endif
184
185 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
186 #define LDAP_PVT_THREAD_CREATE_DETACHED 1
187
188 LDAP_F int 
189 ldap_pvt_thread_create LDAP_P((
190         ldap_pvt_thread_t * thread, 
191         int     detach,
192         void *(*start_routine)( void * ), 
193         void *arg));
194
195 LDAP_F void 
196 ldap_pvt_thread_exit LDAP_P(( void *retval ));
197
198 LDAP_F int 
199 ldap_pvt_thread_join LDAP_P(( ldap_pvt_thread_t thread, void **status ));
200
201 LDAP_F int 
202 ldap_pvt_thread_kill LDAP_P(( ldap_pvt_thread_t thread, int signo ));
203
204 LDAP_F int 
205 ldap_pvt_thread_yield LDAP_P(( void ));
206
207 LDAP_F int 
208 ldap_pvt_thread_cond_init LDAP_P(( ldap_pvt_thread_cond_t *cond ));
209
210 LDAP_F int 
211 ldap_pvt_thread_cond_destroy LDAP_P(( ldap_pvt_thread_cond_t *cond ));
212
213 LDAP_F int 
214 ldap_pvt_thread_cond_signal LDAP_P(( ldap_pvt_thread_cond_t *cond ));
215
216 LDAP_F int 
217 ldap_pvt_thread_cond_broadcast LDAP_P(( ldap_pvt_thread_cond_t *cond ));
218
219 LDAP_F int 
220 ldap_pvt_thread_cond_wait LDAP_P((
221         ldap_pvt_thread_cond_t *cond, 
222         ldap_pvt_thread_mutex_t *mutex ));
223
224 LDAP_F int 
225 ldap_pvt_thread_mutex_init LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
226
227 LDAP_F int 
228 ldap_pvt_thread_mutex_destroy LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
229
230 LDAP_F int 
231 ldap_pvt_thread_mutex_lock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
232
233 LDAP_F int 
234 ldap_pvt_thread_mutex_trylock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
235
236 LDAP_F int 
237 ldap_pvt_thread_mutex_unlock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
238
239 typedef struct ldap_pvt_thread_rdwr_var {
240         ldap_pvt_thread_mutex_t ltrw_mutex;     
241         ldap_pvt_thread_cond_t ltrw_read;       /* wait for read */
242         ldap_pvt_thread_cond_t ltrw_write;      /* wait for write */
243         int ltrw_valid;
244 #define LDAP_PVT_THREAD_RDWR_VALID 0x0bad
245         int ltrw_r_active;
246         int ltrw_w_active;
247         int ltrw_r_wait;
248         int ltrw_w_wait;
249 } ldap_pvt_thread_rdwr_t;
250
251 LDAP_F int 
252 ldap_pvt_thread_rdwr_init LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
253 LDAP_F int 
254 ldap_pvt_thread_rdwr_destroy LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
255 LDAP_F int 
256 ldap_pvt_thread_rdwr_rlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
257 LDAP_F int 
258 ldap_pvt_thread_rdwr_rtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
259 LDAP_F int 
260 ldap_pvt_thread_rdwr_runlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
261 LDAP_F int 
262 ldap_pvt_thread_rdwr_wlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
263 LDAP_F int 
264 ldap_pvt_thread_rdwr_wtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
265 LDAP_F int 
266 ldap_pvt_thread_rdwr_wunlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
267
268 #ifdef LDAP_DEBUG
269 LDAP_F int 
270 ldap_pvt_thread_rdwr_readers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
271 LDAP_F int 
272 ldap_pvt_thread_rdwr_writers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
273 LDAP_F int 
274 ldap_pvt_thread_rdwr_active LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
275 #endif /* LDAP_DEBUG */
276
277 #define LDAP_PVT_THREAD_EINVAL EINVAL
278 #define LDAP_PVT_THREAD_EBUSY EINVAL
279
280 LDAP_END_DECL
281
282 #endif /* _LDAP_THREAD_H */