]> git.sur5r.net Git - openldap/blob - include/ldap_int_thread.h
Use pthread rwlocks, if available
[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 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 LDAP_END_DECL
93
94
95 #elif defined( HAVE_THR )
96 /********************************************
97  *                                          *
98  * thread definitions for Solaris LWP (THR) *
99  *                                          *
100  ********************************************/
101
102 #include <thread.h>
103 #include <synch.h>
104
105 LDAP_BEGIN_DECL
106
107 typedef thread_t                ldap_int_thread_t;
108 typedef mutex_t                 ldap_int_thread_mutex_t;
109 typedef cond_t                  ldap_int_thread_cond_t;
110
111 #define HAVE_REENTRANT_FUNCTIONS 1
112
113 #ifdef HAVE_THR_GETCONCURRENCY
114 #define HAVE_GETCONCURRENCY 1
115 #endif
116 #ifdef HAVE_THR_SETCONCURRENCY
117 #define HAVE_SETCONCURRENCY 1
118 #endif
119
120 LDAP_END_DECL
121
122 #elif defined( HAVE_LWP )
123 /*************************************
124  *                                   *
125  * thread definitions for SunOS LWP  *
126  *                                   *
127  *************************************/
128
129 #include <lwp/lwp.h>
130 #include <lwp/stackdep.h>
131
132 LDAP_BEGIN_DECL
133
134 typedef thread_t                ldap_int_thread_t;
135 typedef mon_t                   ldap_int_thread_mutex_t;
136 struct ldap_int_thread_lwp_cv {
137         int             lcv_created;
138         cv_t            lcv_cv;
139 };
140 typedef struct ldap_int_thread_lwp_cv ldap_int_thread_cond_t;
141
142 #define HAVE_REENTRANT_FUNCTIONS 1
143
144 LDAP_END_DECL
145
146 #elif defined(HAVE_NT_THREADS)
147
148 LDAP_BEGIN_DECL
149
150 #include <process.h>
151 #include <windows.h>
152
153 typedef unsigned long   ldap_int_thread_t;
154 typedef HANDLE  ldap_int_thread_mutex_t;
155 typedef HANDLE  ldap_int_thread_cond_t;
156
157 LDAP_END_DECL
158
159 #else
160
161 /***********************************
162  *                                 *
163  * thread definitions for no       *
164  * underlying library support      *
165  *                                 *
166  ***********************************/
167
168 LDAP_BEGIN_DECL
169
170 #ifndef NO_THREADS
171 #define NO_THREADS 1
172 #endif
173
174 typedef int                     ldap_int_thread_t;
175 typedef int                     ldap_int_thread_mutex_t;
176 typedef int                     ldap_int_thread_cond_t;
177
178 LDAP_END_DECL
179
180 #endif /* no threads support */
181
182 LDAP_BEGIN_DECL
183
184 LIBLDAP_F( int )
185 ldap_int_thread_initialize LDAP_P(( void ));
186
187 LIBLDAP_F( int )
188 ldap_int_thread_destroy LDAP_P(( void ));
189
190 LIBLDAP_F( unsigned int )
191 ldap_int_thread_sleep LDAP_P(( unsigned int s ));
192
193 #ifdef HAVE_GETCONCURRENCY
194 LIBLDAP_F( int )
195 ldap_int_thread_get_concurrency LDAP_P(( void ));
196 #endif
197
198 #ifdef HAVE_SETCONCURRENCY
199 #       ifndef LDAP_THREAD_CONCURRENCY
200         /* three concurrent threads should be enough */
201 #       define LDAP_THREAD_CONCURRENCY  3
202 #       endif
203 LIBLDAP_F( int )
204 ldap_int_thread_set_concurrency LDAP_P(( int ));
205 #endif
206
207 LIBLDAP_F( int ) 
208 ldap_int_thread_create LDAP_P((
209         ldap_int_thread_t * thread, 
210         int     detach,
211         void *(*start_routine)( void * ), 
212         void *arg));
213
214 LIBLDAP_F( void ) 
215 ldap_int_thread_exit LDAP_P(( void *retval ));
216
217 LIBLDAP_F( int )
218 ldap_int_thread_join LDAP_P(( ldap_int_thread_t thread, void **status ));
219
220 LIBLDAP_F( int )
221 ldap_int_thread_kill LDAP_P(( ldap_int_thread_t thread, int signo ));
222
223 LIBLDAP_F( int )
224 ldap_int_thread_yield LDAP_P(( void ));
225
226 LIBLDAP_F( int )
227 ldap_int_thread_cond_init LDAP_P(( ldap_int_thread_cond_t *cond ));
228
229 LIBLDAP_F( int )
230 ldap_int_thread_cond_destroy LDAP_P(( ldap_int_thread_cond_t *cond ));
231
232 LIBLDAP_F( int )
233 ldap_int_thread_cond_signal LDAP_P(( ldap_int_thread_cond_t *cond ));
234
235 LIBLDAP_F( int )
236 ldap_int_thread_cond_broadcast LDAP_P(( ldap_int_thread_cond_t *cond ));
237
238 LIBLDAP_F( int )
239 ldap_int_thread_cond_wait LDAP_P((
240         ldap_int_thread_cond_t *cond, 
241         ldap_int_thread_mutex_t *mutex ));
242
243 LIBLDAP_F( int )
244 ldap_int_thread_mutex_init LDAP_P(( ldap_int_thread_mutex_t *mutex ));
245
246 LIBLDAP_F( int )
247 ldap_int_thread_mutex_destroy LDAP_P(( ldap_int_thread_mutex_t *mutex ));
248
249 LIBLDAP_F( int )
250 ldap_int_thread_mutex_lock LDAP_P(( ldap_int_thread_mutex_t *mutex ));
251
252 LIBLDAP_F( int )
253 ldap_int_thread_mutex_trylock LDAP_P(( ldap_int_thread_mutex_t *mutex ));
254
255 LIBLDAP_F( int )
256 ldap_int_thread_mutex_unlock LDAP_P(( ldap_int_thread_mutex_t *mutex ));
257
258 LDAP_END_DECL
259
260 #endif /* _LDAP_INT_THREAD_H */