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-2009 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;
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
57 #if defined( HAVE_PTHREAD_GETCONCURRENCY ) || \
58 defined( HAVE_THR_GETCONCURRENCY )
59 #define LDAP_THREAD_HAVE_GETCONCURRENCY 1
62 #if defined( HAVE_PTHREAD_SETCONCURRENCY ) || \
63 defined( HAVE_THR_SETCONCURRENCY )
64 #define LDAP_THREAD_HAVE_SETCONCURRENCY 1
67 #if defined( HAVE_PTHREAD_RWLOCK_DESTROY )
68 #define LDAP_THREAD_HAVE_RDWR 1
69 typedef pthread_rwlock_t ldap_int_thread_rdwr_t;
74 #elif defined ( HAVE_MACH_CTHREADS )
75 /**********************************
77 * definitions for Mach CThreads *
79 **********************************/
81 #if defined( HAVE_MACH_CTHREADS_H )
82 # include <mach/cthreads.h>
83 #elif defined( HAVE_CTHREADS_H )
84 # include <cthreads.h>
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;
96 #elif defined( HAVE_GNU_PTH )
97 /***********************************
99 * thread definitions for GNU Pth *
101 ***********************************/
103 #define PTH_SYSCALL_SOFT 1
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;
114 #define LDAP_THREAD_HAVE_RDWR 1
115 typedef pth_rwlock_t ldap_int_thread_rdwr_t;
120 #elif defined( HAVE_THR )
121 /********************************************
123 * thread definitions for Solaris LWP (THR) *
125 ********************************************/
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
142 #ifdef HAVE_THR_SETCONCURRENCY
143 #define LDAP_THREAD_HAVE_SETCONCURRENCY 1
148 #elif defined( HAVE_LWP )
149 /*************************************
151 * thread definitions for SunOS LWP *
153 *************************************/
156 #include <lwp/stackdep.h>
157 #define LDAP_THREAD_HAVE_SLEEP 1
161 typedef thread_t ldap_int_thread_t;
162 typedef mon_t ldap_int_thread_mutex_t;
163 struct ldap_int_thread_lwp_cv {
167 typedef struct ldap_int_thread_lwp_cv ldap_int_thread_cond_t;
169 #define HAVE_REENTRANT_FUNCTIONS 1
173 #elif defined(HAVE_NT_THREADS)
174 /*************************************
176 * thread definitions for NT threads *
178 *************************************/
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;
193 /***********************************
195 * thread definitions for no *
196 * underlying library support *
198 ***********************************/
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;
216 #endif /* no threads support */
221 #ifndef ldap_int_thread_equal
222 #define ldap_int_thread_equal(a, b) ((a) == (b))
225 #ifndef LDAP_THREAD_HAVE_RDWR
226 typedef struct ldap_int_thread_rdwr_s * ldap_int_thread_rdwr_t;
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;
236 typedef struct ldap_int_thread_rmutex_s * ldap_int_thread_rmutex_t;
240 #if defined(LDAP_THREAD_DEBUG) && !((LDAP_THREAD_DEBUG +0) & 2U)
241 #define LDAP_THREAD_DEBUG_WRAP 1
244 #ifdef LDAP_THREAD_DEBUG_WRAP
245 /**************************************
247 * definitions for type-wrapped debug *
249 **************************************/
253 #ifndef LDAP_UINTPTR_T /* May be configured in CPPFLAGS */
254 #define LDAP_UINTPTR_T unsigned long
258 ldap_debug_magic = -(int) (((unsigned)-1)/19)
259 } ldap_debug_magic_t;
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;
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 */
275 ldap_debug_state_t state; /* doubles as another magic number */
276 } ldap_debug_usage_info_t;
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;
285 ldap_int_thread_cond_t wrapped;
286 ldap_debug_usage_info_t usage;
287 } ldap_debug_thread_cond_t;
290 ldap_int_thread_rdwr_t wrapped;
291 ldap_debug_usage_info_t usage;
292 } ldap_debug_thread_rdwr_t;
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,
301 LDAP_CONST char *msg,
302 ldap_debug_thread_mutex_t *mutex ));
307 #endif /* LDAP_THREAD_DEBUG_WRAP */
309 #endif /* _LDAP_INT_THREAD_H */