lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* Copyright (C) 2002, 2003 Free Software Foundation, Inc. |
| 2 | This file is part of the GNU C Library. |
| 3 | Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, write to the Free |
| 17 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 18 | 02111-1307 USA. */ |
| 19 | |
| 20 | #include <features.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <dlfcn.h> |
| 23 | |
| 24 | /* psm: keep this before internals.h */ |
| 25 | |
| 26 | #include "internals.h" |
| 27 | |
| 28 | /* Pointers to the libc functions. */ |
| 29 | struct pthread_functions __libc_pthread_functions attribute_hidden; |
| 30 | |
| 31 | |
| 32 | # define FORWARD2(name, rettype, decl, params, defaction) \ |
| 33 | rettype \ |
| 34 | name decl \ |
| 35 | { \ |
| 36 | if (__libc_pthread_functions.ptr_##name == NULL) \ |
| 37 | defaction; \ |
| 38 | \ |
| 39 | return __libc_pthread_functions.ptr_##name params; \ |
| 40 | } |
| 41 | |
| 42 | # define FORWARD(name, decl, params, defretval) \ |
| 43 | FORWARD2 (name, int, decl, params, return defretval) |
| 44 | |
| 45 | FORWARD (pthread_attr_destroy, (pthread_attr_t *attr), (attr), 0) |
| 46 | |
| 47 | FORWARD (pthread_attr_init, (pthread_attr_t *attr), (attr), 0) |
| 48 | |
| 49 | FORWARD (pthread_attr_getdetachstate, |
| 50 | (const pthread_attr_t *attr, int *detachstate), (attr, detachstate), |
| 51 | 0) |
| 52 | FORWARD (pthread_attr_setdetachstate, (pthread_attr_t *attr, int detachstate), |
| 53 | (attr, detachstate), 0) |
| 54 | |
| 55 | FORWARD (pthread_attr_getinheritsched, |
| 56 | (const pthread_attr_t *attr, int *inherit), (attr, inherit), 0) |
| 57 | FORWARD (pthread_attr_setinheritsched, (pthread_attr_t *attr, int inherit), |
| 58 | (attr, inherit), 0) |
| 59 | |
| 60 | FORWARD (pthread_attr_getschedparam, |
| 61 | (const pthread_attr_t *attr, struct sched_param *param), |
| 62 | (attr, param), 0) |
| 63 | FORWARD (pthread_attr_setschedparam, |
| 64 | (pthread_attr_t *attr, const struct sched_param *param), |
| 65 | (attr, param), 0) |
| 66 | |
| 67 | FORWARD (pthread_attr_getschedpolicy, |
| 68 | (const pthread_attr_t *attr, int *policy), (attr, policy), 0) |
| 69 | FORWARD (pthread_attr_setschedpolicy, (pthread_attr_t *attr, int policy), |
| 70 | (attr, policy), 0) |
| 71 | |
| 72 | FORWARD (pthread_attr_getscope, |
| 73 | (const pthread_attr_t *attr, int *scope), (attr, scope), 0) |
| 74 | FORWARD (pthread_attr_setscope, (pthread_attr_t *attr, int scope), |
| 75 | (attr, scope), 0) |
| 76 | |
| 77 | |
| 78 | FORWARD (pthread_condattr_destroy, (pthread_condattr_t *attr), (attr), 0) |
| 79 | FORWARD (pthread_condattr_init, (pthread_condattr_t *attr), (attr), 0) |
| 80 | |
| 81 | |
| 82 | FORWARD (pthread_cond_broadcast, (pthread_cond_t *cond), (cond), 0) |
| 83 | |
| 84 | FORWARD (pthread_cond_destroy, (pthread_cond_t *cond), (cond), 0) |
| 85 | |
| 86 | FORWARD (pthread_cond_init, |
| 87 | (pthread_cond_t *cond, const pthread_condattr_t *cond_attr), |
| 88 | (cond, cond_attr), 0) |
| 89 | |
| 90 | FORWARD (pthread_cond_signal, (pthread_cond_t *cond), (cond), 0) |
| 91 | |
| 92 | FORWARD (pthread_cond_wait, (pthread_cond_t *cond, pthread_mutex_t *mutex), |
| 93 | (cond, mutex), 0) |
| 94 | |
| 95 | FORWARD (pthread_cond_timedwait, |
| 96 | (pthread_cond_t *cond, pthread_mutex_t *mutex, |
| 97 | const struct timespec *abstime), (cond, mutex, abstime), 0) |
| 98 | |
| 99 | |
| 100 | FORWARD (pthread_equal, (pthread_t thread1, pthread_t thread2), |
| 101 | (thread1, thread2), 1) |
| 102 | |
| 103 | |
| 104 | /* Use an alias to avoid warning, as pthread_exit is declared noreturn. */ |
| 105 | FORWARD2 (__pthread_exit, void, (void *retval), (retval), exit (EXIT_SUCCESS)) |
| 106 | strong_alias (__pthread_exit, pthread_exit) |
| 107 | |
| 108 | |
| 109 | FORWARD (pthread_getschedparam, |
| 110 | (pthread_t target_thread, int *policy, struct sched_param *param), |
| 111 | (target_thread, policy, param), 0) |
| 112 | FORWARD (pthread_setschedparam, |
| 113 | (pthread_t target_thread, int policy, |
| 114 | const struct sched_param *param), (target_thread, policy, param), 0) |
| 115 | |
| 116 | |
| 117 | FORWARD (pthread_mutex_destroy, (pthread_mutex_t *mutex), (mutex), 0) |
| 118 | |
| 119 | FORWARD (pthread_mutex_init, |
| 120 | (pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr), |
| 121 | (mutex, mutexattr), 0) |
| 122 | strong_alias(pthread_mutex_init, __pthread_mutex_init) |
| 123 | |
| 124 | FORWARD (pthread_mutex_lock, (pthread_mutex_t *mutex), (mutex), 0) |
| 125 | strong_alias(pthread_mutex_lock, __pthread_mutex_lock) |
| 126 | |
| 127 | FORWARD (pthread_mutex_trylock, (pthread_mutex_t *mutex), (mutex), 0) |
| 128 | strong_alias(pthread_mutex_trylock, __pthread_mutex_trylock) |
| 129 | |
| 130 | FORWARD (pthread_mutex_unlock, (pthread_mutex_t *mutex), (mutex), 0) |
| 131 | strong_alias(pthread_mutex_unlock, __pthread_mutex_unlock) |
| 132 | |
| 133 | FORWARD2 (pthread_self, pthread_t, (void), (), return 0) |
| 134 | |
| 135 | |
| 136 | FORWARD (pthread_setcancelstate, (int state, int *oldstate), (state, oldstate), |
| 137 | 0) |
| 138 | |
| 139 | FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0) |
| 140 | |
| 141 | FORWARD2 (_pthread_cleanup_push, void, (struct _pthread_cleanup_buffer * buffer, void (*routine)(void *), void * arg), (buffer, routine, arg), return) |
| 142 | FORWARD2 (_pthread_cleanup_push_defer, void, (struct _pthread_cleanup_buffer * buffer, void (*routine)(void *), void * arg), (buffer, routine, arg), return) |
| 143 | |
| 144 | FORWARD2 (_pthread_cleanup_pop, void, (struct _pthread_cleanup_buffer * buffer, int execute), (buffer, execute), return) |
| 145 | FORWARD2 (_pthread_cleanup_pop_restore, void, (struct _pthread_cleanup_buffer * buffer, int execute), (buffer, execute), return) |