]> git.sur5r.net Git - openldap/blob - include/ldap_int_thread.h
Really disable pthread rw locks
[openldap] / include / ldap_int_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_int_thread.h - ldap internal thread wrappers header file */
12
13 #ifndef _LDAP_INT_THREAD_H
14 #define _LDAP_INT_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_int_thread_t;
33 typedef pthread_mutex_t         ldap_int_thread_mutex_t;
34 typedef pthread_cond_t          ldap_int_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 #if 0 && defined( HAVE_PTHREAD_RWLOCK_DESTROY )
53 #define LDAP_THREAD_HAVE_RDWR 1
54 typedef pthread_rwlock_t ldap_pvt_thread_rdwr_t;
55 #endif
56
57 LDAP_END_DECL
58
59 #elif defined ( HAVE_MACH_CTHREADS )
60 /**********************************
61  *                                *
62  * definitions for Mach CThreads  *
63  *                                *
64  **********************************/
65
66 #include <mach/cthreads.h>
67
68 LDAP_BEGIN_DECL
69
70 typedef cthread_t               ldap_int_thread_t;
71 typedef struct mutex            ldap_int_thread_mutex_t;
72 typedef struct condition        ldap_int_thread_cond_t;
73
74 LDAP_END_DECL
75
76 #elif defined( HAVE_GNU_PTH )
77 /***********************************
78  *                                 *
79  * thread definitions for GNU Pth  *
80  *                                 *
81  ***********************************/
82
83 #define PTH_SYSCALL_SOFT 1
84 #include <pth.h>
85
86 LDAP_BEGIN_DECL
87
88 typedef pth_t           ldap_int_thread_t;
89 typedef pth_mutex_t     ldap_int_thread_mutex_t;
90 typedef pth_cond_t      ldap_int_thread_cond_t;
91
92 #if 0
93 #define LDAP_THREAD_HAVE_RDWR 1
94 typedef pth_rwlock_t ldap_pvt_thread_rdwr_t;
95 #endif
96
97 LDAP_END_DECL
98
99
100 #elif defined( HAVE_THR )
101 /********************************************
102  *                                          *
103  * thread definitions for Solaris LWP (THR) *
104  *                                          *
105  ********************************************/
106
107 #include <thread.h>
108 #include <synch.h>
109
110 LDAP_BEGIN_DECL
111
112 typedef thread_t                ldap_int_thread_t;
113 typedef mutex_t                 ldap_int_thread_mutex_t;
114 typedef cond_t                  ldap_int_thread_cond_t;
115
116 #define HAVE_REENTRANT_FUNCTIONS 1
117
118 #ifdef HAVE_THR_GETCONCURRENCY
119 #define HAVE_GETCONCURRENCY 1
120 #endif
121 #ifdef HAVE_THR_SETCONCURRENCY
122 #define HAVE_SETCONCURRENCY 1
123 #endif
124
125 LDAP_END_DECL
126
127 #elif defined( HAVE_LWP )
128 /*************************************
129  *                                   *
130  * thread definitions for SunOS LWP  *
131  *                                   *
132  *************************************/
133
134 #include <lwp/lwp.h>
135 #include <lwp/stackdep.h>
136
137 LDAP_BEGIN_DECL
138
139 typedef thread_t                ldap_int_thread_t;
140 typedef mon_t                   ldap_int_thread_mutex_t;
141 struct ldap_int_thread_lwp_cv {
142         int             lcv_created;
143         cv_t            lcv_cv;
144 };
145 typedef struct ldap_int_thread_lwp_cv ldap_int_thread_cond_t;
146
147 #define HAVE_REENTRANT_FUNCTIONS 1
148
149 LDAP_END_DECL
150
151 #elif defined(HAVE_NT_THREADS)
152
153 LDAP_BEGIN_DECL
154
155 #include <process.h>
156 #include <windows.h>
157
158 typedef unsigned long   ldap_int_thread_t;
159 typedef HANDLE  ldap_int_thread_mutex_t;
160 typedef HANDLE  ldap_int_thread_cond_t;
161
162 LDAP_END_DECL
163
164 #else
165
166 /***********************************
167  *                                 *
168  * thread definitions for no       *
169  * underlying library support      *
170  *                                 *
171  ***********************************/
172
173 LDAP_BEGIN_DECL
174
175 #ifndef NO_THREADS
176 #define NO_THREADS 1
177 #endif
178
179 typedef int                     ldap_int_thread_t;
180 typedef int                     ldap_int_thread_mutex_t;
181 typedef int                     ldap_int_thread_cond_t;
182
183 LDAP_END_DECL
184
185 #endif /* no threads support */
186
187 LDAP_BEGIN_DECL
188
189 LIBLDAP_F( int )
190 ldap_int_thread_initialize LDAP_P(( void ));
191
192 LIBLDAP_F( int )
193 ldap_int_thread_destroy LDAP_P(( void ));
194
195 LIBLDAP_F( unsigned int )
196 ldap_int_thread_sleep LDAP_P(( unsigned int s ));
197
198 #ifdef HAVE_GETCONCURRENCY
199 LIBLDAP_F( int )
200 ldap_int_thread_get_concurrency LDAP_P(( void ));
201 #endif
202
203 #ifdef HAVE_SETCONCURRENCY
204 #       ifndef LDAP_THREAD_CONCURRENCY
205         /* three concurrent threads should be enough */
206 #       define LDAP_THREAD_CONCURRENCY  3
207 #       endif
208 LIBLDAP_F( int )
209 ldap_int_thread_set_concurrency LDAP_P(( int ));
210 #endif
211
212 LIBLDAP_F( int ) 
213 ldap_int_thread_create LDAP_P((
214         ldap_int_thread_t * thread, 
215         int     detach,
216         void *(*start_routine)( void * ), 
217         void *arg));
218
219 LIBLDAP_F( void ) 
220 ldap_int_thread_exit LDAP_P(( void *retval ));
221
222 LIBLDAP_F( int )
223 ldap_int_thread_join LDAP_P(( ldap_int_thread_t thread, void **status ));
224
225 LIBLDAP_F( int )
226 ldap_int_thread_kill LDAP_P(( ldap_int_thread_t thread, int signo ));
227
228 LIBLDAP_F( int )
229 ldap_int_thread_yield LDAP_P(( void ));
230
231 LIBLDAP_F( int )
232 ldap_int_thread_cond_init LDAP_P(( ldap_int_thread_cond_t *cond ));
233
234 LIBLDAP_F( int )
235 ldap_int_thread_cond_destroy LDAP_P(( ldap_int_thread_cond_t *cond ));
236
237 LIBLDAP_F( int )
238 ldap_int_thread_cond_signal LDAP_P(( ldap_int_thread_cond_t *cond ));
239
240 LIBLDAP_F( int )
241 ldap_int_thread_cond_broadcast LDAP_P(( ldap_int_thread_cond_t *cond ));
242
243 LIBLDAP_F( int )
244 ldap_int_thread_cond_wait LDAP_P((
245         ldap_int_thread_cond_t *cond, 
246         ldap_int_thread_mutex_t *mutex ));
247
248 LIBLDAP_F( int )
249 ldap_int_thread_mutex_init LDAP_P(( ldap_int_thread_mutex_t *mutex ));
250
251 LIBLDAP_F( int )
252 ldap_int_thread_mutex_destroy LDAP_P(( ldap_int_thread_mutex_t *mutex ));
253
254 LIBLDAP_F( int )
255 ldap_int_thread_mutex_lock LDAP_P(( ldap_int_thread_mutex_t *mutex ));
256
257 LIBLDAP_F( int )
258 ldap_int_thread_mutex_trylock LDAP_P(( ldap_int_thread_mutex_t *mutex ));
259
260 LIBLDAP_F( int )
261 ldap_int_thread_mutex_unlock LDAP_P(( ldap_int_thread_mutex_t *mutex ));
262
263 LDAP_END_DECL
264
265 #endif /* _LDAP_INT_THREAD_H */