1 /* ldap_int_thread.h - ldap internal thread wrappers header file */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2006 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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>.
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 ));
27 #ifndef _LDAP_INT_THREAD_H
28 #define _LDAP_INT_THREAD_H
30 #if defined( HAVE_PTHREADS )
31 /**********************************
33 * definitions for POSIX Threads *
35 **********************************/
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;
48 #define ldap_int_thread_equal(a, b) pthread_equal((a), (b))
50 #if defined( _POSIX_REENTRANT_FUNCTIONS ) || \
51 defined( _POSIX_THREAD_SAFE_FUNCTIONS ) || \
52 defined( _POSIX_THREADSAFE_FUNCTIONS )
53 #define HAVE_REENTRANT_FUNCTIONS 1
56 #if defined( HAVE_PTHREAD_GETCONCURRENCY ) || \
57 defined( HAVE_THR_GETCONCURRENCY )
58 #define LDAP_THREAD_HAVE_GETCONCURRENCY 1
61 #if defined( HAVE_PTHREAD_SETCONCURRENCY ) || \
62 defined( HAVE_THR_SETCONCURRENCY )
63 #define LDAP_THREAD_HAVE_SETCONCURRENCY 1
66 #if 0 && defined( HAVE_PTHREAD_RWLOCK_DESTROY )
67 #define LDAP_THREAD_HAVE_RDWR 1
68 typedef pthread_rwlock_t ldap_int_thread_rdwr_t;
73 #elif defined ( HAVE_MACH_CTHREADS )
74 /**********************************
76 * definitions for Mach CThreads *
78 **********************************/
80 #if defined( HAVE_MACH_CTHREADS_H )
81 # include <mach/cthreads.h>
82 #elif defined( HAVE_CTHREAD_H
83 # include <cthreads.h>
88 typedef cthread_t ldap_int_thread_t;
89 typedef struct mutex ldap_int_thread_mutex_t;
90 typedef struct condition ldap_int_thread_cond_t;
94 #elif defined( HAVE_GNU_PTH )
95 /***********************************
97 * thread definitions for GNU Pth *
99 ***********************************/
101 #define PTH_SYSCALL_SOFT 1
106 typedef pth_t ldap_int_thread_t;
107 typedef pth_mutex_t ldap_int_thread_mutex_t;
108 typedef pth_cond_t ldap_int_thread_cond_t;
111 #define LDAP_THREAD_HAVE_RDWR 1
112 typedef pth_rwlock_t ldap_int_thread_rdwr_t;
117 #elif defined( HAVE_THR )
118 /********************************************
120 * thread definitions for Solaris LWP (THR) *
122 ********************************************/
129 typedef thread_t ldap_int_thread_t;
130 typedef mutex_t ldap_int_thread_mutex_t;
131 typedef cond_t ldap_int_thread_cond_t;
133 #define HAVE_REENTRANT_FUNCTIONS 1
135 #ifdef HAVE_THR_GETCONCURRENCY
136 #define LDAP_THREAD_HAVE_GETCONCURRENCY 1
138 #ifdef HAVE_THR_SETCONCURRENCY
139 #define LDAP_THREAD_HAVE_SETCONCURRENCY 1
144 #elif defined( HAVE_LWP )
145 /*************************************
147 * thread definitions for SunOS LWP *
149 *************************************/
152 #include <lwp/stackdep.h>
153 #define LDAP_THREAD_HAVE_SLEEP 1
157 typedef thread_t ldap_int_thread_t;
158 typedef mon_t ldap_int_thread_mutex_t;
159 struct ldap_int_thread_lwp_cv {
163 typedef struct ldap_int_thread_lwp_cv ldap_int_thread_cond_t;
165 #define HAVE_REENTRANT_FUNCTIONS 1
169 #elif defined(HAVE_NT_THREADS)
170 /*************************************
172 * thread definitions for NT threads *
174 *************************************/
181 typedef unsigned long ldap_int_thread_t;
182 typedef HANDLE ldap_int_thread_mutex_t;
183 typedef HANDLE ldap_int_thread_cond_t;
188 /***********************************
190 * thread definitions for no *
191 * underlying library support *
193 ***********************************/
201 typedef int ldap_int_thread_t;
202 typedef int ldap_int_thread_mutex_t;
203 typedef int ldap_int_thread_cond_t;
205 #define LDAP_THREAD_HAVE_TPOOL 1
206 typedef int ldap_int_thread_pool_t;
210 #endif /* no threads support */
215 #ifndef ldap_int_thread_equal
216 #define ldap_int_thread_equal(a, b) ((a) == (b))
219 #ifndef LDAP_THREAD_HAVE_RDWR
220 typedef struct ldap_int_thread_rdwr_s * ldap_int_thread_rdwr_t;
223 LDAP_F(int) ldap_int_thread_pool_startup ( void );
224 LDAP_F(int) ldap_int_thread_pool_shutdown ( void );
226 #ifndef LDAP_THREAD_HAVE_TPOOL
227 typedef struct ldap_int_thread_pool_s * ldap_int_thread_pool_t;
230 typedef struct ldap_int_thread_rmutex_s * ldap_int_thread_rmutex_t;
234 #if defined(LDAP_THREAD_DEBUG) && !((LDAP_THREAD_DEBUG +0) & 2U)
235 #define LDAP_THREAD_DEBUG_WRAP 1
238 #ifdef LDAP_THREAD_DEBUG_WRAP
239 /**************************************
241 * definitions for type-wrapped debug *
243 **************************************/
247 #ifndef LDAP_UINTPTR_T /* May be configured in CPPFLAGS */
248 #define LDAP_UINTPTR_T unsigned long
252 ldap_debug_magic = -(int) (((unsigned)-1)/19)
253 } ldap_debug_magic_t;
256 /* Could fill in "locked" etc here later */
257 ldap_debug_state_inited = (int) (((unsigned)-1)/11),
258 ldap_debug_state_destroyed
259 } ldap_debug_state_t;
262 /* Enclosed in magic numbers in the hope of catching overwrites */
263 ldap_debug_magic_t magic; /* bit pattern to recognize usages */
264 LDAP_UINTPTR_T self; /* ~(LDAP_UINTPTR_T)&(this struct) */
265 union ldap_debug_mem_u { /* Dummy memory reference */
269 ldap_debug_state_t state; /* doubles as another magic number */
270 } ldap_debug_usage_info_t;
273 ldap_int_thread_mutex_t wrapped;
274 ldap_debug_usage_info_t usage;
275 ldap_int_thread_t owner;
276 } ldap_debug_thread_mutex_t;
279 ldap_int_thread_cond_t wrapped;
280 ldap_debug_usage_info_t usage;
281 } ldap_debug_thread_cond_t;
284 ldap_int_thread_rdwr_t wrapped;
285 ldap_debug_usage_info_t usage;
286 } ldap_debug_thread_rdwr_t;
289 #define LDAP_INT_THREAD_ASSERT_MUTEX_OWNER(mutex) \
290 ldap_debug_thread_assert_mutex_owner( \
291 __FILE__, __LINE__, "owns(" #mutex ")", mutex )
292 LDAP_F(void) ldap_debug_thread_assert_mutex_owner LDAP_P((
293 LDAP_CONST char *file,
295 LDAP_CONST char *msg,
296 ldap_debug_thread_mutex_t *mutex ));
301 #endif /* LDAP_THREAD_DEBUG_WRAP */
303 #endif /* _LDAP_INT_THREAD_H */