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-2010 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_NT_THREADS)
149 /*************************************
151 * thread definitions for NT threads *
153 *************************************/
160 typedef unsigned long ldap_int_thread_t;
161 typedef HANDLE ldap_int_thread_mutex_t;
162 typedef HANDLE ldap_int_thread_cond_t;
163 typedef DWORD ldap_int_thread_key_t;
168 /***********************************
170 * thread definitions for no *
171 * underlying library support *
173 ***********************************/
181 typedef int ldap_int_thread_t;
182 typedef int ldap_int_thread_mutex_t;
183 typedef int ldap_int_thread_cond_t;
184 typedef int ldap_int_thread_key_t;
186 #define LDAP_THREAD_HAVE_TPOOL 1
187 typedef int ldap_int_thread_pool_t;
191 #endif /* no threads support */
196 #ifndef ldap_int_thread_equal
197 #define ldap_int_thread_equal(a, b) ((a) == (b))
200 #ifndef LDAP_THREAD_HAVE_RDWR
201 typedef struct ldap_int_thread_rdwr_s * ldap_int_thread_rdwr_t;
204 LDAP_F(int) ldap_int_thread_pool_startup ( void );
205 LDAP_F(int) ldap_int_thread_pool_shutdown ( void );
207 #ifndef LDAP_THREAD_HAVE_TPOOL
208 typedef struct ldap_int_thread_pool_s * ldap_int_thread_pool_t;
211 typedef struct ldap_int_thread_rmutex_s * ldap_int_thread_rmutex_t;
215 #if defined(LDAP_THREAD_DEBUG) && !((LDAP_THREAD_DEBUG +0) & 2U)
216 #define LDAP_THREAD_DEBUG_WRAP 1
219 #ifdef LDAP_THREAD_DEBUG_WRAP
220 /**************************************
222 * definitions for type-wrapped debug *
224 **************************************/
228 #ifndef LDAP_UINTPTR_T /* May be configured in CPPFLAGS */
229 #define LDAP_UINTPTR_T unsigned long
233 ldap_debug_magic = -(int) (((unsigned)-1)/19)
234 } ldap_debug_magic_t;
237 /* Could fill in "locked" etc here later */
238 ldap_debug_state_inited = (int) (((unsigned)-1)/11),
239 ldap_debug_state_destroyed
240 } ldap_debug_state_t;
243 /* Enclosed in magic numbers in the hope of catching overwrites */
244 ldap_debug_magic_t magic; /* bit pattern to recognize usages */
245 LDAP_UINTPTR_T self; /* ~(LDAP_UINTPTR_T)&(this struct) */
246 union ldap_debug_mem_u { /* Dummy memory reference */
250 ldap_debug_state_t state; /* doubles as another magic number */
251 } ldap_debug_usage_info_t;
254 ldap_int_thread_mutex_t wrapped;
255 ldap_debug_usage_info_t usage;
256 ldap_int_thread_t owner;
257 } ldap_debug_thread_mutex_t;
260 ldap_int_thread_cond_t wrapped;
261 ldap_debug_usage_info_t usage;
262 } ldap_debug_thread_cond_t;
265 ldap_int_thread_rdwr_t wrapped;
266 ldap_debug_usage_info_t usage;
267 } ldap_debug_thread_rdwr_t;
270 #define LDAP_INT_THREAD_ASSERT_MUTEX_OWNER(mutex) \
271 ldap_debug_thread_assert_mutex_owner( \
272 __FILE__, __LINE__, "owns(" #mutex ")", mutex )
273 LDAP_F(void) ldap_debug_thread_assert_mutex_owner LDAP_P((
274 LDAP_CONST char *file,
276 LDAP_CONST char *msg,
277 ldap_debug_thread_mutex_t *mutex ));
282 #endif /* LDAP_THREAD_DEBUG_WRAP */
284 #endif /* _LDAP_INT_THREAD_H */