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