1 /* ldap_pvt_thread.h - ldap threads header file */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2017 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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>.
17 #ifndef _LDAP_PVT_THREAD_H
18 #define _LDAP_PVT_THREAD_H /* libldap_r/ldap_thr_debug.h #undefines this */
20 #include "ldap_cdefs.h"
21 #include "ldap_int_thread.h"
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
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
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 */
44 #define ldap_pvt_thread_equal ldap_int_thread_equal
47 ldap_pvt_thread_initialize LDAP_P(( void ));
50 ldap_pvt_thread_destroy LDAP_P(( void ));
52 LDAP_F( unsigned int )
53 ldap_pvt_thread_sleep LDAP_P(( unsigned int s ));
56 ldap_pvt_thread_get_concurrency LDAP_P(( void ));
59 ldap_pvt_thread_set_concurrency LDAP_P(( int ));
61 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
62 #define LDAP_PVT_THREAD_CREATE_DETACHED 1
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 *) )
73 #endif /* !LDAP_PVT_THREAD_H_DONE */
76 ldap_pvt_thread_create LDAP_P((
77 ldap_pvt_thread_t * thread,
79 void *(*start_routine)( void * ),
83 ldap_pvt_thread_exit LDAP_P(( void *retval ));
86 ldap_pvt_thread_join LDAP_P(( ldap_pvt_thread_t thread, void **status ));
89 ldap_pvt_thread_kill LDAP_P(( ldap_pvt_thread_t thread, int signo ));
92 ldap_pvt_thread_yield LDAP_P(( void ));
95 ldap_pvt_thread_cond_init LDAP_P(( ldap_pvt_thread_cond_t *cond ));
98 ldap_pvt_thread_cond_destroy LDAP_P(( ldap_pvt_thread_cond_t *cond ));
101 ldap_pvt_thread_cond_signal LDAP_P(( ldap_pvt_thread_cond_t *cond ));
104 ldap_pvt_thread_cond_broadcast LDAP_P(( ldap_pvt_thread_cond_t *cond ));
107 ldap_pvt_thread_cond_wait LDAP_P((
108 ldap_pvt_thread_cond_t *cond,
109 ldap_pvt_thread_mutex_t *mutex ));
112 ldap_pvt_thread_mutex_init LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
115 ldap_pvt_thread_mutex_destroy LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
118 ldap_pvt_thread_mutex_lock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
121 ldap_pvt_thread_mutex_trylock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
124 ldap_pvt_thread_mutex_unlock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
127 ldap_pvt_thread_rmutex_init LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex ));
130 ldap_pvt_thread_rmutex_destroy LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex ));
133 ldap_pvt_thread_rmutex_lock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex,
134 ldap_pvt_thread_t owner));
137 ldap_pvt_thread_rmutex_trylock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex,
138 ldap_pvt_thread_t owner));
141 ldap_pvt_thread_rmutex_unlock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex,
142 ldap_pvt_thread_t owner));
144 LDAP_F( ldap_pvt_thread_t )
145 ldap_pvt_thread_self LDAP_P(( void ));
147 #ifdef LDAP_INT_THREAD_ASSERT_MUTEX_OWNER
148 #define LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER LDAP_INT_THREAD_ASSERT_MUTEX_OWNER
150 #define LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER(mutex) ((void) 0)
154 ldap_pvt_thread_rdwr_init LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
157 ldap_pvt_thread_rdwr_destroy LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
160 ldap_pvt_thread_rdwr_rlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
163 ldap_pvt_thread_rdwr_rtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
166 ldap_pvt_thread_rdwr_runlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
169 ldap_pvt_thread_rdwr_wlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
172 ldap_pvt_thread_rdwr_wtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
175 ldap_pvt_thread_rdwr_wunlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
178 ldap_pvt_thread_key_create LDAP_P((ldap_pvt_thread_key_t *keyp));
181 ldap_pvt_thread_key_destroy LDAP_P((ldap_pvt_thread_key_t key));
184 ldap_pvt_thread_key_setdata LDAP_P((ldap_pvt_thread_key_t key, void *data));
187 ldap_pvt_thread_key_getdata LDAP_P((ldap_pvt_thread_key_t key, void **data));
191 ldap_pvt_thread_rdwr_readers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
194 ldap_pvt_thread_rdwr_writers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
197 ldap_pvt_thread_rdwr_active LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
198 #endif /* LDAP_DEBUG */
200 #define LDAP_PVT_THREAD_EINVAL EINVAL
201 #define LDAP_PVT_THREAD_EBUSY EINVAL
203 #ifndef LDAP_PVT_THREAD_H_DONE
204 typedef ldap_int_thread_pool_t ldap_pvt_thread_pool_t;
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 */
211 ldap_pvt_thread_pool_init LDAP_P((
212 ldap_pvt_thread_pool_t *pool_out,
217 ldap_pvt_thread_pool_submit LDAP_P((
218 ldap_pvt_thread_pool_t *pool,
219 ldap_pvt_thread_start_t *start,
223 ldap_pvt_thread_pool_retract LDAP_P((
224 ldap_pvt_thread_pool_t *pool,
225 ldap_pvt_thread_start_t *start,
229 ldap_pvt_thread_pool_maxthreads LDAP_P((
230 ldap_pvt_thread_pool_t *pool,
233 #ifndef LDAP_PVT_THREAD_H_DONE
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 */
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 ));
257 ldap_pvt_thread_pool_pausing LDAP_P((
258 ldap_pvt_thread_pool_t *pool ));
261 ldap_pvt_thread_pool_backload LDAP_P((
262 ldap_pvt_thread_pool_t *pool ));
265 ldap_pvt_thread_pool_idle LDAP_P((
266 ldap_pvt_thread_pool_t *pool ));
269 ldap_pvt_thread_pool_unidle LDAP_P((
270 ldap_pvt_thread_pool_t *pool ));
273 ldap_pvt_thread_pool_pausecheck LDAP_P((
274 ldap_pvt_thread_pool_t *pool ));
277 ldap_pvt_thread_pool_pause LDAP_P((
278 ldap_pvt_thread_pool_t *pool ));
281 ldap_pvt_thread_pool_resume LDAP_P((
282 ldap_pvt_thread_pool_t *pool ));
285 ldap_pvt_thread_pool_destroy LDAP_P((
286 ldap_pvt_thread_pool_t *pool,
290 ldap_pvt_thread_pool_getkey LDAP_P((
294 ldap_pvt_thread_pool_keyfree_t **kfree ));
297 ldap_pvt_thread_pool_setkey LDAP_P((
301 ldap_pvt_thread_pool_keyfree_t *kfree,
303 ldap_pvt_thread_pool_keyfree_t **oldkfreep ));
306 ldap_pvt_thread_pool_purgekey LDAP_P(( void *key ));
309 ldap_pvt_thread_pool_context LDAP_P(( void ));
312 ldap_pvt_thread_pool_context_reset LDAP_P(( void *key ));
314 LDAP_F( ldap_pvt_thread_t )
315 ldap_pvt_thread_pool_tid LDAP_P(( void *ctx ));
319 #define LDAP_PVT_THREAD_H_DONE
320 #endif /* _LDAP_PVT_THREAD_H */