]> git.sur5r.net Git - openldap/blob - include/lthread.h
Kill off #elif in ldap/include/. K&R does not support it.
[openldap] / include / lthread.h
1 /* lthread.h - ldap threads header file */
2
3 #ifndef _LTHREAD_H
4 #define _LTHREAD_H
5
6 #include "portable.h"
7
8 #ifdef HAVE_PTHREADS
9 /**********************************
10  *                                *
11  * definitions for POSIX Threads  *
12  *                                *
13  **********************************/
14
15 #include <pthread.h>
16 #ifdef HAVE_SCHED_H
17 #include <sched.h>
18 #endif
19
20 LDAP_BEGIN_DECL
21
22 #if !defined( HAVE_PTHREAD_ATTR_INIT ) && \
23         defined( HAVE_PTHREAD_ATTR_CREATE )
24 #define pthread_attr_init( a )          pthread_attr_create( a )
25 #endif
26
27 #if !defined( HAVE_PTHREAD_ATTR_DESTROY ) && \
28         defined( HAVE_PTHREAD_ATTR_DELETE )
29 #define pthread_attr_destroy( a )       pthread_attr_delete( a )
30 #endif
31
32 #if !defined( HAVE_PTHREAD_ATTR_SETDETACHSTATE ) && \
33         defined( HAVE_PTHREAD_ATTR_SETDETACH_NP )
34 #define pthread_attr_setdetachstate( a, b ) \
35                                         pthread_attr_setdetach_np( a, b )
36 #endif
37
38 #ifndef HAVE_PTHREAD_KILL
39 /* missing pthread_kill(), define prototype */
40 LDAP_F void pthread_kill LDAP_P(( pthread_t tid, int sig ));
41 #endif
42
43 #ifndef HAVE_PTHREADS_D4
44 #define pthread_mutexattr_default       NULL
45 #define pthread_condattr_default        NULL
46
47 #ifdef HAVE_SCHED_YIELD
48 #define pthread_yield sched_yield
49 #endif
50 #endif
51
52 LDAP_END_DECL
53
54 /* Do not use #elif.  K&R does not support it. */
55 #else /* !HAVE_PTHREADS */
56 #ifdef HAVE_MACH_CTHREADS
57 /**********************************
58  *                                *
59  * definitions for Mach CThreads  *
60  *                                *
61  **********************************/
62
63 #include <mach/cthreads.h>
64
65 LDAP_BEGIN_DECL
66
67 typedef cthread_fn_t    VFP;
68 typedef int             pthread_attr_t;
69 typedef cthread_t       pthread_t;
70
71 /* default attr states */
72 #define pthread_mutexattr_default       NULL
73 #define pthread_condattr_default        NULL
74
75 /* thread state - joinable or not */
76 #define PTHREAD_CREATE_JOINABLE 0
77 #define PTHREAD_CREATE_DETACHED 1
78 /* thread scope - who is in scheduling pool */
79 #define PTHREAD_SCOPE_PROCESS   0
80 #define PTHREAD_SCOPE_SYSTEM    1
81
82 /* mutex attributes and mutex type */
83 typedef int     pthread_mutexattr_t;
84 typedef struct mutex pthread_mutex_t;
85
86 /* mutex and condition variable scope - process or system */
87 #define PTHREAD_SHARE_PRIVATE   0
88 #define PTHREAD_SHARE_PROCESS   1
89
90 /* condition variable attributes and condition variable type */
91 typedef int     pthread_condattr_t;
92 typedef struct condition pthread_cond_t;
93
94 LDAP_END_DECL
95
96 #else /* !HAVE_MACH_CTHREADS */
97 #ifdef HAVE_THR
98 /**************************************
99  *                                    *
100  * thread definitions for Solaris LWP *
101  *                                    *
102  **************************************/
103
104 #include <thread.h>
105 #include <synch.h>
106
107 LDAP_BEGIN_DECL
108
109 typedef void    *(*VFP)();
110
111 /* default attr states */
112 #define pthread_mutexattr_default       NULL
113 #define pthread_condattr_default        NULL
114
115 /* thread state - joinable or not */
116 #define PTHREAD_CREATE_JOINABLE 0
117 #define PTHREAD_CREATE_DETACHED THR_DETACHED
118 /* thread scope - who is in scheduling pool */
119 #define PTHREAD_SCOPE_PROCESS   0
120 #define PTHREAD_SCOPE_SYSTEM    THR_BOUND
121 /* mutex and condition variable scope - process or system */
122 #define PTHREAD_SHARE_PRIVATE   USYNC_THREAD
123 #define PTHREAD_SHARE_PROCESS   USYNC_PROCESS
124
125
126 #if !defined(__SunOS_5_6)
127 /* thread attributes and thread type */
128 typedef int             pthread_attr_t;
129 typedef thread_t        pthread_t;
130
131 /* mutex attributes and mutex type */
132 typedef int     pthread_mutexattr_t;
133 typedef mutex_t pthread_mutex_t;
134
135 /* condition variable attributes and condition variable type */
136 typedef int     pthread_condattr_t;
137 typedef cond_t  pthread_cond_t;
138 #endif /* ! sunos56 */
139
140 LDAP_END_DECL
141
142 #else /* !HAVE_THR */
143 #ifdef HAVE_LWP
144 /*************************************
145  *                                   *
146  * thread definitions for SunOS LWP  *
147  *                                   *
148  *************************************/
149
150 #include <lwp/lwp.h>
151 #include <lwp/stackdep.h>
152
153 LDAP_BEGIN_DECL
154
155 stkalign_t *get_stack( int *stacknop );
156 void free_stack( int *stackno );
157
158 typedef void    *(*VFP)();
159
160 /* thread attributes and thread type */
161 typedef int             pthread_attr_t;
162 typedef thread_t        pthread_t;
163
164 /* default attr states */
165 #define pthread_mutexattr_default       NULL
166 #define pthread_condattr_default        NULL
167
168 /* thread state - joinable or not */
169 #define PTHREAD_CREATE_JOINABLE 0
170 #define PTHREAD_CREATE_DETACHED 1
171 /* thread scope - who is in scheduling pool */
172 #define PTHREAD_SCOPE_PROCESS   0
173 #define PTHREAD_SCOPE_SYSTEM    1
174
175 /* mutex attributes and mutex type */
176 typedef int     pthread_mutexattr_t;
177 typedef mon_t   pthread_mutex_t;
178
179 /* mutex and condition variable scope - process or system */
180 #define PTHREAD_SHARE_PRIVATE   0
181 #define PTHREAD_SHARE_PROCESS   1
182
183 /* condition variable attributes and condition variable type */
184 typedef int     pthread_condattr_t;
185 typedef struct lwpcv {
186         int             lcv_created;
187         cv_t            lcv_cv;
188 } pthread_cond_t;
189
190 LDAP_END_DECL
191
192 #else /* !HAVE_LWP */
193 /***********************************
194  *                                 *
195  * thread definitions for no       *
196  * underlying library support      *
197  *                                 *
198  ***********************************/
199
200 LDAP_BEGIN_DECL
201
202 #ifndef NO_THREADS
203 #define NO_THREADS 1
204 #endif
205
206 #ifndef PREEMPTIVE_THREADS
207 /* treat no threads as preemptive */
208 #define PREEMPTIVE_THREADS 1
209 #endif
210
211 typedef void    *(*VFP)();
212
213 /* thread attributes and thread type */
214 typedef int     pthread_attr_t;
215 typedef int     pthread_t;
216
217 /* default attr states */
218 #define pthread_mutexattr_default       NULL
219 #define pthread_condattr_default        NULL
220
221 /* thread state - joinable or not */
222 #define PTHREAD_CREATE_JOINABLE 0
223 #define PTHREAD_CREATE_DETACHED 0
224 /* thread scope - who is in scheduling pool */
225 #define PTHREAD_SCOPE_PROCESS   0
226 #define PTHREAD_SCOPE_SYSTEM    0
227
228 /* mutex attributes and mutex type */
229 typedef int     pthread_mutexattr_t;
230 typedef int     pthread_mutex_t;
231
232 /* mutex and condition variable scope - process or system */
233 #define PTHREAD_SHARE_PRIVATE   0
234 #define PTHREAD_SHARE_PROCESS   0
235
236 /* condition variable attributes and condition variable type */
237 typedef int     pthread_condattr_t;
238 typedef int     pthread_cond_t;
239
240 LDAP_END_DECL
241
242 #endif /* HAVE_LWP */
243 #endif /* HAVE_THR */
244 #endif /* HAVE_MACH_CTHREADS */
245 #endif /* HAVE_PTHREADS */
246 #endif /* _LTHREAD_H */