threads.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* $OpenLDAP$ */
  2. /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  3. *
  4. * Copyright 1998-2024 The OpenLDAP Foundation.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted only as authorized by the OpenLDAP
  9. * Public License.
  10. *
  11. * A copy of this license is available in file LICENSE in the
  12. * top-level directory of the distribution or, alternatively, at
  13. * <http://www.OpenLDAP.org/license.html>.
  14. */
  15. #include "portable.h"
  16. #include <stdio.h>
  17. #include <ac/stdarg.h>
  18. #include <ac/stdlib.h>
  19. #include <ac/string.h>
  20. #include <ac/unistd.h>
  21. #include "ldap-int.h"
  22. #ifdef LDAP_R_COMPILE
  23. #include "ldap_pvt_thread.h" /* Get the thread interface */
  24. #include "ldap_thr_debug.h" /* May redirect thread initialize/destroy calls */
  25. /*
  26. * Common LDAP thread routines
  27. * see thr_*.c for implementation specific routines
  28. * see rdwr.c for generic reader/writer lock implementation
  29. * see tpool.c for generic thread pool implementation
  30. */
  31. int ldap_pvt_thread_initialize( void )
  32. {
  33. int rc;
  34. static int init = 0;
  35. ldap_pvt_thread_t tid;
  36. /* we only get one shot at this */
  37. if( init++ ) return -1;
  38. rc = ldap_int_thread_initialize();
  39. if( rc ) return rc;
  40. #ifndef LDAP_THREAD_HAVE_TPOOL
  41. rc = ldap_int_thread_pool_startup();
  42. if( rc ) return rc;
  43. #endif
  44. /* kludge to pull symbol definitions in */
  45. tid = ldap_pvt_thread_self();
  46. return 0;
  47. }
  48. int ldap_pvt_thread_destroy( void )
  49. {
  50. #ifndef LDAP_THREAD_HAVE_TPOOL
  51. (void) ldap_int_thread_pool_shutdown();
  52. #endif
  53. return ldap_int_thread_destroy();
  54. }
  55. /*
  56. * Default implementations of some LDAP thread routines
  57. */
  58. #define LDAP_THREAD_IMPLEMENTATION
  59. #include "ldap_thr_debug.h" /* May rename the symbols defined below */
  60. #ifndef LDAP_THREAD_HAVE_GETCONCURRENCY
  61. int
  62. ldap_pvt_thread_get_concurrency ( void )
  63. {
  64. return 1;
  65. }
  66. #endif
  67. #ifndef LDAP_THREAD_HAVE_SETCONCURRENCY
  68. int
  69. ldap_pvt_thread_set_concurrency ( int concurrency )
  70. {
  71. return 1;
  72. }
  73. #endif
  74. #ifndef LDAP_THREAD_HAVE_SLEEP
  75. /*
  76. * Here we assume we have fully preemptive threads and that sleep()
  77. * does the right thing.
  78. */
  79. unsigned int
  80. ldap_pvt_thread_sleep(
  81. unsigned int interval
  82. )
  83. {
  84. sleep( interval );
  85. return 0;
  86. }
  87. #endif
  88. #endif /* LDAP_R_COMPILE */