No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / openldap / dist / include / ldap_int_thread.h
blob155cbb47026d9183fe6bc12521aa0c2bd8c66231
1 /* ldap_int_thread.h - ldap internal thread wrappers header file */
2 /* $OpenLDAP: pkg/ldap/include/ldap_int_thread.h,v 1.20.2.5 2008/02/11 23:26:40 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 *
5 * Copyright 1998-2008 The OpenLDAP Foundation.
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
10 * Public License.
12 * A copy of this license is available in file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
18 LDAP_BEGIN_DECL
20 /* Can be done twice in libldap_r. See libldap_r/ldap_thr_debug.h. */
21 LDAP_F(int) ldap_int_thread_initialize LDAP_P(( void ));
22 LDAP_F(int) ldap_int_thread_destroy LDAP_P(( void ));
24 LDAP_END_DECL
27 #ifndef _LDAP_INT_THREAD_H
28 #define _LDAP_INT_THREAD_H
30 #if defined( HAVE_PTHREADS )
31 /**********************************
32 * *
33 * definitions for POSIX Threads *
34 * *
35 **********************************/
37 #include <pthread.h>
38 #ifdef HAVE_SCHED_H
39 #include <sched.h>
40 #endif
42 LDAP_BEGIN_DECL
44 typedef pthread_t ldap_int_thread_t;
45 typedef pthread_mutex_t ldap_int_thread_mutex_t;
46 typedef pthread_cond_t ldap_int_thread_cond_t;
47 typedef pthread_key_t ldap_int_thread_key_t;
49 #define ldap_int_thread_equal(a, b) pthread_equal((a), (b))
51 #if defined( _POSIX_REENTRANT_FUNCTIONS ) || \
52 defined( _POSIX_THREAD_SAFE_FUNCTIONS ) || \
53 defined( _POSIX_THREADSAFE_FUNCTIONS )
54 #define HAVE_REENTRANT_FUNCTIONS 1
55 #endif
57 #if defined( HAVE_PTHREAD_GETCONCURRENCY ) || \
58 defined( HAVE_THR_GETCONCURRENCY )
59 #define LDAP_THREAD_HAVE_GETCONCURRENCY 1
60 #endif
62 #if defined( HAVE_PTHREAD_SETCONCURRENCY ) || \
63 defined( HAVE_THR_SETCONCURRENCY )
64 #define LDAP_THREAD_HAVE_SETCONCURRENCY 1
65 #endif
67 #if defined( HAVE_PTHREAD_RWLOCK_DESTROY )
68 #define LDAP_THREAD_HAVE_RDWR 1
69 typedef pthread_rwlock_t ldap_int_thread_rdwr_t;
70 #endif
72 LDAP_END_DECL
74 #elif defined ( HAVE_MACH_CTHREADS )
75 /**********************************
76 * *
77 * definitions for Mach CThreads *
78 * *
79 **********************************/
81 #if defined( HAVE_MACH_CTHREADS_H )
82 # include <mach/cthreads.h>
83 #elif defined( HAVE_CTHREAD_H
84 # include <cthreads.h>
85 #endif
87 LDAP_BEGIN_DECL
89 typedef cthread_t ldap_int_thread_t;
90 typedef struct mutex ldap_int_thread_mutex_t;
91 typedef struct condition ldap_int_thread_cond_t;
92 typedef cthread_key_t ldap_int_thread_key_t;
94 LDAP_END_DECL
96 #elif defined( HAVE_GNU_PTH )
97 /***********************************
98 * *
99 * thread definitions for GNU Pth *
101 ***********************************/
103 #define PTH_SYSCALL_SOFT 1
104 #include <pth.h>
106 LDAP_BEGIN_DECL
108 typedef pth_t ldap_int_thread_t;
109 typedef pth_mutex_t ldap_int_thread_mutex_t;
110 typedef pth_cond_t ldap_int_thread_cond_t;
111 typedef pth_key_t ldap_int_thread_key_t;
113 #if 0
114 #define LDAP_THREAD_HAVE_RDWR 1
115 typedef pth_rwlock_t ldap_int_thread_rdwr_t;
116 #endif
118 LDAP_END_DECL
120 #elif defined( HAVE_THR )
121 /********************************************
123 * thread definitions for Solaris LWP (THR) *
125 ********************************************/
127 #include <thread.h>
128 #include <synch.h>
130 LDAP_BEGIN_DECL
132 typedef thread_t ldap_int_thread_t;
133 typedef mutex_t ldap_int_thread_mutex_t;
134 typedef cond_t ldap_int_thread_cond_t;
135 typedef thread_key_t ldap_int_thread_key_t;
137 #define HAVE_REENTRANT_FUNCTIONS 1
139 #ifdef HAVE_THR_GETCONCURRENCY
140 #define LDAP_THREAD_HAVE_GETCONCURRENCY 1
141 #endif
142 #ifdef HAVE_THR_SETCONCURRENCY
143 #define LDAP_THREAD_HAVE_SETCONCURRENCY 1
144 #endif
146 LDAP_END_DECL
148 #elif defined( HAVE_LWP )
149 /*************************************
151 * thread definitions for SunOS LWP *
153 *************************************/
155 #include <lwp/lwp.h>
156 #include <lwp/stackdep.h>
157 #define LDAP_THREAD_HAVE_SLEEP 1
159 LDAP_BEGIN_DECL
161 typedef thread_t ldap_int_thread_t;
162 typedef mon_t ldap_int_thread_mutex_t;
163 struct ldap_int_thread_lwp_cv {
164 int lcv_created;
165 cv_t lcv_cv;
167 typedef struct ldap_int_thread_lwp_cv ldap_int_thread_cond_t;
169 #define HAVE_REENTRANT_FUNCTIONS 1
171 LDAP_END_DECL
173 #elif defined(HAVE_NT_THREADS)
174 /*************************************
176 * thread definitions for NT threads *
178 *************************************/
180 #include <process.h>
181 #include <windows.h>
183 LDAP_BEGIN_DECL
185 typedef unsigned long ldap_int_thread_t;
186 typedef HANDLE ldap_int_thread_mutex_t;
187 typedef HANDLE ldap_int_thread_cond_t;
188 typedef DWORD ldap_int_thread_key_t;
190 LDAP_END_DECL
192 #else
193 /***********************************
195 * thread definitions for no *
196 * underlying library support *
198 ***********************************/
200 #ifndef NO_THREADS
201 #define NO_THREADS 1
202 #endif
204 LDAP_BEGIN_DECL
206 typedef int ldap_int_thread_t;
207 typedef int ldap_int_thread_mutex_t;
208 typedef int ldap_int_thread_cond_t;
209 typedef int ldap_int_thread_key_t;
211 #define LDAP_THREAD_HAVE_TPOOL 1
212 typedef int ldap_int_thread_pool_t;
214 LDAP_END_DECL
216 #endif /* no threads support */
219 LDAP_BEGIN_DECL
221 #ifndef ldap_int_thread_equal
222 #define ldap_int_thread_equal(a, b) ((a) == (b))
223 #endif
225 #ifndef LDAP_THREAD_HAVE_RDWR
226 typedef struct ldap_int_thread_rdwr_s * ldap_int_thread_rdwr_t;
227 #endif
229 LDAP_F(int) ldap_int_thread_pool_startup ( void );
230 LDAP_F(int) ldap_int_thread_pool_shutdown ( void );
232 #ifndef LDAP_THREAD_HAVE_TPOOL
233 typedef struct ldap_int_thread_pool_s * ldap_int_thread_pool_t;
234 #endif
236 typedef struct ldap_int_thread_rmutex_s * ldap_int_thread_rmutex_t;
237 LDAP_END_DECL
240 #if defined(LDAP_THREAD_DEBUG) && !((LDAP_THREAD_DEBUG +0) & 2U)
241 #define LDAP_THREAD_DEBUG_WRAP 1
242 #endif
244 #ifdef LDAP_THREAD_DEBUG_WRAP
245 /**************************************
247 * definitions for type-wrapped debug *
249 **************************************/
251 LDAP_BEGIN_DECL
253 #ifndef LDAP_UINTPTR_T /* May be configured in CPPFLAGS */
254 #define LDAP_UINTPTR_T unsigned long
255 #endif
257 typedef enum {
258 ldap_debug_magic = -(int) (((unsigned)-1)/19)
259 } ldap_debug_magic_t;
261 typedef enum {
262 /* Could fill in "locked" etc here later */
263 ldap_debug_state_inited = (int) (((unsigned)-1)/11),
264 ldap_debug_state_destroyed
265 } ldap_debug_state_t;
267 typedef struct {
268 /* Enclosed in magic numbers in the hope of catching overwrites */
269 ldap_debug_magic_t magic; /* bit pattern to recognize usages */
270 LDAP_UINTPTR_T self; /* ~(LDAP_UINTPTR_T)&(this struct) */
271 union ldap_debug_mem_u { /* Dummy memory reference */
272 unsigned char *ptr;
273 LDAP_UINTPTR_T num;
274 } mem;
275 ldap_debug_state_t state; /* doubles as another magic number */
276 } ldap_debug_usage_info_t;
278 typedef struct {
279 ldap_int_thread_mutex_t wrapped;
280 ldap_debug_usage_info_t usage;
281 ldap_int_thread_t owner;
282 } ldap_debug_thread_mutex_t;
284 typedef struct {
285 ldap_int_thread_cond_t wrapped;
286 ldap_debug_usage_info_t usage;
287 } ldap_debug_thread_cond_t;
289 typedef struct {
290 ldap_int_thread_rdwr_t wrapped;
291 ldap_debug_usage_info_t usage;
292 } ldap_debug_thread_rdwr_t;
294 #ifndef NDEBUG
295 #define LDAP_INT_THREAD_ASSERT_MUTEX_OWNER(mutex) \
296 ldap_debug_thread_assert_mutex_owner( \
297 __FILE__, __LINE__, "owns(" #mutex ")", mutex )
298 LDAP_F(void) ldap_debug_thread_assert_mutex_owner LDAP_P((
299 LDAP_CONST char *file,
300 int line,
301 LDAP_CONST char *msg,
302 ldap_debug_thread_mutex_t *mutex ));
303 #endif /* NDEBUG */
305 LDAP_END_DECL
307 #endif /* LDAP_THREAD_DEBUG_WRAP */
309 #endif /* _LDAP_INT_THREAD_H */