2 * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
5 * Redistribution and use in source and binary forms are permitted only
6 * as authorized by the OpenLDAP Public License. A copy of this
7 * license is available at http://www.OpenLDAP.org/license.html or
8 * in file LICENSE in the top-level directory of the distribution.
10 /* ldap_pvt_thread.h - ldap threads header file NG */
12 #ifndef _LDAP_PVT_THREAD_H
13 #define _LDAP_PVT_THREAD_H
17 #if defined( HAVE_PTHREADS )
18 /**********************************
20 * definitions for POSIX Threads *
22 **********************************/
31 typedef pthread_t ldap_pvt_thread_t;
32 typedef pthread_attr_t ldap_pvt_thread_attr_t;
33 typedef pthread_mutex_t ldap_pvt_thread_mutex_t;
34 typedef pthread_mutexattr_t ldap_pvt_thread_mutexattr_t;
35 typedef pthread_cond_t ldap_pvt_thread_cond_t;
36 typedef pthread_condattr_t ldap_pvt_thread_condattr_t;
38 #define LDAP_PVT_THREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
39 #define LDAP_PVT_THREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
41 #if defined( _POSIX_REENTRANT_FUNCTIONS ) || \
42 defined( _POSIX_THREAD_SAFE_FUNCTIONS ) || \
43 defined( _POSIX_THREADSAFE_FUNCTIONS )
44 #define HAVE_REENTRANT_FUNCTIONS 1
49 #elif defined ( HAVE_MACH_CTHREADS )
50 /**********************************
52 * definitions for Mach CThreads *
54 **********************************/
56 #include <mach/cthreads.h>
60 typedef cthread_t ldap_pvt_thread_t;
61 typedef int ldap_pvt_thread_attr_t;
62 typedef struct mutex ldap_pvt_thread_mutex_t;
63 typedef int ldap_pvt_thread_mutexattr_t;
64 typedef struct condition ldap_pvt_thread_cond_t;
65 typedef int ldap_pvt_thread_condattr_t;
67 #define LDAP_PVT_THREAD_CREATE_DETACHED 1
68 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
72 #elif defined( HAVE_THR )
73 /**************************************
75 * thread definitions for Solaris LWP *
77 **************************************/
84 typedef thread_t ldap_pvt_thread_t;
85 typedef int ldap_pvt_thread_attr_t;
86 typedef mutex_t ldap_pvt_thread_mutex_t;
87 typedef int ldap_pvt_thread_mutexattr_t;
88 typedef cond_t ldap_pvt_thread_cond_t;
89 typedef int ldap_pvt_thread_condattr_t;
91 #define LDAP_PVT_THREAD_CREATE_DETACHED THR_DETACHED
92 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
94 #define HAVE_REENTRANT_FUNCTIONS 1
98 #elif defined( HAVE_LWP )
99 /*************************************
101 * thread definitions for SunOS LWP *
103 *************************************/
106 #include <lwp/stackdep.h>
110 typedef thread_t ldap_pvt_thread_t;
111 typedef int ldap_pvt_thread_attr_t;
112 typedef mon_t ldap_pvt_thread_mutex_t;
113 typedef int ldap_pvt_thread_mutexattr_t;
118 typedef struct lwpcv ldap_pvt_thread_cond_t;
119 typedef int ldap_pvt_thread_condattr_t;
121 #define LDAP_PVT_THREAD_CREATE_DETACHED 1
122 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
124 #define HAVE_REENTRANT_FUNCTIONS 1
126 stkalign_t *ldap_pvt_thread_get_stack( int *stacknop );
127 void ldap_pvt_thread_free_stack( int *stackno );
131 #elif HAVE_NT_THREADS
136 typedef HANDLE ldap_pvt_thread_t;
137 typedef int ldap_pvt_thread_attr_t;
138 typedef HANDLE ldap_pvt_thread_mutex_t;
139 typedef int ldap_pvt_thread_mutexattr_t;
140 typedef HANDLE ldap_pvt_thread_cond_t;
141 typedef int ldap_pvt_thread_condattr_t;
143 #define LDAP_PVT_THREAD_CREATE_DETACHED 0
144 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
148 /***********************************
150 * thread definitions for no *
151 * underlying library support *
153 ***********************************/
161 typedef int ldap_pvt_thread_t;
162 typedef int ldap_pvt_thread_attr_t;
163 typedef int ldap_pvt_thread_mutex_t;
164 typedef int ldap_pvt_thread_mutexattr_t;
165 typedef int ldap_pvt_thread_cond_t;
166 typedef int ldap_pvt_thread_condattr_t;
168 #define LDAP_PVT_THREAD_CREATE_DETACHED 0
169 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
173 #endif /* no threads support */
176 # define HAVE_THREADS 1
180 ldap_pvt_thread_create LDAP_P(( ldap_pvt_thread_t * thread,
181 ldap_pvt_thread_attr_t *attr,
182 void *(*start_routine)( void *),
186 ldap_pvt_thread_exit LDAP_P(( void *retval ));
189 ldap_pvt_thread_join LDAP_P(( ldap_pvt_thread_t thread,
190 void **thread_return ));
193 ldap_pvt_thread_kill LDAP_P(( ldap_pvt_thread_t thread, int signo ));
196 ldap_pvt_thread_yield LDAP_P(( void ));
199 ldap_pvt_thread_attr_init LDAP_P(( ldap_pvt_thread_attr_t *attr ));
202 ldap_pvt_thread_attr_destroy LDAP_P(( ldap_pvt_thread_attr_t *attr ));
205 ldap_pvt_thread_attr_setdetachstate LDAP_P(( ldap_pvt_thread_attr_t *attr,
209 ldap_pvt_thread_cond_init LDAP_P(( ldap_pvt_thread_cond_t *cond,
210 ldap_pvt_thread_condattr_t *attr ));
213 ldap_pvt_thread_cond_signal LDAP_P(( ldap_pvt_thread_cond_t *cond ));
216 ldap_pvt_thread_cond_broadcast LDAP_P(( ldap_pvt_thread_cond_t *cond ));
219 ldap_pvt_thread_cond_wait LDAP_P(( ldap_pvt_thread_cond_t *cond,
220 ldap_pvt_thread_mutex_t *mutex ));
223 ldap_pvt_thread_mutex_init LDAP_P(( ldap_pvt_thread_mutex_t *mutex,
224 ldap_pvt_thread_mutexattr_t *attr ));
227 ldap_pvt_thread_mutex_destroy LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
230 ldap_pvt_thread_mutex_lock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
233 ldap_pvt_thread_mutex_unlock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
235 #include <ldap_cdefs.h>
237 typedef struct ldap_pvt_thread_rdwr_var {
240 ldap_pvt_thread_mutex_t mutex;
241 ldap_pvt_thread_cond_t lock_free;
242 } ldap_pvt_thread_rdwr_t;
244 typedef void * ldap_pvt_thread_rdwrattr_t;
247 ldap_pvt_thread_rdwr_init LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp,
248 ldap_pvt_thread_rdwrattr_t *attrp));
250 ldap_pvt_thread_rdwr_rlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
252 ldap_pvt_thread_rdwr_runlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
254 ldap_pvt_thread_rdwr_wlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
256 ldap_pvt_thread_rdwr_wunlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
260 ldap_pvt_thread_rdwr_rchk LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
262 ldap_pvt_thread_rdwr_wchk LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
264 ldap_pvt_thread_rdwr_rwchk LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
265 #endif /* LDAP_DEBUG */
269 #endif /* _LDAP_THREAD_H */