1 /* ldap_pvt_thread.h - ldap threads header file */
2 /* $OpenLDAP: pkg/ldap/include/ldap_pvt_thread.h,v 1.51.2.10 2008/03/21 00:46:03 hyc Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2008 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
;
32 typedef ldap_int_thread_mutex_t ldap_pvt_thread_mutex_t
;
33 typedef ldap_int_thread_cond_t ldap_pvt_thread_cond_t
;
34 typedef ldap_int_thread_rdwr_t ldap_pvt_thread_rdwr_t
;
36 typedef ldap_int_thread_rmutex_t ldap_pvt_thread_rmutex_t
;
37 typedef ldap_int_thread_key_t ldap_pvt_thread_key_t
;
38 #endif /* !LDAP_PVT_THREAD_H_DONE */
40 #define ldap_pvt_thread_equal ldap_int_thread_equal
43 ldap_pvt_thread_initialize
LDAP_P(( void ));
46 ldap_pvt_thread_destroy
LDAP_P(( void ));
48 LDAP_F( unsigned int )
49 ldap_pvt_thread_sleep
LDAP_P(( unsigned int s
));
52 ldap_pvt_thread_get_concurrency
LDAP_P(( void ));
55 ldap_pvt_thread_set_concurrency
LDAP_P(( int ));
57 #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
58 #define LDAP_PVT_THREAD_CREATE_DETACHED 1
60 #ifndef LDAP_PVT_THREAD_H_DONE
61 #define LDAP_PVT_THREAD_SET_STACK_SIZE
62 #ifndef LDAP_PVT_THREAD_STACK_SIZE
63 /* LARGE stack. Will be twice as large on 64 bit machine. */
64 #define LDAP_PVT_THREAD_STACK_SIZE ( 1 * 1024 * 1024 * sizeof(void *) )
65 /* May be explicitly defined to zero to disable it */
66 #elif LDAP_PVT_THREAD_STACK_SIZE == 0
67 #undef LDAP_PVT_THREAD_SET_STACK_SIZE
69 #endif /* !LDAP_PVT_THREAD_H_DONE */
72 ldap_pvt_thread_create
LDAP_P((
73 ldap_pvt_thread_t
* thread
,
75 void *(*start_routine
)( void * ),
79 ldap_pvt_thread_exit
LDAP_P(( void *retval
));
82 ldap_pvt_thread_join
LDAP_P(( ldap_pvt_thread_t thread
, void **status
));
85 ldap_pvt_thread_kill
LDAP_P(( ldap_pvt_thread_t thread
, int signo
));
88 ldap_pvt_thread_yield
LDAP_P(( void ));
91 ldap_pvt_thread_cond_init
LDAP_P(( ldap_pvt_thread_cond_t
*cond
));
94 ldap_pvt_thread_cond_destroy
LDAP_P(( ldap_pvt_thread_cond_t
*cond
));
97 ldap_pvt_thread_cond_signal
LDAP_P(( ldap_pvt_thread_cond_t
*cond
));
100 ldap_pvt_thread_cond_broadcast
LDAP_P(( ldap_pvt_thread_cond_t
*cond
));
103 ldap_pvt_thread_cond_wait
LDAP_P((
104 ldap_pvt_thread_cond_t
*cond
,
105 ldap_pvt_thread_mutex_t
*mutex
));
108 ldap_pvt_thread_mutex_init
LDAP_P(( ldap_pvt_thread_mutex_t
*mutex
));
111 ldap_pvt_thread_mutex_destroy
LDAP_P(( ldap_pvt_thread_mutex_t
*mutex
));
114 ldap_pvt_thread_mutex_lock
LDAP_P(( ldap_pvt_thread_mutex_t
*mutex
));
117 ldap_pvt_thread_mutex_trylock
LDAP_P(( ldap_pvt_thread_mutex_t
*mutex
));
120 ldap_pvt_thread_mutex_unlock
LDAP_P(( ldap_pvt_thread_mutex_t
*mutex
));
123 ldap_pvt_thread_rmutex_init
LDAP_P(( ldap_pvt_thread_rmutex_t
*rmutex
));
126 ldap_pvt_thread_rmutex_destroy
LDAP_P(( ldap_pvt_thread_rmutex_t
*rmutex
));
129 ldap_pvt_thread_rmutex_lock
LDAP_P(( ldap_pvt_thread_rmutex_t
*rmutex
,
130 ldap_pvt_thread_t owner
));
133 ldap_pvt_thread_rmutex_trylock
LDAP_P(( ldap_pvt_thread_rmutex_t
*rmutex
,
134 ldap_pvt_thread_t owner
));
137 ldap_pvt_thread_rmutex_unlock
LDAP_P(( ldap_pvt_thread_rmutex_t
*rmutex
,
138 ldap_pvt_thread_t owner
));
140 LDAP_F( ldap_pvt_thread_t
)
141 ldap_pvt_thread_self
LDAP_P(( void ));
143 #ifdef LDAP_INT_THREAD_ASSERT_MUTEX_OWNER
144 #define LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER LDAP_INT_THREAD_ASSERT_MUTEX_OWNER
146 #define LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER(mutex) ((void) 0)
150 ldap_pvt_thread_rdwr_init
LDAP_P((ldap_pvt_thread_rdwr_t
*rdwrp
));
153 ldap_pvt_thread_rdwr_destroy
LDAP_P((ldap_pvt_thread_rdwr_t
*rdwrp
));
156 ldap_pvt_thread_rdwr_rlock
LDAP_P((ldap_pvt_thread_rdwr_t
*rdwrp
));
159 ldap_pvt_thread_rdwr_rtrylock
LDAP_P((ldap_pvt_thread_rdwr_t
*rdwrp
));
162 ldap_pvt_thread_rdwr_runlock
LDAP_P((ldap_pvt_thread_rdwr_t
*rdwrp
));
165 ldap_pvt_thread_rdwr_wlock
LDAP_P((ldap_pvt_thread_rdwr_t
*rdwrp
));
168 ldap_pvt_thread_rdwr_wtrylock
LDAP_P((ldap_pvt_thread_rdwr_t
*rdwrp
));
171 ldap_pvt_thread_rdwr_wunlock
LDAP_P((ldap_pvt_thread_rdwr_t
*rdwrp
));
174 ldap_pvt_thread_key_create
LDAP_P((ldap_pvt_thread_key_t
*keyp
));
177 ldap_pvt_thread_key_destroy
LDAP_P((ldap_pvt_thread_key_t key
));
180 ldap_pvt_thread_key_setdata
LDAP_P((ldap_pvt_thread_key_t key
, void *data
));
183 ldap_pvt_thread_key_getdata
LDAP_P((ldap_pvt_thread_key_t key
, void **data
));
187 ldap_pvt_thread_rdwr_readers
LDAP_P((ldap_pvt_thread_rdwr_t
*rdwrp
));
190 ldap_pvt_thread_rdwr_writers
LDAP_P((ldap_pvt_thread_rdwr_t
*rdwrp
));
193 ldap_pvt_thread_rdwr_active
LDAP_P((ldap_pvt_thread_rdwr_t
*rdwrp
));
194 #endif /* LDAP_DEBUG */
196 #define LDAP_PVT_THREAD_EINVAL EINVAL
197 #define LDAP_PVT_THREAD_EBUSY EINVAL
199 #ifndef LDAP_PVT_THREAD_H_DONE
200 typedef ldap_int_thread_pool_t ldap_pvt_thread_pool_t
;
202 typedef void * (ldap_pvt_thread_start_t
) LDAP_P((void *ctx
, void *arg
));
203 typedef void (ldap_pvt_thread_pool_keyfree_t
) LDAP_P((void *key
, void *data
));
204 #endif /* !LDAP_PVT_THREAD_H_DONE */
207 ldap_pvt_thread_pool_init
LDAP_P((
208 ldap_pvt_thread_pool_t
*pool_out
,
213 ldap_pvt_thread_pool_submit
LDAP_P((
214 ldap_pvt_thread_pool_t
*pool
,
215 ldap_pvt_thread_start_t
*start
,
219 ldap_pvt_thread_pool_maxthreads
LDAP_P((
220 ldap_pvt_thread_pool_t
*pool
,
223 #ifndef LDAP_PVT_THREAD_H_DONE
225 LDAP_PVT_THREAD_POOL_PARAM_UNKNOWN
= -1,
226 LDAP_PVT_THREAD_POOL_PARAM_MAX
,
227 LDAP_PVT_THREAD_POOL_PARAM_MAX_PENDING
,
228 LDAP_PVT_THREAD_POOL_PARAM_OPEN
,
229 LDAP_PVT_THREAD_POOL_PARAM_STARTING
,
230 LDAP_PVT_THREAD_POOL_PARAM_ACTIVE
,
231 LDAP_PVT_THREAD_POOL_PARAM_PAUSING
,
232 LDAP_PVT_THREAD_POOL_PARAM_PENDING
,
233 LDAP_PVT_THREAD_POOL_PARAM_BACKLOAD
,
234 LDAP_PVT_THREAD_POOL_PARAM_ACTIVE_MAX
,
235 LDAP_PVT_THREAD_POOL_PARAM_PENDING_MAX
,
236 LDAP_PVT_THREAD_POOL_PARAM_BACKLOAD_MAX
,
237 LDAP_PVT_THREAD_POOL_PARAM_STATE
238 } ldap_pvt_thread_pool_param_t
;
239 #endif /* !LDAP_PVT_THREAD_H_DONE */
242 ldap_pvt_thread_pool_query
LDAP_P((
243 ldap_pvt_thread_pool_t
*pool
,
244 ldap_pvt_thread_pool_param_t param
, void *value
));
247 ldap_pvt_thread_pool_pausing
LDAP_P((
248 ldap_pvt_thread_pool_t
*pool
));
251 ldap_pvt_thread_pool_backload
LDAP_P((
252 ldap_pvt_thread_pool_t
*pool
));
255 ldap_pvt_thread_pool_pausecheck
LDAP_P((
256 ldap_pvt_thread_pool_t
*pool
));
259 ldap_pvt_thread_pool_pause
LDAP_P((
260 ldap_pvt_thread_pool_t
*pool
));
263 ldap_pvt_thread_pool_resume
LDAP_P((
264 ldap_pvt_thread_pool_t
*pool
));
267 ldap_pvt_thread_pool_destroy
LDAP_P((
268 ldap_pvt_thread_pool_t
*pool
,
272 ldap_pvt_thread_pool_getkey
LDAP_P((
276 ldap_pvt_thread_pool_keyfree_t
**kfree
));
279 ldap_pvt_thread_pool_setkey
LDAP_P((
283 ldap_pvt_thread_pool_keyfree_t
*kfree
,
285 ldap_pvt_thread_pool_keyfree_t
**oldkfreep
));
288 ldap_pvt_thread_pool_purgekey
LDAP_P(( void *key
));
291 ldap_pvt_thread_pool_context
LDAP_P(( void ));
294 ldap_pvt_thread_pool_context_reset
LDAP_P(( void *key
));
296 LDAP_F( ldap_pvt_thread_t
)
297 ldap_pvt_thread_pool_tid
LDAP_P(( void *ctx
));
301 #define LDAP_PVT_THREAD_H_DONE
302 #endif /* _LDAP_PVT_THREAD_H */