forward.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <dlfcn.h>
  17. #include <pthreadP.h>
  18. #include <signal.h>
  19. #include <stdlib.h>
  20. #include <atomic.h>
  21. #include <sysdep.h>
  22. /* Pointers to the libc functions. */
  23. struct pthread_functions __libc_pthread_functions attribute_hidden;
  24. #define FORWARD2(name, rettype, decl, params, defaction) \
  25. rettype \
  26. name decl \
  27. { \
  28. if (__libc_pthread_functions.ptr_##name == NULL) \
  29. defaction; \
  30. \
  31. return __libc_pthread_functions.ptr_##name params; \
  32. }
  33. #define FORWARD(name, decl, params, defretval) \
  34. FORWARD2 (name, int, decl, params, return defretval)
  35. FORWARD (pthread_attr_destroy, (pthread_attr_t *attr), (attr), 0)
  36. FORWARD (__pthread_attr_init_2_1, (pthread_attr_t *attr), (attr), 0)
  37. weak_alias(__pthread_attr_init_2_1, pthread_attr_init)
  38. FORWARD (pthread_attr_getdetachstate,
  39. (const pthread_attr_t *attr, int *detachstate), (attr, detachstate),
  40. 0)
  41. FORWARD (pthread_attr_setdetachstate, (pthread_attr_t *attr, int detachstate),
  42. (attr, detachstate), 0)
  43. FORWARD (pthread_attr_getinheritsched,
  44. (const pthread_attr_t *attr, int *inherit), (attr, inherit), 0)
  45. FORWARD (pthread_attr_setinheritsched, (pthread_attr_t *attr, int inherit),
  46. (attr, inherit), 0)
  47. FORWARD (pthread_attr_getschedparam,
  48. (const pthread_attr_t *attr, struct sched_param *param),
  49. (attr, param), 0)
  50. FORWARD (pthread_attr_setschedparam,
  51. (pthread_attr_t *attr, const struct sched_param *param),
  52. (attr, param), 0)
  53. FORWARD (pthread_attr_getschedpolicy,
  54. (const pthread_attr_t *attr, int *policy), (attr, policy), 0)
  55. FORWARD (pthread_attr_setschedpolicy, (pthread_attr_t *attr, int policy),
  56. (attr, policy), 0)
  57. FORWARD (pthread_attr_getscope,
  58. (const pthread_attr_t *attr, int *scope), (attr, scope), 0)
  59. FORWARD (pthread_attr_setscope, (pthread_attr_t *attr, int scope),
  60. (attr, scope), 0)
  61. FORWARD (pthread_condattr_destroy, (pthread_condattr_t *attr), (attr), 0)
  62. FORWARD (pthread_condattr_init, (pthread_condattr_t *attr), (attr), 0)
  63. FORWARD (__pthread_cond_broadcast, (pthread_cond_t *cond), (cond), 0)
  64. weak_alias(__pthread_cond_broadcast, pthread_cond_broadcast)
  65. FORWARD (__pthread_cond_destroy, (pthread_cond_t *cond), (cond), 0)
  66. weak_alias(__pthread_cond_destroy, pthread_cond_destroy)
  67. FORWARD (__pthread_cond_init,
  68. (pthread_cond_t *cond, const pthread_condattr_t *cond_attr),
  69. (cond, cond_attr), 0)
  70. weak_alias(__pthread_cond_init, pthread_cond_init)
  71. FORWARD (__pthread_cond_signal, (pthread_cond_t *cond), (cond), 0)
  72. weak_alias(__pthread_cond_signal, pthread_cond_signal)
  73. FORWARD (__pthread_cond_wait, (pthread_cond_t *cond, pthread_mutex_t *mutex),
  74. (cond, mutex), 0)
  75. weak_alias(__pthread_cond_wait, pthread_cond_wait)
  76. FORWARD (__pthread_cond_timedwait,
  77. (pthread_cond_t *cond, pthread_mutex_t *mutex,
  78. const struct timespec *abstime), (cond, mutex, abstime), 0)
  79. weak_alias(__pthread_cond_timedwait, pthread_cond_timedwait)
  80. FORWARD (pthread_equal, (pthread_t thread1, pthread_t thread2),
  81. (thread1, thread2), 1)
  82. /* Use an alias to avoid warning, as pthread_exit is declared noreturn. */
  83. FORWARD2 (__pthread_exit, void, (void *retval), (retval), exit (EXIT_SUCCESS))
  84. strong_alias (__pthread_exit, pthread_exit);
  85. FORWARD (pthread_getschedparam,
  86. (pthread_t target_thread, int *policy, struct sched_param *param),
  87. (target_thread, policy, param), 0)
  88. FORWARD (pthread_setschedparam,
  89. (pthread_t target_thread, int policy,
  90. const struct sched_param *param), (target_thread, policy, param), 0)
  91. FORWARD (pthread_mutex_destroy, (pthread_mutex_t *mutex), (mutex), 0)
  92. libc_hidden_proto(pthread_mutex_init)
  93. FORWARD (pthread_mutex_init,
  94. (pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr),
  95. (mutex, mutexattr), 0)
  96. strong_alias(pthread_mutex_init, __pthread_mutex_init)
  97. libc_hidden_def(pthread_mutex_init)
  98. libc_hidden_proto(pthread_mutex_trylock)
  99. FORWARD (pthread_mutex_trylock, (pthread_mutex_t *mutex), (mutex), 0)
  100. strong_alias(pthread_mutex_trylock, __pthread_mutex_trylock)
  101. libc_hidden_def(pthread_mutex_trylock)
  102. libc_hidden_proto(pthread_mutex_lock)
  103. FORWARD (pthread_mutex_lock, (pthread_mutex_t *mutex), (mutex), 0)
  104. strong_alias(pthread_mutex_lock, __pthread_mutex_lock)
  105. libc_hidden_def(pthread_mutex_lock)
  106. libc_hidden_proto(pthread_mutex_unlock)
  107. FORWARD (pthread_mutex_unlock, (pthread_mutex_t *mutex), (mutex), 0)
  108. strong_alias(pthread_mutex_unlock, __pthread_mutex_unlock)
  109. libc_hidden_def(pthread_mutex_unlock)
  110. FORWARD (pthread_mutexattr_init, (pthread_mutexattr_t *attr), (attr), 0)
  111. FORWARD (pthread_mutexattr_destroy, (pthread_mutexattr_t *attr), (attr), 0)
  112. FORWARD (pthread_mutexattr_settype, (pthread_mutexattr_t *attr, int kind),
  113. (attr, kind), 0)
  114. FORWARD2 (pthread_self, pthread_t, (void), (), return 0)
  115. FORWARD (pthread_setcancelstate, (int state, int *oldstate), (state, oldstate),
  116. 0)
  117. FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0)
  118. #define return /* value is void */
  119. FORWARD2(__pthread_unwind,
  120. void attribute_hidden __attribute ((noreturn)) __cleanup_fct_attribute,
  121. (__pthread_unwind_buf_t *buf), (buf), {
  122. /* We cannot call abort() here. */
  123. INTERNAL_SYSCALL_DECL (err);
  124. INTERNAL_SYSCALL (kill, err, 1, SIGKILL);
  125. })
  126. #undef return