rpc_thread.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include <stdio.h>
  2. #include <rpc/rpc.h>
  3. #include <assert.h>
  4. #include <libc-lock.h>
  5. #include <libc-tsd.h>
  6. #include <shlib-compat.h>
  7. #include <libc-symbols.h>
  8. /* Variable used in non-threaded applications or for the first thread. */
  9. static struct rpc_thread_variables __libc_tsd_RPC_VARS_mem;
  10. static __thread struct rpc_thread_variables *thread_rpc_vars
  11. attribute_tls_model_ie;
  12. /*
  13. * Task-variable destructor
  14. */
  15. void
  16. __rpc_thread_destroy (void)
  17. {
  18. struct rpc_thread_variables *tvp = thread_rpc_vars;
  19. if (tvp != NULL) {
  20. __rpc_thread_svc_cleanup ();
  21. __rpc_thread_clnt_cleanup ();
  22. __rpc_thread_key_cleanup ();
  23. free (tvp->clnt_perr_buf_s);
  24. free (tvp->clntraw_private_s);
  25. free (tvp->svcraw_private_s);
  26. free (tvp->authdes_cache_s);
  27. free (tvp->authdes_lru_s);
  28. free (tvp->svc_xports_s);
  29. free (tvp->svc_pollfd_s);
  30. if (tvp != &__libc_tsd_RPC_VARS_mem)
  31. free (tvp);
  32. thread_rpc_vars = NULL;
  33. }
  34. }
  35. text_set_element (__libc_subfreeres, __rpc_thread_destroy);
  36. /*
  37. * Initialize RPC multi-threaded operation
  38. */
  39. static void
  40. rpc_thread_multi (void)
  41. {
  42. thread_rpc_vars = &__libc_tsd_RPC_VARS_mem;
  43. }
  44. struct rpc_thread_variables *
  45. __rpc_thread_variables (void)
  46. {
  47. __libc_once_define (static, once);
  48. struct rpc_thread_variables *tvp = thread_rpc_vars;
  49. if (tvp == NULL) {
  50. __libc_once (once, rpc_thread_multi);
  51. tvp = thread_rpc_vars;
  52. if (tvp == NULL) {
  53. tvp = calloc (1, sizeof *tvp);
  54. if (tvp != NULL)
  55. thread_rpc_vars = tvp;
  56. }
  57. }
  58. return tvp;
  59. }
  60. /* Global variables If we're single-threaded, or if this is the first
  61. thread using the variable, use the existing global variable. This
  62. provides backwards compatibility for existing applications which
  63. dynamically link against this code. */
  64. #undef svc_fdset
  65. #undef rpc_createerr
  66. #undef svc_pollfd
  67. #undef svc_max_pollfd
  68. fd_set *
  69. __rpc_thread_svc_fdset (void)
  70. {
  71. struct rpc_thread_variables *tvp;
  72. tvp = __rpc_thread_variables ();
  73. if (tvp == &__libc_tsd_RPC_VARS_mem)
  74. return &svc_fdset;
  75. return &tvp->svc_fdset_s;
  76. }
  77. libc_hidden_nolink_sunrpc (__rpc_thread_svc_fdset, GLIBC_2_2_3)
  78. struct rpc_createerr *
  79. __rpc_thread_createerr (void)
  80. {
  81. struct rpc_thread_variables *tvp;
  82. tvp = __rpc_thread_variables ();
  83. if (tvp == &__libc_tsd_RPC_VARS_mem)
  84. return &rpc_createerr;
  85. return &tvp->rpc_createerr_s;
  86. }
  87. libc_hidden_nolink_sunrpc (__rpc_thread_createerr, GLIBC_2_2_3)
  88. struct pollfd **
  89. __rpc_thread_svc_pollfd (void)
  90. {
  91. struct rpc_thread_variables *tvp;
  92. tvp = __rpc_thread_variables ();
  93. if (tvp == &__libc_tsd_RPC_VARS_mem)
  94. return &svc_pollfd;
  95. return &tvp->svc_pollfd_s;
  96. }
  97. #ifdef EXPORT_RPC_SYMBOLS
  98. libc_hidden_def (__rpc_thread_svc_pollfd)
  99. #else
  100. libc_hidden_nolink_sunrpc (__rpc_thread_svc_pollfd, GLIBC_2_2_3)
  101. #endif
  102. int *
  103. __rpc_thread_svc_max_pollfd (void)
  104. {
  105. struct rpc_thread_variables *tvp;
  106. tvp = __rpc_thread_variables ();
  107. if (tvp == &__libc_tsd_RPC_VARS_mem)
  108. return &svc_max_pollfd;
  109. return &tvp->svc_max_pollfd_s;
  110. }
  111. #ifdef EXPORT_RPC_SYMBOLS
  112. libc_hidden_def (__rpc_thread_svc_max_pollfd)
  113. #else
  114. libc_hidden_nolink_sunrpc (__rpc_thread_svc_max_pollfd, GLIBC_2_2_3)
  115. #endif