rpc_thread.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #define __FORCE_GLIBC
  2. #include <features.h>
  3. #include <stdio.h>
  4. #include <assert.h>
  5. #include "rpc_private.h"
  6. #ifdef __UCLIBC_HAS_THREADS__
  7. #include <bits/libc-tsd.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 struct rpc_thread_variables *__libc_tsd_RPC_VARS_data =
  11. &__libc_tsd_RPC_VARS_mem;
  12. /*
  13. * Task-variable destructor
  14. */
  15. void
  16. __rpc_thread_destroy (void)
  17. {
  18. struct rpc_thread_variables *tvp = __rpc_thread_variables();
  19. if (tvp != NULL && tvp != &__libc_tsd_RPC_VARS_mem) {
  20. __rpc_thread_svc_cleanup ();
  21. __rpc_thread_clnt_cleanup ();
  22. //__rpc_thread_key_cleanup ();
  23. free (tvp->authnone_private_s);
  24. free (tvp->clnt_perr_buf_s);
  25. free (tvp->clntraw_private_s);
  26. free (tvp->svcraw_private_s);
  27. free (tvp->authdes_cache_s);
  28. free (tvp->authdes_lru_s);
  29. free (tvp);
  30. }
  31. }
  32. /*
  33. * Initialize RPC multi-threaded operation
  34. */
  35. static void
  36. rpc_thread_multi (void)
  37. {
  38. __libc_tsd_set (RPC_VARS, &__libc_tsd_RPC_VARS_mem);
  39. }
  40. struct rpc_thread_variables attribute_hidden *
  41. __rpc_thread_variables (void)
  42. {
  43. __libc_once_define (static, once);
  44. struct rpc_thread_variables *tvp;
  45. tvp = __libc_tsd_get (RPC_VARS);
  46. if (tvp == NULL) {
  47. __libc_once (once, rpc_thread_multi);
  48. tvp = __libc_tsd_get (RPC_VARS);
  49. if (tvp == NULL) {
  50. tvp = calloc (1, sizeof *tvp);
  51. if (tvp != NULL)
  52. __libc_tsd_set (RPC_VARS, tvp);
  53. else
  54. tvp = __libc_tsd_RPC_VARS_data;
  55. }
  56. }
  57. return tvp;
  58. }
  59. /* Global variables If we're single-threaded, or if this is the first
  60. thread using the variable, use the existing global variable. This
  61. provides backwards compatability for existing applications which
  62. dynamically link against this code. */
  63. #undef svc_fdset
  64. #undef rpc_createerr
  65. #undef svc_pollfd
  66. #undef svc_max_pollfd
  67. fd_set attribute_hidden *
  68. __rpc_thread_svc_fdset_internal (void)
  69. {
  70. struct rpc_thread_variables *tvp;
  71. tvp = __rpc_thread_variables ();
  72. if (tvp == &__libc_tsd_RPC_VARS_mem)
  73. return &svc_fdset;
  74. return &tvp->svc_fdset_s;
  75. }
  76. strong_alias(__rpc_thread_svc_fdset_internal,__rpc_thread_svc_fdset)
  77. struct rpc_createerr attribute_hidden *
  78. __rpc_thread_createerr_internal (void)
  79. {
  80. struct rpc_thread_variables *tvp;
  81. tvp = __rpc_thread_variables ();
  82. if (tvp == &__libc_tsd_RPC_VARS_mem)
  83. return &rpc_createerr;
  84. return &tvp->rpc_createerr_s;
  85. }
  86. #undef __rpc_thread_createerr
  87. strong_alias(__rpc_thread_createerr_internal,__rpc_thread_createerr)
  88. struct pollfd attribute_hidden **
  89. __rpc_thread_svc_pollfd_internal (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. strong_alias(__rpc_thread_svc_pollfd_internal,__rpc_thread_svc_pollfd)
  98. int attribute_hidden *
  99. __rpc_thread_svc_max_pollfd_internal (void)
  100. {
  101. struct rpc_thread_variables *tvp;
  102. tvp = __rpc_thread_variables ();
  103. if (tvp == &__libc_tsd_RPC_VARS_mem)
  104. return &svc_max_pollfd;
  105. return &tvp->svc_max_pollfd_s;
  106. }
  107. strong_alias(__rpc_thread_svc_max_pollfd_internal,__rpc_thread_svc_max_pollfd)
  108. #else
  109. #undef svc_fdset
  110. #undef rpc_createerr
  111. #undef svc_pollfd
  112. #undef svc_max_pollfd
  113. fd_set attribute_hidden * __rpc_thread_svc_fdset_internal (void)
  114. {
  115. extern fd_set svc_fdset;
  116. return &(svc_fdset);
  117. }
  118. strong_alias(__rpc_thread_svc_fdset_internal,__rpc_thread_svc_fdset)
  119. struct rpc_createerr attribute_hidden * __rpc_thread_createerr_internal (void)
  120. {
  121. extern struct rpc_createerr rpc_createerr;
  122. return &(rpc_createerr);
  123. }
  124. #undef __rpc_thread_createerr
  125. strong_alias(__rpc_thread_createerr_internal,__rpc_thread_createerr)
  126. struct pollfd attribute_hidden ** __rpc_thread_svc_pollfd_internal (void)
  127. {
  128. extern struct pollfd *svc_pollfd;
  129. return &(svc_pollfd);
  130. }
  131. strong_alias(__rpc_thread_svc_pollfd_internal,__rpc_thread_svc_pollfd)
  132. int attribute_hidden * __rpc_thread_svc_max_pollfd_internal (void)
  133. {
  134. extern int svc_max_pollfd;
  135. return &(svc_max_pollfd);
  136. }
  137. strong_alias(__rpc_thread_svc_max_pollfd_internal,__rpc_thread_svc_max_pollfd)
  138. #endif /* __UCLIBC_HAS_THREADS__ */