]> git.sur5r.net Git - openldap/blob - include/ldap_pvt_thread.h
Merge remote-tracking branch 'origin/mdb.master'
[openldap] / include / ldap_pvt_thread.h
1 /* ldap_pvt_thread.h - ldap threads header file */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  * 
5  * Copyright 1998-2013 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 #ifndef _LDAP_PVT_THREAD_H
18 #define _LDAP_PVT_THREAD_H /* libldap_r/ldap_thr_debug.h #undefines this */
19
20 #include "ldap_cdefs.h"
21 #include "ldap_int_thread.h"
22
23 LDAP_BEGIN_DECL
24
25 #ifndef LDAP_PVT_THREAD_H_DONE
26 typedef ldap_int_thread_t                       ldap_pvt_thread_t;
27 #ifdef LDAP_THREAD_DEBUG_WRAP
28 typedef ldap_debug_thread_mutex_t       ldap_pvt_thread_mutex_t;
29 typedef ldap_debug_thread_cond_t        ldap_pvt_thread_cond_t;
30 typedef ldap_debug_thread_rdwr_t        ldap_pvt_thread_rdwr_t;
31 #define LDAP_PVT_MUTEX_FIRSTCREATE      LDAP_DEBUG_MUTEX_FIRSTCREATE
32 #define LDAP_PVT_MUTEX_NULL                     LDAP_DEBUG_MUTEX_NULL
33 #else
34 typedef ldap_int_thread_mutex_t         ldap_pvt_thread_mutex_t;
35 typedef ldap_int_thread_cond_t          ldap_pvt_thread_cond_t;
36 typedef ldap_int_thread_rdwr_t          ldap_pvt_thread_rdwr_t;
37 #define LDAP_PVT_MUTEX_FIRSTCREATE      LDAP_INT_MUTEX_FIRSTCREATE
38 #define LDAP_PVT_MUTEX_NULL                     LDAP_INT_MUTEX_NULL
39 #endif
40 typedef ldap_int_thread_rmutex_t        ldap_pvt_thread_rmutex_t;
41 typedef ldap_int_thread_key_t   ldap_pvt_thread_key_t;
42 #endif /* !LDAP_PVT_THREAD_H_DONE */
43
44 #define ldap_pvt_thread_equal           ldap_int_thread_equal
45
46 LDAP_F( int )
47 ldap_pvt_thread_initialize LDAP_P(( void ));
48
49 LDAP_F( int )
50 ldap_pvt_thread_destroy LDAP_P(( void ));
51
52 LDAP_F( unsigned int )
53 ldap_pvt_thread_sleep LDAP_P(( unsigned int s ));
54
55 LDAP_F( int )
56 ldap_pvt_thread_get_concurrency LDAP_P(( void ));
57
58 LDAP_F( int )
59 ldap_pvt_thread_set_concurrency LDAP_P(( int ));
60
61 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
62 #define LDAP_PVT_THREAD_CREATE_DETACHED 1
63
64 #ifndef LDAP_PVT_THREAD_H_DONE
65 #define LDAP_PVT_THREAD_SET_STACK_SIZE
66 /* The size may be explicitly #defined to zero to disable it. */
67 #if defined( LDAP_PVT_THREAD_STACK_SIZE ) && LDAP_PVT_THREAD_STACK_SIZE == 0
68 #       undef LDAP_PVT_THREAD_SET_STACK_SIZE
69 #elif !defined( LDAP_PVT_THREAD_STACK_SIZE )
70         /* LARGE stack. Will be twice as large on 64 bit machine. */
71 #       define LDAP_PVT_THREAD_STACK_SIZE ( 1 * 1024 * 1024 * sizeof(void *) )
72 #endif
73 #endif /* !LDAP_PVT_THREAD_H_DONE */
74
75 LDAP_F( int )
76 ldap_pvt_thread_create LDAP_P((
77         ldap_pvt_thread_t * thread,
78         int     detach,
79         void *(*start_routine)( void * ),
80         void *arg));
81
82 LDAP_F( void )
83 ldap_pvt_thread_exit LDAP_P(( void *retval ));
84
85 LDAP_F( int )
86 ldap_pvt_thread_join LDAP_P(( ldap_pvt_thread_t thread, void **status ));
87
88 LDAP_F( int )
89 ldap_pvt_thread_kill LDAP_P(( ldap_pvt_thread_t thread, int signo ));
90
91 LDAP_F( int )
92 ldap_pvt_thread_yield LDAP_P(( void ));
93
94 LDAP_F( int )
95 ldap_pvt_thread_cond_init LDAP_P(( ldap_pvt_thread_cond_t *cond ));
96
97 LDAP_F( int )
98 ldap_pvt_thread_cond_destroy LDAP_P(( ldap_pvt_thread_cond_t *cond ));
99
100 LDAP_F( int )
101 ldap_pvt_thread_cond_signal LDAP_P(( ldap_pvt_thread_cond_t *cond ));
102
103 LDAP_F( int )
104 ldap_pvt_thread_cond_broadcast LDAP_P(( ldap_pvt_thread_cond_t *cond ));
105
106 LDAP_F( int )
107 ldap_pvt_thread_cond_wait LDAP_P((
108         ldap_pvt_thread_cond_t *cond,
109         ldap_pvt_thread_mutex_t *mutex ));
110
111 LDAP_F( int )
112 ldap_pvt_thread_mutex_init LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
113
114 LDAP_F( int )
115 ldap_pvt_thread_mutex_destroy LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
116
117 LDAP_F( int )
118 ldap_pvt_thread_mutex_lock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
119
120 LDAP_F( int )
121 ldap_pvt_thread_mutex_trylock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
122
123 LDAP_F( int )
124 ldap_pvt_thread_mutex_unlock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
125
126 LDAP_F( int )
127 ldap_pvt_thread_rmutex_init LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex ));
128
129 LDAP_F( int )
130 ldap_pvt_thread_rmutex_destroy LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex ));
131
132 LDAP_F( int )
133 ldap_pvt_thread_rmutex_lock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex,
134         ldap_pvt_thread_t owner));
135
136 LDAP_F( int )
137 ldap_pvt_thread_rmutex_trylock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex,
138         ldap_pvt_thread_t owner));
139
140 LDAP_F( int )
141 ldap_pvt_thread_rmutex_unlock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex,
142         ldap_pvt_thread_t owner));
143
144 LDAP_F( ldap_pvt_thread_t )
145 ldap_pvt_thread_self LDAP_P(( void ));
146
147 #ifdef  LDAP_INT_THREAD_ASSERT_MUTEX_OWNER
148 #define LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER LDAP_INT_THREAD_ASSERT_MUTEX_OWNER
149 #else
150 #define LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER(mutex) ((void) 0)
151 #endif
152
153 LDAP_F( int )
154 ldap_pvt_thread_rdwr_init LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
155
156 LDAP_F( int )
157 ldap_pvt_thread_rdwr_destroy LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
158
159 LDAP_F( int )
160 ldap_pvt_thread_rdwr_rlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
161
162 LDAP_F( int )
163 ldap_pvt_thread_rdwr_rtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
164
165 LDAP_F( int )
166 ldap_pvt_thread_rdwr_runlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
167
168 LDAP_F( int )
169 ldap_pvt_thread_rdwr_wlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
170
171 LDAP_F( int )
172 ldap_pvt_thread_rdwr_wtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
173
174 LDAP_F( int )
175 ldap_pvt_thread_rdwr_wunlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
176
177 LDAP_F( int )
178 ldap_pvt_thread_key_create LDAP_P((ldap_pvt_thread_key_t *keyp));
179
180 LDAP_F( int )
181 ldap_pvt_thread_key_destroy LDAP_P((ldap_pvt_thread_key_t key));
182
183 LDAP_F( int )
184 ldap_pvt_thread_key_setdata LDAP_P((ldap_pvt_thread_key_t key, void *data));
185
186 LDAP_F( int )
187 ldap_pvt_thread_key_getdata LDAP_P((ldap_pvt_thread_key_t key, void **data));
188
189 #ifdef LDAP_DEBUG
190 LDAP_F( int )
191 ldap_pvt_thread_rdwr_readers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
192
193 LDAP_F( int )
194 ldap_pvt_thread_rdwr_writers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
195
196 LDAP_F( int )
197 ldap_pvt_thread_rdwr_active LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
198 #endif /* LDAP_DEBUG */
199
200 #define LDAP_PVT_THREAD_EINVAL EINVAL
201 #define LDAP_PVT_THREAD_EBUSY EINVAL
202
203 #ifndef LDAP_PVT_THREAD_H_DONE
204 typedef ldap_int_thread_pool_t ldap_pvt_thread_pool_t;
205
206 typedef void * (ldap_pvt_thread_start_t) LDAP_P((void *ctx, void *arg));
207 typedef void (ldap_pvt_thread_pool_keyfree_t) LDAP_P((void *key, void *data));
208 #endif /* !LDAP_PVT_THREAD_H_DONE */
209
210 LDAP_F( int )
211 ldap_pvt_thread_pool_init LDAP_P((
212         ldap_pvt_thread_pool_t *pool_out,
213         int max_threads,
214         int max_pending ));
215
216 LDAP_F( int )
217 ldap_pvt_thread_pool_init_q LDAP_P((
218         ldap_pvt_thread_pool_t *pool_out,
219         int max_threads,
220         int max_pending,
221         int num_qs ));
222
223 LDAP_F( int )
224 ldap_pvt_thread_pool_submit LDAP_P((
225         ldap_pvt_thread_pool_t *pool,
226         ldap_pvt_thread_start_t *start,
227         void *arg ));
228
229 LDAP_F( int )
230 ldap_pvt_thread_pool_retract LDAP_P((
231         ldap_pvt_thread_pool_t *pool,
232         ldap_pvt_thread_start_t *start,
233         void *arg ));
234
235 LDAP_F( int )
236 ldap_pvt_thread_pool_maxthreads LDAP_P((
237         ldap_pvt_thread_pool_t *pool,
238         int max_threads ));
239
240 #ifndef LDAP_PVT_THREAD_H_DONE
241 typedef enum {
242         LDAP_PVT_THREAD_POOL_PARAM_UNKNOWN = -1,
243         LDAP_PVT_THREAD_POOL_PARAM_MAX,
244         LDAP_PVT_THREAD_POOL_PARAM_MAX_PENDING,
245         LDAP_PVT_THREAD_POOL_PARAM_OPEN,
246         LDAP_PVT_THREAD_POOL_PARAM_STARTING,
247         LDAP_PVT_THREAD_POOL_PARAM_ACTIVE,
248         LDAP_PVT_THREAD_POOL_PARAM_PAUSING,
249         LDAP_PVT_THREAD_POOL_PARAM_PENDING,
250         LDAP_PVT_THREAD_POOL_PARAM_BACKLOAD,
251         LDAP_PVT_THREAD_POOL_PARAM_ACTIVE_MAX,
252         LDAP_PVT_THREAD_POOL_PARAM_PENDING_MAX,
253         LDAP_PVT_THREAD_POOL_PARAM_BACKLOAD_MAX,
254         LDAP_PVT_THREAD_POOL_PARAM_STATE
255 } ldap_pvt_thread_pool_param_t;
256 #endif /* !LDAP_PVT_THREAD_H_DONE */
257
258 LDAP_F( int )
259 ldap_pvt_thread_pool_query LDAP_P((
260         ldap_pvt_thread_pool_t *pool,
261         ldap_pvt_thread_pool_param_t param, void *value ));
262
263 LDAP_F( int )
264 ldap_pvt_thread_pool_pausing LDAP_P((
265         ldap_pvt_thread_pool_t *pool ));
266
267 LDAP_F( int )
268 ldap_pvt_thread_pool_backload LDAP_P((
269         ldap_pvt_thread_pool_t *pool ));
270
271 LDAP_F( void )
272 ldap_pvt_thread_pool_idle LDAP_P((
273         ldap_pvt_thread_pool_t *pool ));
274
275 LDAP_F( void )
276 ldap_pvt_thread_pool_unidle LDAP_P((
277         ldap_pvt_thread_pool_t *pool ));
278
279 LDAP_F( int )
280 ldap_pvt_thread_pool_pausecheck LDAP_P((
281         ldap_pvt_thread_pool_t *pool ));
282
283 LDAP_F( int )
284 ldap_pvt_thread_pool_pause LDAP_P((
285         ldap_pvt_thread_pool_t *pool ));
286
287 LDAP_F( int )
288 ldap_pvt_thread_pool_resume LDAP_P((
289         ldap_pvt_thread_pool_t *pool ));
290
291 LDAP_F( int )
292 ldap_pvt_thread_pool_destroy LDAP_P((
293         ldap_pvt_thread_pool_t *pool,
294         int run_pending ));
295
296 LDAP_F( int )
297 ldap_pvt_thread_pool_getkey LDAP_P((
298         void *ctx,
299         void *key,
300         void **data,
301         ldap_pvt_thread_pool_keyfree_t **kfree ));
302
303 LDAP_F( int )
304 ldap_pvt_thread_pool_setkey LDAP_P((
305         void *ctx,
306         void *key,
307         void *data,
308         ldap_pvt_thread_pool_keyfree_t *kfree,
309         void **olddatap,
310         ldap_pvt_thread_pool_keyfree_t **oldkfreep ));
311
312 LDAP_F( void )
313 ldap_pvt_thread_pool_purgekey LDAP_P(( void *key ));
314
315 LDAP_F( void *)
316 ldap_pvt_thread_pool_context LDAP_P(( void ));
317
318 LDAP_F( void )
319 ldap_pvt_thread_pool_context_reset LDAP_P(( void *key ));
320
321 LDAP_F( ldap_pvt_thread_t )
322 ldap_pvt_thread_pool_tid LDAP_P(( void *ctx ));
323
324 LDAP_END_DECL
325
326 #define LDAP_PVT_THREAD_H_DONE
327 #endif /* _LDAP_PVT_THREAD_H */