ldap_pvt_thread.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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-2024 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. #ifndef _LDAP_PVT_THREAD_H
  17. #define _LDAP_PVT_THREAD_H /* libldap/ldap_thr_debug.h #undefines this */
  18. #include "ldap_cdefs.h"
  19. #include "ldap_int_thread.h"
  20. LDAP_BEGIN_DECL
  21. #ifndef LDAP_PVT_THREAD_H_DONE
  22. typedef ldap_int_thread_t ldap_pvt_thread_t;
  23. #ifdef LDAP_THREAD_DEBUG_WRAP
  24. typedef ldap_debug_thread_mutex_t ldap_pvt_thread_mutex_t;
  25. typedef ldap_debug_thread_cond_t ldap_pvt_thread_cond_t;
  26. typedef ldap_debug_thread_rdwr_t ldap_pvt_thread_rdwr_t;
  27. #define LDAP_PVT_MUTEX_FIRSTCREATE LDAP_DEBUG_MUTEX_FIRSTCREATE
  28. #define LDAP_PVT_MUTEX_NULL LDAP_DEBUG_MUTEX_NULL
  29. #else
  30. typedef ldap_int_thread_mutex_t ldap_pvt_thread_mutex_t;
  31. typedef ldap_int_thread_cond_t ldap_pvt_thread_cond_t;
  32. typedef ldap_int_thread_rdwr_t ldap_pvt_thread_rdwr_t;
  33. #define LDAP_PVT_MUTEX_FIRSTCREATE LDAP_INT_MUTEX_FIRSTCREATE
  34. #define LDAP_PVT_MUTEX_NULL LDAP_INT_MUTEX_NULL
  35. #endif
  36. typedef ldap_int_thread_key_t ldap_pvt_thread_key_t;
  37. #endif /* !LDAP_PVT_THREAD_H_DONE */
  38. #define ldap_pvt_thread_equal ldap_int_thread_equal
  39. LDAP_F( int )
  40. ldap_pvt_thread_initialize LDAP_P(( void ));
  41. LDAP_F( int )
  42. ldap_pvt_thread_destroy LDAP_P(( void ));
  43. LDAP_F( unsigned int )
  44. ldap_pvt_thread_sleep LDAP_P(( unsigned int s ));
  45. LDAP_F( int )
  46. ldap_pvt_thread_get_concurrency LDAP_P(( void ));
  47. LDAP_F( int )
  48. ldap_pvt_thread_set_concurrency LDAP_P(( int ));
  49. #define LDAP_PVT_THREAD_CREATE_JOINABLE 0
  50. #define LDAP_PVT_THREAD_CREATE_DETACHED 1
  51. #ifndef LDAP_PVT_THREAD_H_DONE
  52. #define LDAP_PVT_THREAD_SET_STACK_SIZE
  53. /* The size may be explicitly #defined to zero to disable it. */
  54. #if defined( LDAP_PVT_THREAD_STACK_SIZE ) && LDAP_PVT_THREAD_STACK_SIZE == 0
  55. # undef LDAP_PVT_THREAD_SET_STACK_SIZE
  56. #elif !defined( LDAP_PVT_THREAD_STACK_SIZE )
  57. /* LARGE stack. Will be twice as large on 64 bit machine. */
  58. # define LDAP_PVT_THREAD_STACK_SIZE ( 1 * 1024 * 1024 * sizeof(void *) )
  59. #endif
  60. #endif /* !LDAP_PVT_THREAD_H_DONE */
  61. LDAP_F( int )
  62. ldap_pvt_thread_create LDAP_P((
  63. ldap_pvt_thread_t * thread,
  64. int detach,
  65. void *(*start_routine)( void * ),
  66. void *arg));
  67. LDAP_F( void )
  68. ldap_pvt_thread_exit LDAP_P(( void *retval ));
  69. LDAP_F( int )
  70. ldap_pvt_thread_join LDAP_P(( ldap_pvt_thread_t thread, void **status ));
  71. LDAP_F( int )
  72. ldap_pvt_thread_kill LDAP_P(( ldap_pvt_thread_t thread, int signo ));
  73. LDAP_F( int )
  74. ldap_pvt_thread_yield LDAP_P(( void ));
  75. LDAP_F( int )
  76. ldap_pvt_thread_cond_init LDAP_P(( ldap_pvt_thread_cond_t *cond ));
  77. LDAP_F( int )
  78. ldap_pvt_thread_cond_destroy LDAP_P(( ldap_pvt_thread_cond_t *cond ));
  79. LDAP_F( int )
  80. ldap_pvt_thread_cond_signal LDAP_P(( ldap_pvt_thread_cond_t *cond ));
  81. LDAP_F( int )
  82. ldap_pvt_thread_cond_broadcast LDAP_P(( ldap_pvt_thread_cond_t *cond ));
  83. LDAP_F( int )
  84. ldap_pvt_thread_cond_wait LDAP_P((
  85. ldap_pvt_thread_cond_t *cond,
  86. ldap_pvt_thread_mutex_t *mutex ));
  87. LDAP_F( int )
  88. ldap_pvt_thread_mutex_init LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
  89. LDAP_F( int )
  90. ldap_pvt_thread_mutex_recursive_init LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
  91. LDAP_F( int )
  92. ldap_pvt_thread_mutex_destroy LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
  93. LDAP_F( int )
  94. ldap_pvt_thread_mutex_lock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
  95. LDAP_F( int )
  96. ldap_pvt_thread_mutex_trylock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
  97. LDAP_F( int )
  98. ldap_pvt_thread_mutex_unlock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
  99. LDAP_F( ldap_pvt_thread_t )
  100. ldap_pvt_thread_self LDAP_P(( void ));
  101. #ifdef LDAP_INT_THREAD_ASSERT_MUTEX_OWNER
  102. #define LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER LDAP_INT_THREAD_ASSERT_MUTEX_OWNER
  103. #else
  104. #define LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER(mutex) ((void) 0)
  105. #endif
  106. LDAP_F( int )
  107. ldap_pvt_thread_rdwr_init LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
  108. LDAP_F( int )
  109. ldap_pvt_thread_rdwr_destroy LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
  110. LDAP_F( int )
  111. ldap_pvt_thread_rdwr_rlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
  112. LDAP_F( int )
  113. ldap_pvt_thread_rdwr_rtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
  114. LDAP_F( int )
  115. ldap_pvt_thread_rdwr_runlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
  116. LDAP_F( int )
  117. ldap_pvt_thread_rdwr_wlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
  118. LDAP_F( int )
  119. ldap_pvt_thread_rdwr_wtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
  120. LDAP_F( int )
  121. ldap_pvt_thread_rdwr_wunlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
  122. LDAP_F( int )
  123. ldap_pvt_thread_key_create LDAP_P((ldap_pvt_thread_key_t *keyp));
  124. LDAP_F( int )
  125. ldap_pvt_thread_key_destroy LDAP_P((ldap_pvt_thread_key_t key));
  126. LDAP_F( int )
  127. ldap_pvt_thread_key_setdata LDAP_P((ldap_pvt_thread_key_t key, void *data));
  128. LDAP_F( int )
  129. ldap_pvt_thread_key_getdata LDAP_P((ldap_pvt_thread_key_t key, void **data));
  130. #ifdef LDAP_DEBUG
  131. LDAP_F( int )
  132. ldap_pvt_thread_rdwr_readers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
  133. LDAP_F( int )
  134. ldap_pvt_thread_rdwr_writers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
  135. LDAP_F( int )
  136. ldap_pvt_thread_rdwr_active LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
  137. #endif /* LDAP_DEBUG */
  138. #define LDAP_PVT_THREAD_EINVAL EINVAL
  139. #define LDAP_PVT_THREAD_EBUSY EINVAL
  140. #ifndef LDAP_PVT_THREAD_H_DONE
  141. typedef ldap_int_thread_pool_t ldap_pvt_thread_pool_t;
  142. typedef void * (ldap_pvt_thread_start_t) LDAP_P((void *ctx, void *arg));
  143. typedef int (ldap_pvt_thread_walk_t) LDAP_P((ldap_pvt_thread_start_t *start, void *start_arg, void *arg));
  144. typedef void (ldap_pvt_thread_pool_keyfree_t) LDAP_P((void *key, void *data));
  145. #endif /* !LDAP_PVT_THREAD_H_DONE */
  146. LDAP_F( int )
  147. ldap_pvt_thread_pool_init LDAP_P((
  148. ldap_pvt_thread_pool_t *pool_out,
  149. int max_threads,
  150. int max_pending ));
  151. LDAP_F( int )
  152. ldap_pvt_thread_pool_init_q LDAP_P((
  153. ldap_pvt_thread_pool_t *pool_out,
  154. int max_threads,
  155. int max_pending,
  156. int num_qs ));
  157. LDAP_F( int )
  158. ldap_pvt_thread_pool_submit LDAP_P((
  159. ldap_pvt_thread_pool_t *pool,
  160. ldap_pvt_thread_start_t *start,
  161. void *arg ));
  162. LDAP_F( int )
  163. ldap_pvt_thread_pool_submit2 LDAP_P((
  164. ldap_pvt_thread_pool_t *pool,
  165. ldap_pvt_thread_start_t *start,
  166. void *arg,
  167. void **cookie ));
  168. LDAP_F( int )
  169. ldap_pvt_thread_pool_retract LDAP_P((
  170. void *cookie ));
  171. LDAP_F( int )
  172. ldap_pvt_thread_pool_walk LDAP_P((
  173. ldap_pvt_thread_pool_t *pool,
  174. ldap_pvt_thread_start_t *start,
  175. ldap_pvt_thread_walk_t *cb,
  176. void *arg ));
  177. LDAP_F( int )
  178. ldap_pvt_thread_pool_maxthreads LDAP_P((
  179. ldap_pvt_thread_pool_t *pool,
  180. int max_threads ));
  181. LDAP_F( int )
  182. ldap_pvt_thread_pool_queues LDAP_P((
  183. ldap_pvt_thread_pool_t *pool,
  184. int numqs ));
  185. #ifndef LDAP_PVT_THREAD_H_DONE
  186. typedef enum {
  187. LDAP_PVT_THREAD_POOL_PARAM_UNKNOWN = -1,
  188. LDAP_PVT_THREAD_POOL_PARAM_MAX,
  189. LDAP_PVT_THREAD_POOL_PARAM_MAX_PENDING,
  190. LDAP_PVT_THREAD_POOL_PARAM_OPEN,
  191. LDAP_PVT_THREAD_POOL_PARAM_STARTING,
  192. LDAP_PVT_THREAD_POOL_PARAM_ACTIVE,
  193. LDAP_PVT_THREAD_POOL_PARAM_PAUSING,
  194. LDAP_PVT_THREAD_POOL_PARAM_PENDING,
  195. LDAP_PVT_THREAD_POOL_PARAM_BACKLOAD,
  196. LDAP_PVT_THREAD_POOL_PARAM_ACTIVE_MAX,
  197. LDAP_PVT_THREAD_POOL_PARAM_PENDING_MAX,
  198. LDAP_PVT_THREAD_POOL_PARAM_BACKLOAD_MAX,
  199. LDAP_PVT_THREAD_POOL_PARAM_STATE,
  200. LDAP_PVT_THREAD_POOL_PARAM_PAUSED
  201. } ldap_pvt_thread_pool_param_t;
  202. #endif /* !LDAP_PVT_THREAD_H_DONE */
  203. LDAP_F( int )
  204. ldap_pvt_thread_pool_query LDAP_P((
  205. ldap_pvt_thread_pool_t *pool,
  206. ldap_pvt_thread_pool_param_t param, void *value ));
  207. LDAP_F( int )
  208. ldap_pvt_thread_pool_pausing LDAP_P((
  209. ldap_pvt_thread_pool_t *pool ));
  210. LDAP_F( int )
  211. ldap_pvt_thread_pool_backload LDAP_P((
  212. ldap_pvt_thread_pool_t *pool ));
  213. LDAP_F( void )
  214. ldap_pvt_thread_pool_idle LDAP_P((
  215. ldap_pvt_thread_pool_t *pool ));
  216. LDAP_F( void )
  217. ldap_pvt_thread_pool_unidle LDAP_P((
  218. ldap_pvt_thread_pool_t *pool ));
  219. LDAP_F( int )
  220. ldap_pvt_thread_pool_pausequery LDAP_P((
  221. ldap_pvt_thread_pool_t *pool ));
  222. LDAP_F( int )
  223. ldap_pvt_thread_pool_pausewait LDAP_P((
  224. ldap_pvt_thread_pool_t *pool ));
  225. LDAP_F( int )
  226. ldap_pvt_thread_pool_pausecheck_native LDAP_P((
  227. ldap_pvt_thread_pool_t *pool ));
  228. LDAP_F( int )
  229. ldap_pvt_thread_pool_pause LDAP_P((
  230. ldap_pvt_thread_pool_t *pool ));
  231. LDAP_F( int )
  232. ldap_pvt_thread_pool_resume LDAP_P((
  233. ldap_pvt_thread_pool_t *pool ));
  234. LDAP_F( int )
  235. ldap_pvt_thread_pool_destroy LDAP_P((
  236. ldap_pvt_thread_pool_t *pool,
  237. int run_pending ));
  238. LDAP_F( int )
  239. ldap_pvt_thread_pool_close LDAP_P((
  240. ldap_pvt_thread_pool_t *pool,
  241. int run_pending ));
  242. LDAP_F( int )
  243. ldap_pvt_thread_pool_free LDAP_P((
  244. ldap_pvt_thread_pool_t *pool ));
  245. LDAP_F( int )
  246. ldap_pvt_thread_pool_getkey LDAP_P((
  247. void *ctx,
  248. void *key,
  249. void **data,
  250. ldap_pvt_thread_pool_keyfree_t **kfree ));
  251. LDAP_F( int )
  252. ldap_pvt_thread_pool_setkey LDAP_P((
  253. void *ctx,
  254. void *key,
  255. void *data,
  256. ldap_pvt_thread_pool_keyfree_t *kfree,
  257. void **olddatap,
  258. ldap_pvt_thread_pool_keyfree_t **oldkfreep ));
  259. LDAP_F( void )
  260. ldap_pvt_thread_pool_purgekey LDAP_P(( void *key ));
  261. LDAP_F( void *)
  262. ldap_pvt_thread_pool_context LDAP_P(( void ));
  263. LDAP_F( void )
  264. ldap_pvt_thread_pool_context_reset LDAP_P(( void *key ));
  265. LDAP_F( ldap_pvt_thread_t )
  266. ldap_pvt_thread_pool_tid LDAP_P(( void *ctx ));
  267. LDAP_END_DECL
  268. #define LDAP_PVT_THREAD_H_DONE
  269. #endif /* _LDAP_PVT_THREAD_H */