]> git.sur5r.net Git - openldap/blob - include/lthread.h
Add special check for pthreads under HP-UX (as last resort).
[openldap] / include / lthread.h
1 /*
2  * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
3  * All rights reserved.
4  *
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.
9  */
10 /* lthread.h - ldap threads header file */
11
12 #ifndef _LTHREAD_H
13 #define _LTHREAD_H
14
15 #include "portable.h"
16
17 #if defined( HAVE_PTHREADS )
18 /**********************************
19  *                                *
20  * definitions for POSIX Threads  *
21  *                                *
22  **********************************/
23
24 #include <pthread.h>
25 #ifdef HAVE_SCHED_H
26 #include <sched.h>
27 #endif
28
29 LDAP_BEGIN_DECL
30
31 #if defined( _POSIX_REENTRANT_FUNCTIONS ) || \
32         defined( _POSIX_THREAD_SAFE_FUNCTIONS ) || \
33         defined( _POSIX_THREAD_SAFE_FUNCTIONS )
34 #define HAVE_REENTRANT_FUNCTIONS 1
35 #endif
36
37 #if !defined( HAVE_PTHREAD_ATTR_INIT ) && \
38         defined( HAVE_PTHREAD_ATTR_CREATE )
39 #define pthread_attr_init( a )          pthread_attr_create( a )
40 #endif
41
42 #if !defined( HAVE_PTHREAD_ATTR_DESTROY ) && \
43         defined( HAVE_PTHREAD_ATTR_DELETE )
44 #define pthread_attr_destroy( a )       pthread_attr_delete( a )
45 #endif
46
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 )
51 #endif
52
53 #ifndef HAVE_PTHREAD_KILL
54 /* missing pthread_kill(), define prototype */
55 LDAP_F void pthread_kill LDAP_P(( pthread_t tid, int sig ));
56 #endif
57
58 #ifndef HAVE_PTHREADS_D4
59 #define pthread_mutexattr_default       NULL
60 #define pthread_condattr_default        NULL
61
62 #ifdef HAVE_SCHED_YIELD
63 #define pthread_yield sched_yield
64 #endif
65 #endif
66
67 LDAP_END_DECL
68
69 #elif defined ( HAVE_MACH_CTHREADS )
70 /**********************************
71  *                                *
72  * definitions for Mach CThreads  *
73  *                                *
74  **********************************/
75
76 #include <mach/cthreads.h>
77
78 LDAP_BEGIN_DECL
79
80 typedef cthread_fn_t    VFP;
81 typedef int             pthread_attr_t;
82 typedef cthread_t       pthread_t;
83
84 /* default attr states */
85 #define pthread_mutexattr_default       NULL
86 #define pthread_condattr_default        NULL
87
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
94
95 /* mutex attributes and mutex type */
96 typedef int     pthread_mutexattr_t;
97 typedef struct mutex pthread_mutex_t;
98
99 /* mutex and condition variable scope - process or system */
100 #define PTHREAD_SHARE_PRIVATE   0
101 #define PTHREAD_SHARE_PROCESS   1
102
103 /* condition variable attributes and condition variable type */
104 typedef int     pthread_condattr_t;
105 typedef struct condition pthread_cond_t;
106
107 LDAP_END_DECL
108
109 #elif defined( HAVE_THR )
110 /**************************************
111  *                                    *
112  * thread definitions for Solaris LWP *
113  *                                    *
114  **************************************/
115
116 #include <thread.h>
117 #include <synch.h>
118
119 LDAP_BEGIN_DECL
120
121 #define HAVE_REENTRANT_FUNCTIONS 1
122
123 typedef void    *(*VFP)();
124
125 /* default attr states */
126 #define pthread_mutexattr_default       NULL
127 #define pthread_condattr_default        NULL
128
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
138
139 /* thread attributes and thread type */
140 typedef int             pthread_attr_t;
141 typedef thread_t        pthread_t;
142
143 /* mutex attributes and mutex type */
144 typedef int     pthread_mutexattr_t;
145 typedef mutex_t pthread_mutex_t;
146
147 /* condition variable attributes and condition variable type */
148 typedef int     pthread_condattr_t;
149 typedef cond_t  pthread_cond_t;
150
151 LDAP_END_DECL
152
153 #elif defined( HAVE_LWP )
154 /*************************************
155  *                                   *
156  * thread definitions for SunOS LWP  *
157  *                                   *
158  *************************************/
159
160 #include <lwp/lwp.h>
161 #include <lwp/stackdep.h>
162
163 LDAP_BEGIN_DECL
164
165 #define HAVE_REENTRANT_FUNCTIONS 1
166
167 stkalign_t *get_stack( int *stacknop );
168 void free_stack( int *stackno );
169
170 typedef void    *(*VFP)();
171
172 /* thread attributes and thread type */
173 typedef int             pthread_attr_t;
174 typedef thread_t        pthread_t;
175
176 /* default attr states */
177 #define pthread_mutexattr_default       NULL
178 #define pthread_condattr_default        NULL
179
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
186
187 /* mutex attributes and mutex type */
188 typedef int     pthread_mutexattr_t;
189 typedef mon_t   pthread_mutex_t;
190
191 /* mutex and condition variable scope - process or system */
192 #define PTHREAD_SHARE_PRIVATE   0
193 #define PTHREAD_SHARE_PROCESS   1
194
195 /* condition variable attributes and condition variable type */
196 typedef int     pthread_condattr_t;
197 typedef struct lwpcv {
198         int             lcv_created;
199         cv_t            lcv_cv;
200 } pthread_cond_t;
201
202 LDAP_END_DECL
203
204 #elif HAVE_NT_THREADS
205
206 #include <windows.h>
207 #include <process.h>
208
209 typedef void    (*VFP)(void*);
210
211 /* thread attributes and thread type */
212 typedef int             pthread_attr_t;
213 typedef HANDLE  pthread_t;
214
215 /* default attr states */
216 #define pthread_mutexattr_default       NULL
217 #define pthread_condattr_default        NULL
218
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
225
226 /* mutex attributes and mutex type */
227 typedef int    pthread_mutexattr_t;
228 typedef HANDLE pthread_mutex_t;
229
230 /* mutex and condition variable scope - process or system */
231 #define PTHREAD_SHARE_PRIVATE   USYNC_THREAD
232 #define PTHREAD_SHARE_PROCESS   USYNC_PROCESS
233
234 /* condition variable attributes and condition variable type */
235 typedef int     pthread_condattr_t;
236 typedef HANDLE  pthread_cond_t;
237 typedef int     any_t;
238
239
240 #else
241
242 /***********************************
243  *                                 *
244  * thread definitions for no       *
245  * underlying library support      *
246  *                                 *
247  ***********************************/
248
249 LDAP_BEGIN_DECL
250
251 #ifndef NO_THREADS
252 #define NO_THREADS 1
253 #endif
254
255 typedef void    *(*VFP)();
256
257 /* thread attributes and thread type */
258 typedef int     pthread_attr_t;
259 typedef int     pthread_t;
260
261 /* default attr states */
262 #define pthread_mutexattr_default       NULL
263 #define pthread_condattr_default        NULL
264
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
271
272 /* mutex attributes and mutex type */
273 typedef int     pthread_mutexattr_t;
274 typedef int     pthread_mutex_t;
275
276 /* mutex and condition variable scope - process or system */
277 #define PTHREAD_SHARE_PRIVATE   0
278 #define PTHREAD_SHARE_PROCESS   0
279
280 /* condition variable attributes and condition variable type */
281 typedef int     pthread_condattr_t;
282 typedef int     pthread_cond_t;
283
284 LDAP_END_DECL
285
286 #endif /* no threads support */
287
288 #ifndef NO_THREADS
289 #       define HAVE_THREADS 1
290 #endif
291
292 #endif /* _LTHREAD_H */