ldap_thr_debug.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* ldap_thr_debug.h - preprocessor magic for LDAP_THREAD_DEBUG */
  2. /* $OpenLDAP$ */
  3. /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  4. *
  5. * Copyright 2005-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 the file LICENSE in the
  13. * top-level directory of the distribution or, alternatively, at
  14. * <http://www.OpenLDAP.org/license.html>.
  15. */
  16. #ifdef LDAP_THREAD_DEBUG
  17. /*
  18. * libldap .c files should include this file after ldap_pvt_thread.h,
  19. * with the appropriate LDAP_THREAD*_IMPLEMENTATION macro(s) defined.
  20. */
  21. #ifndef _LDAP_PVT_THREAD_H
  22. #error "ldap_pvt_thread.h" must be included before "ldap_thr_debug.h"
  23. #endif
  24. /*
  25. * Support for thr_debug.c:
  26. *
  27. * thr_debug.c defines ldap_pvt_thread_* as wrappers around the real
  28. * ldap_pvt_thread_* implementation, which this file renames to
  29. * ldap_int_thread_*.
  30. *
  31. * Implementation:
  32. *
  33. * This file re#defines selected ldap_pvt_thread_* names to
  34. * ldap_int_thread_*, which will be used from wrappers in thr_debug.c.
  35. * Two ldap_int_*() calls are redirected to call ldap_debug_*(): These
  36. * are wrappers around the originals, whose definitions are not renamed.
  37. * This file then #includes ldap_pvt_thread.h to declare the renamed
  38. * functions/types. If #included from thr_debug.c it finally #undefines
  39. * the macros again.
  40. *
  41. * include/ldap_pvt_thread.h declares the typedefs ldap_pvt_thread*_t as
  42. * either wrapper types ldap_debug_thread*_t or their usual definitions
  43. * ldap_int_thread*_t, depending on the LDAP_THREAD_DEBUG_WRAP option.
  44. * When defining the underlying implementation, this file then redirects
  45. * the type names back to the original ldap_int_thread*_t types.
  46. * include/ldap_<int,pvt>_thread.h also do some thr_debug magic.
  47. *
  48. * So,
  49. * libldap/<not thr_debug.c> thus define ldap_int_thread_*() instead
  50. * of ldap_pvt_thread_*().
  51. * thr_debug.c defines the ldap_pvt_*() and ldap_debug_*() functions.
  52. * In thread.c, ldap_pvt_thread_<initialize/destroy>() will call
  53. * ldap_debug_thread_*() instead of ldap_int_thread_*().
  54. * In tpool.c, ldap_int_thread_pool_shutdown() has explicit thr_debug.c
  55. * support which treats ldap_pvt_thread_pool_destroy() the same way.
  56. */
  57. #ifndef LDAP_THREAD_IMPLEMENTATION /* for first part of threads.c */
  58. #define ldap_int_thread_initialize ldap_debug_thread_initialize
  59. #define ldap_int_thread_destroy ldap_debug_thread_destroy
  60. #else /* LDAP_THREAD_IMPLEMENTATION -- for thr_*.c and end of threads.c */
  61. #undef ldap_int_thread_initialize
  62. #undef ldap_int_thread_destroy
  63. #ifdef LDAP_THREAD_DEBUG_WRAP /* see ldap_pvt_thread.h */
  64. #define ldap_pvt_thread_mutex_t ldap_int_thread_mutex_t
  65. #define ldap_pvt_thread_cond_t ldap_int_thread_cond_t
  66. #endif
  67. #define ldap_pvt_thread_sleep ldap_int_thread_sleep
  68. #define ldap_pvt_thread_get_concurrency ldap_int_thread_get_concurrency
  69. #define ldap_pvt_thread_set_concurrency ldap_int_thread_set_concurrency
  70. #define ldap_pvt_thread_create ldap_int_thread_create
  71. #define ldap_pvt_thread_exit ldap_int_thread_exit
  72. #define ldap_pvt_thread_join ldap_int_thread_join
  73. #define ldap_pvt_thread_kill ldap_int_thread_kill
  74. #define ldap_pvt_thread_yield ldap_int_thread_yield
  75. #define ldap_pvt_thread_cond_init ldap_int_thread_cond_init
  76. #define ldap_pvt_thread_cond_destroy ldap_int_thread_cond_destroy
  77. #define ldap_pvt_thread_cond_signal ldap_int_thread_cond_signal
  78. #define ldap_pvt_thread_cond_broadcast ldap_int_thread_cond_broadcast
  79. #define ldap_pvt_thread_cond_wait ldap_int_thread_cond_wait
  80. #define ldap_pvt_thread_mutex_init ldap_int_thread_mutex_init
  81. #define ldap_pvt_thread_mutex_recursive_init ldap_int_thread_mutex_recursive_init
  82. #define ldap_pvt_thread_mutex_destroy ldap_int_thread_mutex_destroy
  83. #define ldap_pvt_thread_mutex_lock ldap_int_thread_mutex_lock
  84. #define ldap_pvt_thread_mutex_trylock ldap_int_thread_mutex_trylock
  85. #define ldap_pvt_thread_mutex_unlock ldap_int_thread_mutex_unlock
  86. #define ldap_pvt_thread_self ldap_int_thread_self
  87. #endif /* LDAP_THREAD_IMPLEMENTATION */
  88. #ifdef LDAP_THREAD_RDWR_IMPLEMENTATION /* rdwr.c, thr_debug.c */
  89. #ifdef LDAP_THREAD_DEBUG_WRAP /* see ldap_pvt_thread.h */
  90. #define ldap_pvt_thread_rdwr_t ldap_int_thread_rdwr_t
  91. #endif
  92. #define ldap_pvt_thread_rdwr_init ldap_int_thread_rdwr_init
  93. #define ldap_pvt_thread_rdwr_destroy ldap_int_thread_rdwr_destroy
  94. #define ldap_pvt_thread_rdwr_rlock ldap_int_thread_rdwr_rlock
  95. #define ldap_pvt_thread_rdwr_rtrylock ldap_int_thread_rdwr_rtrylock
  96. #define ldap_pvt_thread_rdwr_runlock ldap_int_thread_rdwr_runlock
  97. #define ldap_pvt_thread_rdwr_wlock ldap_int_thread_rdwr_wlock
  98. #define ldap_pvt_thread_rdwr_wtrylock ldap_int_thread_rdwr_wtrylock
  99. #define ldap_pvt_thread_rdwr_wunlock ldap_int_thread_rdwr_wunlock
  100. #define ldap_pvt_thread_rdwr_readers ldap_int_thread_rdwr_readers
  101. #define ldap_pvt_thread_rdwr_writers ldap_int_thread_rdwr_writers
  102. #define ldap_pvt_thread_rdwr_active ldap_int_thread_rdwr_active
  103. #endif /* LDAP_THREAD_RDWR_IMPLEMENTATION */
  104. #ifdef LDAP_THREAD_POOL_IMPLEMENTATION /* tpool.c, thr_debug.c */
  105. #ifdef LDAP_THREAD_DEBUG_WRAP /* see ldap_pvt_thread.h */
  106. #define ldap_pvt_thread_pool_t ldap_int_thread_pool_t
  107. #endif
  108. #define ldap_pvt_thread_pool_init ldap_int_thread_pool_init
  109. #define ldap_pvt_thread_pool_submit ldap_int_thread_pool_submit
  110. #define ldap_pvt_thread_pool_maxthreads ldap_int_thread_pool_maxthreads
  111. #define ldap_pvt_thread_pool_backload ldap_int_thread_pool_backload
  112. #define ldap_pvt_thread_pool_pause ldap_int_thread_pool_pause
  113. #define ldap_pvt_thread_pool_resume ldap_int_thread_pool_resume
  114. #define ldap_pvt_thread_pool_destroy ldap_int_thread_pool_destroy
  115. #define ldap_pvt_thread_pool_close ldap_int_thread_pool_close
  116. #define ldap_pvt_thread_pool_free ldap_int_thread_pool_free
  117. #define ldap_pvt_thread_pool_getkey ldap_int_thread_pool_getkey
  118. #define ldap_pvt_thread_pool_setkey ldap_int_thread_pool_setkey
  119. #define ldap_pvt_thread_pool_purgekey ldap_int_thread_pool_purgekey
  120. #define ldap_pvt_thread_pool_context ldap_int_thread_pool_context
  121. #define ldap_pvt_thread_pool_context_reset ldap_int_thread_pool_context_reset
  122. #endif /* LDAP_THREAD_POOL_IMPLEMENTATION */
  123. #undef _LDAP_PVT_THREAD_H
  124. #include "ldap_pvt_thread.h"
  125. #ifdef LDAP_THREAD_POOL_IMPLEMENTATION /* tpool.c */
  126. /*
  127. * tpool.c:ldap_int_thread_pool_shutdown() needs this. Could not
  128. * use it for ldap_pvt_thread.h above because of its use of LDAP_P().
  129. */
  130. #undef ldap_pvt_thread_pool_destroy
  131. #define ldap_pvt_thread_pool_destroy(p,r) ldap_int_thread_pool_destroy(p,r)
  132. #endif
  133. #ifdef LDAP_THREAD_DEBUG_IMPLEMENTATION /* thr_debug.c */
  134. #undef ldap_pvt_thread_mutex_t
  135. #undef ldap_pvt_thread_cond_t
  136. #undef ldap_pvt_thread_sleep
  137. #undef ldap_pvt_thread_get_concurrency
  138. #undef ldap_pvt_thread_set_concurrency
  139. #undef ldap_pvt_thread_create
  140. #undef ldap_pvt_thread_exit
  141. #undef ldap_pvt_thread_join
  142. #undef ldap_pvt_thread_kill
  143. #undef ldap_pvt_thread_yield
  144. #undef ldap_pvt_thread_cond_init
  145. #undef ldap_pvt_thread_cond_destroy
  146. #undef ldap_pvt_thread_cond_signal
  147. #undef ldap_pvt_thread_cond_broadcast
  148. #undef ldap_pvt_thread_cond_wait
  149. #undef ldap_pvt_thread_mutex_init
  150. #undef ldap_pvt_thread_mutex_recursive_init
  151. #undef ldap_pvt_thread_mutex_destroy
  152. #undef ldap_pvt_thread_mutex_lock
  153. #undef ldap_pvt_thread_mutex_trylock
  154. #undef ldap_pvt_thread_mutex_unlock
  155. #undef ldap_pvt_thread_self
  156. /* LDAP_THREAD_RDWR_IMPLEMENTATION: */
  157. #undef ldap_pvt_thread_rdwr_t
  158. #undef ldap_pvt_thread_rdwr_init
  159. #undef ldap_pvt_thread_rdwr_destroy
  160. #undef ldap_pvt_thread_rdwr_rlock
  161. #undef ldap_pvt_thread_rdwr_rtrylock
  162. #undef ldap_pvt_thread_rdwr_runlock
  163. #undef ldap_pvt_thread_rdwr_wlock
  164. #undef ldap_pvt_thread_rdwr_wtrylock
  165. #undef ldap_pvt_thread_rdwr_wunlock
  166. #undef ldap_pvt_thread_rdwr_readers
  167. #undef ldap_pvt_thread_rdwr_writers
  168. #undef ldap_pvt_thread_rdwr_active
  169. /* LDAP_THREAD_POOL_IMPLEMENTATION: */
  170. #undef ldap_pvt_thread_pool_t
  171. #undef ldap_pvt_thread_pool_init
  172. #undef ldap_pvt_thread_pool_submit
  173. #undef ldap_pvt_thread_pool_maxthreads
  174. #undef ldap_pvt_thread_pool_backload
  175. #undef ldap_pvt_thread_pool_pause
  176. #undef ldap_pvt_thread_pool_resume
  177. #undef ldap_pvt_thread_pool_destroy
  178. #undef ldap_pvt_thread_pool_close
  179. #undef ldap_pvt_thread_pool_free
  180. #undef ldap_pvt_thread_pool_getkey
  181. #undef ldap_pvt_thread_pool_setkey
  182. #undef ldap_pvt_thread_pool_purgekey
  183. #undef ldap_pvt_thread_pool_context
  184. #undef ldap_pvt_thread_pool_context_reset
  185. #endif /* LDAP_THREAD_DEBUG_IMPLEMENTATION */
  186. #endif /* LDAP_THREAD_DEBUG */