]> git.sur5r.net Git - openldap/blob - include/ldap_pvt_thread.h
Added fix to allow modrdn whose new rdn was already an attr value.
[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 #ifndef NO_THREADS
159 #       define HAVE_THREADS 1
160 #endif
161
162 LDAP_BEGIN_DECL
163
164 LDAP_F( int )
165 ldap_pvt_thread_initialize LDAP_P(( void ));
166
167 LDAP_F( int )
168 ldap_pvt_thread_destroy LDAP_P(( void ));
169
170 LDAP_F( unsigned int )
171 ldap_pvt_thread_sleep LDAP_P(( unsigned int s ));
172
173 #ifdef HAVE_GETCONCURRENCY
174 LDAP_F( int )
175 ldap_pvt_thread_get_concurrency LDAP_P(( void ));
176 #endif
177
178 #ifdef HAVE_SETCONCURRENCY
179 #       ifndef LDAP_THREAD_CONCURRENCY
180         /* three concurrent threads should be enough */
181 #       define LDAP_THREAD_CONCURRENCY  3
182 #       endif
183 LDAP_F( int )
184 ldap_pvt_thread_set_concurrency LDAP_P(( int ));
185 #endif
186
187 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
188 #define LDAP_PVT_THREAD_CREATE_DETACHED 1
189
190 LDAP_F( int ) 
191 ldap_pvt_thread_create LDAP_P((
192         ldap_pvt_thread_t * thread, 
193         int     detach,
194         void *(*start_routine)( void * ), 
195         void *arg));
196
197 LDAP_F( void ) 
198 ldap_pvt_thread_exit LDAP_P(( void *retval ));
199
200 LDAP_F( int )
201 ldap_pvt_thread_join LDAP_P(( ldap_pvt_thread_t thread, void **status ));
202
203 LDAP_F( int )
204 ldap_pvt_thread_kill LDAP_P(( ldap_pvt_thread_t thread, int signo ));
205
206 LDAP_F( int )
207 ldap_pvt_thread_yield LDAP_P(( void ));
208
209 LDAP_F( int )
210 ldap_pvt_thread_cond_init LDAP_P(( ldap_pvt_thread_cond_t *cond ));
211
212 LDAP_F( int )
213 ldap_pvt_thread_cond_destroy LDAP_P(( ldap_pvt_thread_cond_t *cond ));
214
215 LDAP_F( int )
216 ldap_pvt_thread_cond_signal LDAP_P(( ldap_pvt_thread_cond_t *cond ));
217
218 LDAP_F( int )
219 ldap_pvt_thread_cond_broadcast LDAP_P(( ldap_pvt_thread_cond_t *cond ));
220
221 LDAP_F( int )
222 ldap_pvt_thread_cond_wait LDAP_P((
223         ldap_pvt_thread_cond_t *cond, 
224         ldap_pvt_thread_mutex_t *mutex ));
225
226 LDAP_F( int )
227 ldap_pvt_thread_mutex_init LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
228
229 LDAP_F( int )
230 ldap_pvt_thread_mutex_destroy LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
231
232 LDAP_F( int )
233 ldap_pvt_thread_mutex_lock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
234
235 LDAP_F( int )
236 ldap_pvt_thread_mutex_trylock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
237
238 LDAP_F( int )
239 ldap_pvt_thread_mutex_unlock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
240
241 typedef struct ldap_pvt_thread_rdwr_var {
242         ldap_pvt_thread_mutex_t ltrw_mutex;     
243         ldap_pvt_thread_cond_t ltrw_read;       /* wait for read */
244         ldap_pvt_thread_cond_t ltrw_write;      /* wait for write */
245         int ltrw_valid;
246 #define LDAP_PVT_THREAD_RDWR_VALID 0x0bad
247         int ltrw_r_active;
248         int ltrw_w_active;
249         int ltrw_r_wait;
250         int ltrw_w_wait;
251 } ldap_pvt_thread_rdwr_t;
252
253 LDAP_F( int )
254 ldap_pvt_thread_rdwr_init LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
255
256 LDAP_F( int )
257 ldap_pvt_thread_rdwr_destroy LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
258
259 LDAP_F( int )
260 ldap_pvt_thread_rdwr_rlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
261
262 LDAP_F( int )
263 ldap_pvt_thread_rdwr_rtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
264
265 LDAP_F( int )
266 ldap_pvt_thread_rdwr_runlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
267
268 LDAP_F( int )
269 ldap_pvt_thread_rdwr_wlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
270
271 LDAP_F( int )
272 ldap_pvt_thread_rdwr_wtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
273
274 LDAP_F( int )
275 ldap_pvt_thread_rdwr_wunlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
276
277 #ifdef LDAP_DEBUG
278 LDAP_F( int )
279 ldap_pvt_thread_rdwr_readers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
280
281 LDAP_F( int )
282 ldap_pvt_thread_rdwr_writers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
283
284 LDAP_F( int )
285 ldap_pvt_thread_rdwr_active LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
286 #endif /* LDAP_DEBUG */
287
288 #define LDAP_PVT_THREAD_EINVAL EINVAL
289 #define LDAP_PVT_THREAD_EBUSY EINVAL
290
291 LDAP_END_DECL
292
293 #endif /* _LDAP_THREAD_H */