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 /* lthread.h - ldap threads header file */
17 #if defined( HAVE_PTHREADS )
18 /**********************************
20 * definitions for POSIX Threads *
22 **********************************/
31 #if defined( _POSIX_REENTRANT_FUNCTIONS ) || \
32 defined( _POSIX_THREAD_SAFE_FUNCTIONS ) || \
33 defined( _POSIX_THREAD_SAFE_FUNCTIONS )
34 #define HAVE_REENTRANT_FUNCTIONS 1
37 #if !defined( HAVE_PTHREAD_ATTR_INIT ) && \
38 defined( HAVE_PTHREAD_ATTR_CREATE )
39 #define pthread_attr_init( a ) pthread_attr_create( a )
42 #if !defined( HAVE_PTHREAD_ATTR_DESTROY ) && \
43 defined( HAVE_PTHREAD_ATTR_DELETE )
44 #define pthread_attr_destroy( a ) pthread_attr_delete( a )
47 #if !defined( HAVE_PTHREAD_ATTR_SETDETACHSTATE ) && \
48 defined( HAVE_PTHREAD_ATTR_SETDETACH_NP )
49 #define pthread_attr_setdetachstate( a, b ) \
50 pthread_attr_setdetach_np( a, b )
53 #ifndef HAVE_PTHREAD_KILL
54 /* missing pthread_kill(), define prototype */
55 LDAP_F void pthread_kill LDAP_P(( pthread_t tid, int sig ));
58 #ifndef HAVE_PTHREADS_D4
59 #define pthread_mutexattr_default NULL
60 #define pthread_condattr_default NULL
62 #ifdef HAVE_SCHED_YIELD
63 #define pthread_yield sched_yield
69 #elif defined ( HAVE_MACH_CTHREADS )
70 /**********************************
72 * definitions for Mach CThreads *
74 **********************************/
76 #include <mach/cthreads.h>
80 typedef cthread_fn_t VFP;
81 typedef int pthread_attr_t;
82 typedef cthread_t pthread_t;
84 /* default attr states */
85 #define pthread_mutexattr_default NULL
86 #define pthread_condattr_default NULL
88 /* thread state - joinable or not */
89 #define PTHREAD_CREATE_JOINABLE 0
90 #define PTHREAD_CREATE_DETACHED 1
91 /* thread scope - who is in scheduling pool */
92 #define PTHREAD_SCOPE_PROCESS 0
93 #define PTHREAD_SCOPE_SYSTEM 1
95 /* mutex attributes and mutex type */
96 typedef int pthread_mutexattr_t;
97 typedef struct mutex pthread_mutex_t;
99 /* mutex and condition variable scope - process or system */
100 #define PTHREAD_SHARE_PRIVATE 0
101 #define PTHREAD_SHARE_PROCESS 1
103 /* condition variable attributes and condition variable type */
104 typedef int pthread_condattr_t;
105 typedef struct condition pthread_cond_t;
109 #elif defined( HAVE_THR )
110 /**************************************
112 * thread definitions for Solaris LWP *
114 **************************************/
121 #define HAVE_REENTRANT_FUNCTIONS 1
123 typedef void *(*VFP)();
125 /* default attr states */
126 #define pthread_mutexattr_default NULL
127 #define pthread_condattr_default NULL
129 /* thread state - joinable or not */
130 #define PTHREAD_CREATE_JOINABLE 0
131 #define PTHREAD_CREATE_DETACHED THR_DETACHED
132 /* thread scope - who is in scheduling pool */
133 #define PTHREAD_SCOPE_PROCESS 0
134 #define PTHREAD_SCOPE_SYSTEM THR_BOUND
135 /* mutex and condition variable scope - process or system */
136 #define PTHREAD_SHARE_PRIVATE USYNC_THREAD
137 #define PTHREAD_SHARE_PROCESS USYNC_PROCESS
139 /* thread attributes and thread type */
140 typedef int pthread_attr_t;
141 typedef thread_t pthread_t;
143 /* mutex attributes and mutex type */
144 typedef int pthread_mutexattr_t;
145 typedef mutex_t pthread_mutex_t;
147 /* condition variable attributes and condition variable type */
148 typedef int pthread_condattr_t;
149 typedef cond_t pthread_cond_t;
153 #elif defined( HAVE_LWP )
154 /*************************************
156 * thread definitions for SunOS LWP *
158 *************************************/
161 #include <lwp/stackdep.h>
165 #define HAVE_REENTRANT_FUNCTIONS 1
167 stkalign_t *get_stack( int *stacknop );
168 void free_stack( int *stackno );
170 typedef void *(*VFP)();
172 /* thread attributes and thread type */
173 typedef int pthread_attr_t;
174 typedef thread_t pthread_t;
176 /* default attr states */
177 #define pthread_mutexattr_default NULL
178 #define pthread_condattr_default NULL
180 /* thread state - joinable or not */
181 #define PTHREAD_CREATE_JOINABLE 0
182 #define PTHREAD_CREATE_DETACHED 1
183 /* thread scope - who is in scheduling pool */
184 #define PTHREAD_SCOPE_PROCESS 0
185 #define PTHREAD_SCOPE_SYSTEM 1
187 /* mutex attributes and mutex type */
188 typedef int pthread_mutexattr_t;
189 typedef mon_t pthread_mutex_t;
191 /* mutex and condition variable scope - process or system */
192 #define PTHREAD_SHARE_PRIVATE 0
193 #define PTHREAD_SHARE_PROCESS 1
195 /* condition variable attributes and condition variable type */
196 typedef int pthread_condattr_t;
197 typedef struct lwpcv {
204 #elif HAVE_NT_THREADS
209 typedef void (*VFP)(void*);
211 /* thread attributes and thread type */
212 typedef int pthread_attr_t;
213 typedef HANDLE pthread_t;
215 /* default attr states */
216 #define pthread_mutexattr_default NULL
217 #define pthread_condattr_default NULL
219 /* thread state - joinable or not */
220 #define PTHREAD_CREATE_JOINABLE 0
221 #define PTHREAD_CREATE_DETACHED 0
222 /* thread scope - who is in scheduling pool */
223 #define PTHREAD_SCOPE_PROCESS 0
224 #define PTHREAD_SCOPE_SYSTEM 0
226 /* mutex attributes and mutex type */
227 typedef int pthread_mutexattr_t;
228 typedef HANDLE pthread_mutex_t;
230 /* mutex and condition variable scope - process or system */
231 #define PTHREAD_SHARE_PRIVATE USYNC_THREAD
232 #define PTHREAD_SHARE_PROCESS USYNC_PROCESS
234 /* condition variable attributes and condition variable type */
235 typedef int pthread_condattr_t;
236 typedef HANDLE pthread_cond_t;
242 /***********************************
244 * thread definitions for no *
245 * underlying library support *
247 ***********************************/
255 typedef void *(*VFP)();
257 /* thread attributes and thread type */
258 typedef int pthread_attr_t;
259 typedef int pthread_t;
261 /* default attr states */
262 #define pthread_mutexattr_default NULL
263 #define pthread_condattr_default NULL
265 /* thread state - joinable or not */
266 #define PTHREAD_CREATE_JOINABLE 0
267 #define PTHREAD_CREATE_DETACHED 0
268 /* thread scope - who is in scheduling pool */
269 #define PTHREAD_SCOPE_PROCESS 0
270 #define PTHREAD_SCOPE_SYSTEM 0
272 /* mutex attributes and mutex type */
273 typedef int pthread_mutexattr_t;
274 typedef int pthread_mutex_t;
276 /* mutex and condition variable scope - process or system */
277 #define PTHREAD_SHARE_PRIVATE 0
278 #define PTHREAD_SHARE_PROCESS 0
280 /* condition variable attributes and condition variable type */
281 typedef int pthread_condattr_t;
282 typedef int pthread_cond_t;
286 #endif /* no threads support */
289 # define HAVE_THREADS 1
292 #endif /* _LTHREAD_H */