]> git.sur5r.net Git - openldap/blob - include/ldap_pvt_thread.h
ITS#8100 fixes for delta-syncrepl with empty accesslog
[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-2017 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_submit LDAP_P((
218         ldap_pvt_thread_pool_t *pool,
219         ldap_pvt_thread_start_t *start,
220         void *arg ));
221
222 LDAP_F( int )
223 ldap_pvt_thread_pool_retract LDAP_P((
224         ldap_pvt_thread_pool_t *pool,
225         ldap_pvt_thread_start_t *start,
226         void *arg ));
227
228 LDAP_F( int )
229 ldap_pvt_thread_pool_maxthreads LDAP_P((
230         ldap_pvt_thread_pool_t *pool,
231         int max_threads ));
232
233 #ifndef LDAP_PVT_THREAD_H_DONE
234 typedef enum {
235         LDAP_PVT_THREAD_POOL_PARAM_UNKNOWN = -1,
236         LDAP_PVT_THREAD_POOL_PARAM_MAX,
237         LDAP_PVT_THREAD_POOL_PARAM_MAX_PENDING,
238         LDAP_PVT_THREAD_POOL_PARAM_OPEN,
239         LDAP_PVT_THREAD_POOL_PARAM_STARTING,
240         LDAP_PVT_THREAD_POOL_PARAM_ACTIVE,
241         LDAP_PVT_THREAD_POOL_PARAM_PAUSING,
242         LDAP_PVT_THREAD_POOL_PARAM_PENDING,
243         LDAP_PVT_THREAD_POOL_PARAM_BACKLOAD,
244         LDAP_PVT_THREAD_POOL_PARAM_ACTIVE_MAX,
245         LDAP_PVT_THREAD_POOL_PARAM_PENDING_MAX,
246         LDAP_PVT_THREAD_POOL_PARAM_BACKLOAD_MAX,
247         LDAP_PVT_THREAD_POOL_PARAM_STATE
248 } ldap_pvt_thread_pool_param_t;
249 #endif /* !LDAP_PVT_THREAD_H_DONE */
250
251 LDAP_F( int )
252 ldap_pvt_thread_pool_query LDAP_P((
253         ldap_pvt_thread_pool_t *pool,
254         ldap_pvt_thread_pool_param_t param, void *value ));
255
256 LDAP_F( int )
257 ldap_pvt_thread_pool_pausing LDAP_P((
258         ldap_pvt_thread_pool_t *pool ));
259
260 LDAP_F( int )
261 ldap_pvt_thread_pool_backload LDAP_P((
262         ldap_pvt_thread_pool_t *pool ));
263
264 LDAP_F( void )
265 ldap_pvt_thread_pool_idle LDAP_P((
266         ldap_pvt_thread_pool_t *pool ));
267
268 LDAP_F( void )
269 ldap_pvt_thread_pool_unidle LDAP_P((
270         ldap_pvt_thread_pool_t *pool ));
271
272 LDAP_F( int )
273 ldap_pvt_thread_pool_pausecheck LDAP_P((
274         ldap_pvt_thread_pool_t *pool ));
275
276 LDAP_F( int )
277 ldap_pvt_thread_pool_pause LDAP_P((
278         ldap_pvt_thread_pool_t *pool ));
279
280 LDAP_F( int )
281 ldap_pvt_thread_pool_resume LDAP_P((
282         ldap_pvt_thread_pool_t *pool ));
283
284 LDAP_F( int )
285 ldap_pvt_thread_pool_destroy LDAP_P((
286         ldap_pvt_thread_pool_t *pool,
287         int run_pending ));
288
289 LDAP_F( int )
290 ldap_pvt_thread_pool_getkey LDAP_P((
291         void *ctx,
292         void *key,
293         void **data,
294         ldap_pvt_thread_pool_keyfree_t **kfree ));
295
296 LDAP_F( int )
297 ldap_pvt_thread_pool_setkey LDAP_P((
298         void *ctx,
299         void *key,
300         void *data,
301         ldap_pvt_thread_pool_keyfree_t *kfree,
302         void **olddatap,
303         ldap_pvt_thread_pool_keyfree_t **oldkfreep ));
304
305 LDAP_F( void )
306 ldap_pvt_thread_pool_purgekey LDAP_P(( void *key ));
307
308 LDAP_F( void *)
309 ldap_pvt_thread_pool_context LDAP_P(( void ));
310
311 LDAP_F( void )
312 ldap_pvt_thread_pool_context_reset LDAP_P(( void *key ));
313
314 LDAP_F( ldap_pvt_thread_t )
315 ldap_pvt_thread_pool_tid LDAP_P(( void *ctx ));
316
317 LDAP_END_DECL
318
319 #define LDAP_PVT_THREAD_H_DONE
320 #endif /* _LDAP_PVT_THREAD_H */