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;
233 #if defined(LDAP_THREAD_DEBUG) && !((LDAP_THREAD_DEBUG +0) & 2U)
234 #define LDAP_THREAD_DEBUG_WRAP 1
237 #ifdef LDAP_THREAD_DEBUG_WRAP
238 /**************************************
240 * definitions for type-wrapped debug *
242 **************************************/
246 #ifndef LDAP_UINTPTR_T /* May be configured in CPPFLAGS */
247 #define LDAP_UINTPTR_T unsigned long
253 } ldap_debug_usage_info_t;
256 ldap_int_thread_mutex_t wrapped;
257 ldap_debug_usage_info_t usage;
258 ldap_int_thread_t owner;
259 } ldap_debug_thread_mutex_t;
262 ldap_int_thread_cond_t wrapped;
263 ldap_debug_usage_info_t usage;
264 } ldap_debug_thread_cond_t;
267 ldap_int_thread_rdwr_t wrapped;
268 ldap_debug_usage_info_t usage;
269 } ldap_debug_thread_rdwr_t;
272 #define LDAP_INT_THREAD_ASSERT_MUTEX_OWNER(mutex) \
273 ldap_debug_thread_assert_mutex_owner( \
274 _FILE__, __LINE__, "owns(" #mutex ")", mutex )
275 LDAP_F(void) ldap_debug_thread_assert_mutex_owner LDAP_P((
276 LDAP_CONST char *file,
278 LDAP_CONST char *msg,
279 ldap_debug_thread_mutex_t *mutex ));
284 #endif /* LDAP_THREAD_DEBUG_WRAP */
286 #endif /* _LDAP_INT_THREAD_H */