]> git.sur5r.net Git - openldap/blob - include/ldap_pvt_thread.h
MegaCommit of locking update.
[openldap] / include / ldap_pvt_thread.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 /* ldap_pvt_thread.h - ldap threads header file NG */
11
12 #ifndef _LDAP_PVT_THREAD_H
13 #define _LDAP_PVT_THREAD_H
14
15 #include "ldap_cdefs.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 typedef pthread_t               ldap_pvt_thread_t;
32 typedef pthread_mutex_t         ldap_pvt_thread_mutex_t;
33 typedef pthread_cond_t          ldap_pvt_thread_cond_t;
34
35 #if defined( _POSIX_REENTRANT_FUNCTIONS ) || \
36         defined( _POSIX_THREAD_SAFE_FUNCTIONS ) || \
37         defined( _POSIX_THREADSAFE_FUNCTIONS )
38 #define HAVE_REENTRANT_FUNCTIONS 1
39 #endif
40
41 #if defined( HAVE_PTHREAD_GETCONCURRENCY ) || \
42         defined( HAVE_THR_GETCONCURRENCY )
43 #define HAVE_GETCONCURRENCY 1
44 #endif
45
46 #if defined( HAVE_PTHREAD_SETCONCURRENCY ) || \
47         defined( HAVE_THR_SETCONCURRENCY )
48 #define HAVE_SETCONCURRENCY 1
49 #endif
50
51 LDAP_END_DECL
52
53 #elif defined ( HAVE_MACH_CTHREADS )
54 /**********************************
55  *                                *
56  * definitions for Mach CThreads  *
57  *                                *
58  **********************************/
59
60 #include <mach/cthreads.h>
61
62 LDAP_BEGIN_DECL
63
64 typedef cthread_t               ldap_pvt_thread_t;
65 typedef struct mutex            ldap_pvt_thread_mutex_t;
66 typedef struct condition        ldap_pvt_thread_cond_t;
67
68 LDAP_END_DECL
69
70 #elif defined( HAVE_THR )
71 /********************************************
72  *                                          *
73  * thread definitions for Solaris LWP (THR) *
74  *                                          *
75  ********************************************/
76
77 #include <thread.h>
78 #include <synch.h>
79
80 LDAP_BEGIN_DECL
81
82 typedef thread_t                ldap_pvt_thread_t;
83 typedef mutex_t                 ldap_pvt_thread_mutex_t;
84 typedef cond_t                  ldap_pvt_thread_cond_t;
85
86 #define HAVE_REENTRANT_FUNCTIONS 1
87
88 #ifdef HAVE_THR_GETCONCURRENCY
89 #define HAVE_GETCONCURRENCY 1
90 #endif
91 #ifdef HAVE_THR_SETCONCURRENCY
92 #define HAVE_SETCONCURRENCY 1
93 #endif
94
95 LDAP_END_DECL
96
97 #elif defined( HAVE_LWP )
98 /*************************************
99  *                                   *
100  * thread definitions for SunOS LWP  *
101  *                                   *
102  *************************************/
103
104 #include <lwp/lwp.h>
105 #include <lwp/stackdep.h>
106
107 LDAP_BEGIN_DECL
108
109 typedef thread_t                ldap_pvt_thread_t;
110 typedef mon_t                   ldap_pvt_thread_mutex_t;
111 struct lwpcv {
112         int             lcv_created;
113         cv_t            lcv_cv;
114 };
115 typedef struct lwpcv            ldap_pvt_thread_cond_t;
116
117 #define HAVE_REENTRANT_FUNCTIONS 1
118
119 LDAP_END_DECL
120
121 #elif HAVE_NT_THREADS
122
123 #include <windows.h>
124 #include <process.h>
125
126 LDAP_BEGIN_DECL
127
128 typedef HANDLE                  ldap_pvt_thread_t;
129 typedef HANDLE                  ldap_pvt_thread_mutex_t;
130 typedef HANDLE                  ldap_pvt_thread_cond_t;
131
132 LDAP_END_DECL
133
134 #else
135
136 /***********************************
137  *                                 *
138  * thread definitions for no       *
139  * underlying library support      *
140  *                                 *
141  ***********************************/
142
143 LDAP_BEGIN_DECL
144
145 #ifndef NO_THREADS
146 #define NO_THREADS 1
147 #endif
148
149 typedef int                     ldap_pvt_thread_t;
150 typedef int                     ldap_pvt_thread_mutex_t;
151 typedef int                     ldap_pvt_thread_cond_t;
152
153 LDAP_END_DECL
154
155 #endif /* no threads support */
156
157 #ifndef NO_THREADS
158 #       define HAVE_THREADS 1
159
160 #endif
161
162 LDAP_BEGIN_DECL
163
164 LDAP_F int
165 ldap_pvt_thread_initialize LDAP_P(( void ));
166
167 LDAP_F unsigned int
168 ldap_pvt_thread_sleep LDAP_P(( unsigned int s ));
169
170 #ifdef HAVE_GETCONCURRENCY
171 LDAP_F int
172 ldap_pvt_thread_getconcurrency LDAP_P(( void ));
173 #endif
174 #ifdef HAVE_SETCONCURRENCY
175 #       ifndef LDAP_THREAD_CONCURRENCY
176         /* three concurrent threads should be enough */
177 #       define LDAP_THREAD_CONCURRENCY  3
178 #       endif
179 LDAP_F int
180 ldap_pvt_thread_setconcurrency LDAP_P(( int ));
181 #endif
182
183 LDAP_F int 
184 ldap_pvt_thread_create LDAP_P((
185         ldap_pvt_thread_t * thread, 
186         int     detach,
187         void *(*start_routine)( void * ), 
188         void *arg));
189
190 LDAP_F void 
191 ldap_pvt_thread_exit LDAP_P(( void *retval ));
192
193 LDAP_F int 
194 ldap_pvt_thread_join LDAP_P(( ldap_pvt_thread_t thread, void **status ));
195
196 LDAP_F int 
197 ldap_pvt_thread_kill LDAP_P(( ldap_pvt_thread_t thread, int signo ));
198
199 LDAP_F int 
200 ldap_pvt_thread_yield LDAP_P(( void ));
201
202 LDAP_F int 
203 ldap_pvt_thread_cond_init LDAP_P(( ldap_pvt_thread_cond_t *cond ));
204
205 LDAP_F int 
206 ldap_pvt_thread_cond_signal LDAP_P(( ldap_pvt_thread_cond_t *cond ));
207
208 LDAP_F int 
209 ldap_pvt_thread_cond_broadcast LDAP_P(( ldap_pvt_thread_cond_t *cond ));
210
211 LDAP_F int 
212 ldap_pvt_thread_cond_wait LDAP_P((
213         ldap_pvt_thread_cond_t *cond, 
214         ldap_pvt_thread_mutex_t *mutex ));
215
216 LDAP_F int 
217 ldap_pvt_thread_mutex_init LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
218
219 LDAP_F int 
220 ldap_pvt_thread_mutex_destroy LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
221
222 LDAP_F int 
223 ldap_pvt_thread_mutex_lock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
224
225 LDAP_F int 
226 ldap_pvt_thread_mutex_trylock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
227
228 LDAP_F int 
229 ldap_pvt_thread_mutex_unlock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
230
231 typedef struct ldap_pvt_thread_rdwr_var {
232         int lt_readers_reading;
233         int lt_writer_writing;
234         ldap_pvt_thread_mutex_t lt_mutex;
235         ldap_pvt_thread_cond_t lt_lock_free;
236 } ldap_pvt_thread_rdwr_t;
237
238 #define LDAP_PVT_THREAD_CREATE_DETACHED 1
239 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
240
241 LDAP_F int 
242 ldap_pvt_thread_rdwr_init LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
243 LDAP_F int 
244 ldap_pvt_thread_rdwr_rlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
245 LDAP_F int 
246 ldap_pvt_thread_rdwr_runlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
247 LDAP_F int 
248 ldap_pvt_thread_rdwr_wlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
249 LDAP_F int 
250 ldap_pvt_thread_rdwr_wunlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
251
252 #ifdef LDAP_DEBUG
253 LDAP_F int 
254 ldap_pvt_thread_rdwr_rchk LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
255 LDAP_F int 
256 ldap_pvt_thread_rdwr_wchk LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
257 LDAP_F int 
258 ldap_pvt_thread_rdwr_rwchk LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
259 #endif /* LDAP_DEBUG */
260
261 LDAP_END_DECL
262
263 #endif /* _LDAP_THREAD_H */