test: sync tst-atfork2 with GNU libc
[uclibc-ng.git] / libpthread / nptl / forward.c
blob076d43711ce29761d73ab7241bcca7c5d8ac6489
1 /* Copyright (C) 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <dlfcn.h>
20 #include <pthreadP.h>
21 #include <signal.h>
22 #include <stdlib.h>
24 #include <atomic.h>
25 #include <sysdep.h>
28 /* Pointers to the libc functions. */
29 struct pthread_functions __libc_pthread_functions attribute_hidden;
30 int __libc_pthread_functions_init attribute_hidden;
33 #define FORWARD2(name, rettype, decl, params, defaction) \
34 rettype \
35 name decl \
36 { \
37 if (!__libc_pthread_functions_init) { \
38 defaction; \
39 } else { \
40 return PTHFCT_CALL (ptr_##name, params); \
41 } \
44 #define FORWARD(name, decl, params, defretval) \
45 FORWARD2 (name, int, decl, params, return defretval)
48 FORWARD (pthread_attr_destroy, (pthread_attr_t *attr), (attr), 0)
50 FORWARD (__pthread_attr_init_2_1, (pthread_attr_t *attr), (attr), 0)
51 weak_alias(__pthread_attr_init_2_1, pthread_attr_init)
53 FORWARD (pthread_attr_getdetachstate,
54 (const pthread_attr_t *attr, int *detachstate), (attr, detachstate),
56 FORWARD (pthread_attr_setdetachstate, (pthread_attr_t *attr, int detachstate),
57 (attr, detachstate), 0)
59 FORWARD (pthread_attr_getinheritsched,
60 (const pthread_attr_t *attr, int *inherit), (attr, inherit), 0)
61 FORWARD (pthread_attr_setinheritsched, (pthread_attr_t *attr, int inherit),
62 (attr, inherit), 0)
64 FORWARD (pthread_attr_getschedparam,
65 (const pthread_attr_t *attr, struct sched_param *param),
66 (attr, param), 0)
67 FORWARD (pthread_attr_setschedparam,
68 (pthread_attr_t *attr, const struct sched_param *param),
69 (attr, param), 0)
71 FORWARD (pthread_attr_getschedpolicy,
72 (const pthread_attr_t *attr, int *policy), (attr, policy), 0)
73 FORWARD (pthread_attr_setschedpolicy, (pthread_attr_t *attr, int policy),
74 (attr, policy), 0)
76 FORWARD (pthread_attr_getscope,
77 (const pthread_attr_t *attr, int *scope), (attr, scope), 0)
78 FORWARD (pthread_attr_setscope, (pthread_attr_t *attr, int scope),
79 (attr, scope), 0)
82 FORWARD (pthread_condattr_destroy, (pthread_condattr_t *attr), (attr), 0)
83 FORWARD (pthread_condattr_init, (pthread_condattr_t *attr), (attr), 0)
85 FORWARD (__pthread_cond_broadcast, (pthread_cond_t *cond), (cond), 0)
86 weak_alias(__pthread_cond_broadcast, pthread_cond_broadcast)
88 FORWARD (__pthread_cond_destroy, (pthread_cond_t *cond), (cond), 0)
89 weak_alias(__pthread_cond_destroy, pthread_cond_destroy)
91 FORWARD (__pthread_cond_init,
92 (pthread_cond_t *cond, const pthread_condattr_t *cond_attr),
93 (cond, cond_attr), 0)
94 weak_alias(__pthread_cond_init, pthread_cond_init)
96 FORWARD (__pthread_cond_signal, (pthread_cond_t *cond), (cond), 0)
97 weak_alias(__pthread_cond_signal, pthread_cond_signal)
99 FORWARD (__pthread_cond_wait, (pthread_cond_t *cond, pthread_mutex_t *mutex),
100 (cond, mutex), 0)
101 weak_alias(__pthread_cond_wait, pthread_cond_wait)
103 FORWARD (__pthread_cond_timedwait,
104 (pthread_cond_t *cond, pthread_mutex_t *mutex,
105 const struct timespec *abstime), (cond, mutex, abstime), 0)
106 weak_alias(__pthread_cond_timedwait, pthread_cond_timedwait)
109 FORWARD (pthread_equal, (pthread_t thread1, pthread_t thread2),
110 (thread1, thread2), 1)
113 /* Use an alias to avoid warning, as pthread_exit is declared noreturn. */
114 FORWARD2 (__pthread_exit, void, (void *retval), (retval), exit (EXIT_SUCCESS))
115 strong_alias (__pthread_exit, pthread_exit);
118 FORWARD (pthread_getschedparam,
119 (pthread_t target_thread, int *policy, struct sched_param *param),
120 (target_thread, policy, param), 0)
121 FORWARD (pthread_setschedparam,
122 (pthread_t target_thread, int policy,
123 const struct sched_param *param), (target_thread, policy, param), 0)
126 FORWARD (pthread_mutex_destroy, (pthread_mutex_t *mutex), (mutex), 0)
128 FORWARD (pthread_mutex_init,
129 (pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr),
130 (mutex, mutexattr), 0)
132 FORWARD (pthread_mutex_lock, (pthread_mutex_t *mutex), (mutex), 0)
133 weak_alias (pthread_mutex_lock, __pthread_mutex_lock)
135 FORWARD (pthread_mutex_unlock, (pthread_mutex_t *mutex), (mutex), 0)
136 weak_alias (pthread_mutex_unlock, __pthread_mutex_unlock)
138 FORWARD2 (pthread_self, pthread_t, (void), (), return 0)
141 FORWARD (pthread_setcancelstate, (int state, int *oldstate), (state, oldstate),
144 FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0)
146 #define return /* value is void */
147 FORWARD2(_pthread_cleanup_push_defer,
148 void, (struct _pthread_cleanup_buffer *buffer, void (*routine)(void *), void *arg),
149 (buffer, routine, arg),
150 { buffer->__routine = routine; buffer->__arg = arg; });
152 FORWARD2(_pthread_cleanup_pop_restore,
153 void, (struct _pthread_cleanup_buffer *buffer, int execute),
154 (buffer, execute),
155 if (execute) { buffer->__routine(buffer->__arg); });
157 FORWARD2(__pthread_unwind,
158 void attribute_hidden __attribute ((noreturn)) __cleanup_fct_attribute,
159 (__pthread_unwind_buf_t *buf), (buf), {
160 /* We cannot call abort() here. */
161 INTERNAL_SYSCALL_DECL (err);
162 INTERNAL_SYSCALL (kill, err, 1, SIGKILL);
163 #if __GNUC_PREREQ(4, 5)
164 __builtin_unreachable();
165 #else
166 while(1);
167 #endif
169 #undef return