]> git.sur5r.net Git - openldap/blob - include/ldap_pvt_thread.h
7379a9a1bfc9db192762fa5265db5cabd93720f8
[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 "portable.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_attr_t          ldap_pvt_thread_attr_t;
33 typedef pthread_mutex_t         ldap_pvt_thread_mutex_t;
34 typedef pthread_mutexattr_t     ldap_pvt_thread_mutexattr_t;
35 typedef pthread_cond_t          ldap_pvt_thread_cond_t;
36 typedef pthread_condattr_t      ldap_pvt_thread_condattr_t;
37
38 #define LDAP_PVT_THREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED 
39 #define LDAP_PVT_THREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE 
40
41 #if defined( _POSIX_REENTRANT_FUNCTIONS ) || \
42         defined( _POSIX_THREAD_SAFE_FUNCTIONS ) || \
43         defined( _POSIX_THREADSAFE_FUNCTIONS )
44 #define HAVE_REENTRANT_FUNCTIONS 1
45 #endif
46
47 LDAP_END_DECL
48
49 #elif defined ( HAVE_MACH_CTHREADS )
50 /**********************************
51  *                                *
52  * definitions for Mach CThreads  *
53  *                                *
54  **********************************/
55
56 #include <mach/cthreads.h>
57
58 LDAP_BEGIN_DECL
59
60 typedef cthread_t               ldap_pvt_thread_t;
61 typedef int                     ldap_pvt_thread_attr_t;
62 typedef struct mutex            ldap_pvt_thread_mutex_t;
63 typedef int                     ldap_pvt_thread_mutexattr_t;
64 typedef struct condition        ldap_pvt_thread_cond_t;
65 typedef int                     ldap_pvt_thread_condattr_t;
66
67 #define LDAP_PVT_THREAD_CREATE_DETACHED 1
68 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
69
70 LDAP_END_DECL
71
72 #elif defined( HAVE_THR )
73 /**************************************
74  *                                    *
75  * thread definitions for Solaris LWP *
76  *                                    *
77  **************************************/
78
79 #include <thread.h>
80 #include <synch.h>
81
82 LDAP_BEGIN_DECL
83
84 typedef thread_t                ldap_pvt_thread_t;
85 typedef int                     ldap_pvt_thread_attr_t;
86 typedef mutex_t                 ldap_pvt_thread_mutex_t;
87 typedef int                     ldap_pvt_thread_mutexattr_t;
88 typedef cond_t                  ldap_pvt_thread_cond_t;
89 typedef int                     ldap_pvt_thread_condattr_t;
90
91 #define LDAP_PVT_THREAD_CREATE_DETACHED THR_DETACHED
92 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
93
94 #define HAVE_REENTRANT_FUNCTIONS 1
95
96 LDAP_END_DECL
97
98 #elif defined( HAVE_LWP )
99 /*************************************
100  *                                   *
101  * thread definitions for SunOS LWP  *
102  *                                   *
103  *************************************/
104
105 #include <lwp/lwp.h>
106 #include <lwp/stackdep.h>
107
108 LDAP_BEGIN_DECL
109
110 typedef thread_t                ldap_pvt_thread_t;
111 typedef int                     ldap_pvt_thread_attr_t;
112 typedef mon_t                   ldap_pvt_thread_mutex_t;
113 typedef int                     ldap_pvt_thread_mutexattr_t;
114 struct lwpcv {
115         int             lcv_created;
116         cv_t            lcv_cv;
117 };
118 typedef struct lwpcv            ldap_pvt_thread_cond_t;
119 typedef int                     ldap_pvt_thread_condattr_t;
120
121 #define LDAP_PVT_THREAD_CREATE_DETACHED 1
122 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
123
124 #define HAVE_REENTRANT_FUNCTIONS 1
125
126 stkalign_t *ldap_pvt_thread_get_stack( int *stacknop );
127 void ldap_pvt_thread_free_stack( int *stackno );
128
129 LDAP_END_DECL
130
131 #elif HAVE_NT_THREADS
132
133 #include <windows.h>
134 #include <process.h>
135
136 typedef HANDLE                  ldap_pvt_thread_t;
137 typedef int                     ldap_pvt_thread_attr_t;
138 typedef HANDLE                  ldap_pvt_thread_mutex_t;
139 typedef int                     ldap_pvt_thread_mutexattr_t;
140 typedef HANDLE                  ldap_pvt_thread_cond_t;
141 typedef int                     ldap_pvt_thread_condattr_t;
142
143 #define LDAP_PVT_THREAD_CREATE_DETACHED 0
144 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
145
146 #else
147
148 /***********************************
149  *                                 *
150  * thread definitions for no       *
151  * underlying library support      *
152  *                                 *
153  ***********************************/
154
155 LDAP_BEGIN_DECL
156
157 #ifndef NO_THREADS
158 #define NO_THREADS 1
159 #endif
160
161 typedef int                     ldap_pvt_thread_t;
162 typedef int                     ldap_pvt_thread_attr_t;
163 typedef int                     ldap_pvt_thread_mutex_t;
164 typedef int                     ldap_pvt_thread_mutexattr_t;
165 typedef int                     ldap_pvt_thread_cond_t;
166 typedef int                     ldap_pvt_thread_condattr_t;
167
168 #define LDAP_PVT_THREAD_CREATE_DETACHED 0
169 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
170
171 LDAP_END_DECL
172
173 #endif /* no threads support */
174
175 #ifndef NO_THREADS
176 #       define HAVE_THREADS 1
177 #endif
178
179 LDAP_F int 
180 ldap_pvt_thread_create LDAP_P(( ldap_pvt_thread_t * thread, 
181                                ldap_pvt_thread_attr_t *attr,
182                                void *(*start_routine)( void *), 
183                                void *arg));
184
185 LDAP_F void 
186 ldap_pvt_thread_exit LDAP_P(( void *retval ));
187
188 LDAP_F int 
189 ldap_pvt_thread_join LDAP_P(( ldap_pvt_thread_t thread, 
190                              void **thread_return ));
191
192 LDAP_F int 
193 ldap_pvt_thread_kill LDAP_P(( ldap_pvt_thread_t thread, int signo ));
194
195 LDAP_F int 
196 ldap_pvt_thread_yield LDAP_P(( void ));
197
198 LDAP_F int 
199 ldap_pvt_thread_attr_init LDAP_P(( ldap_pvt_thread_attr_t *attr ));
200
201 LDAP_F int 
202 ldap_pvt_thread_attr_destroy LDAP_P(( ldap_pvt_thread_attr_t *attr ));
203
204 LDAP_F int 
205 ldap_pvt_thread_attr_setdetachstate LDAP_P(( ldap_pvt_thread_attr_t *attr, 
206                                             int dstate ));
207
208 LDAP_F int 
209 ldap_pvt_thread_cond_init LDAP_P(( ldap_pvt_thread_cond_t *cond,
210                                   ldap_pvt_thread_condattr_t *attr ));
211
212 LDAP_F int 
213 ldap_pvt_thread_cond_signal LDAP_P(( ldap_pvt_thread_cond_t *cond ));
214
215 LDAP_F int 
216 ldap_pvt_thread_cond_broadcast LDAP_P(( ldap_pvt_thread_cond_t *cond ));
217
218 LDAP_F int 
219 ldap_pvt_thread_cond_wait LDAP_P(( 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                                    ldap_pvt_thread_mutexattr_t *attr ));
225
226 LDAP_F int 
227 ldap_pvt_thread_mutex_destroy LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
228
229 LDAP_F int 
230 ldap_pvt_thread_mutex_lock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
231
232 LDAP_F int 
233 ldap_pvt_thread_mutex_unlock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
234
235 #include <ldap_cdefs.h>
236
237 typedef struct ldap_pvt_thread_rdwr_var {
238         int readers_reading;
239         int writer_writing;
240         ldap_pvt_thread_mutex_t mutex;
241         ldap_pvt_thread_cond_t lock_free;
242 } ldap_pvt_thread_rdwr_t;
243
244 typedef void * ldap_pvt_thread_rdwrattr_t;
245
246 LDAP_F int 
247 ldap_pvt_thread_rdwr_init LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp, 
248                                   ldap_pvt_thread_rdwrattr_t *attrp));
249 LDAP_F int 
250 ldap_pvt_thread_rdwr_rlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
251 LDAP_F int 
252 ldap_pvt_thread_rdwr_runlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
253 LDAP_F int 
254 ldap_pvt_thread_rdwr_wlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
255 LDAP_F int 
256 ldap_pvt_thread_rdwr_wunlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
257
258 #ifdef LDAP_DEBUG
259 LDAP_F int 
260 ldap_pvt_thread_rdwr_rchk LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
261 LDAP_F int 
262 ldap_pvt_thread_rdwr_wchk LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
263 LDAP_F int 
264 ldap_pvt_thread_rdwr_rwchk LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
265 #endif /* LDAP_DEBUG */
266
267 LDAP_END_DECL
268
269 #endif /* _LDAP_THREAD_H */