blob: 7878334ac95666743c7d667ce294236a66a15793 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* 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.
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 <dlfcn.h>
21#include <pthreadP.h>
22#include <signal.h>
23#include <stdlib.h>
24
25#include <atomic.h>
26#include <sysdep.h>
27
28
29/* Pointers to the libc functions. */
30struct pthread_functions __libc_pthread_functions attribute_hidden;
31int __libc_pthread_functions_init attribute_hidden;
32
33
34#define FORWARD2(name, rettype, decl, params, defaction) \
35rettype \
36name decl \
37{ \
38 if (!__libc_pthread_functions_init) { \
39 defaction; \
40 } else { \
41 return PTHFCT_CALL (ptr_##name, params); \
42 } \
43}
44
45#define FORWARD(name, decl, params, defretval) \
46 FORWARD2 (name, int, decl, params, return defretval)
47
48
49FORWARD (pthread_attr_destroy, (pthread_attr_t *attr), (attr), 0)
50
51FORWARD (__pthread_attr_init_2_1, (pthread_attr_t *attr), (attr), 0)
52weak_alias(__pthread_attr_init_2_1, pthread_attr_init)
53
54FORWARD (pthread_attr_getdetachstate,
55 (const pthread_attr_t *attr, int *detachstate), (attr, detachstate),
56 0)
57FORWARD (pthread_attr_setdetachstate, (pthread_attr_t *attr, int detachstate),
58 (attr, detachstate), 0)
59
60FORWARD (pthread_attr_getinheritsched,
61 (const pthread_attr_t *attr, int *inherit), (attr, inherit), 0)
62FORWARD (pthread_attr_setinheritsched, (pthread_attr_t *attr, int inherit),
63 (attr, inherit), 0)
64
65FORWARD (pthread_attr_getschedparam,
66 (const pthread_attr_t *attr, struct sched_param *param),
67 (attr, param), 0)
68FORWARD (pthread_attr_setschedparam,
69 (pthread_attr_t *attr, const struct sched_param *param),
70 (attr, param), 0)
71
72FORWARD (pthread_attr_getschedpolicy,
73 (const pthread_attr_t *attr, int *policy), (attr, policy), 0)
74FORWARD (pthread_attr_setschedpolicy, (pthread_attr_t *attr, int policy),
75 (attr, policy), 0)
76
77FORWARD (pthread_attr_getscope,
78 (const pthread_attr_t *attr, int *scope), (attr, scope), 0)
79FORWARD (pthread_attr_setscope, (pthread_attr_t *attr, int scope),
80 (attr, scope), 0)
81
82
83FORWARD (pthread_condattr_destroy, (pthread_condattr_t *attr), (attr), 0)
84FORWARD (pthread_condattr_init, (pthread_condattr_t *attr), (attr), 0)
85
86FORWARD (__pthread_cond_broadcast, (pthread_cond_t *cond), (cond), 0)
87weak_alias(__pthread_cond_broadcast, pthread_cond_broadcast)
88
89FORWARD (__pthread_cond_destroy, (pthread_cond_t *cond), (cond), 0)
90weak_alias(__pthread_cond_destroy, pthread_cond_destroy)
91
92FORWARD (__pthread_cond_init,
93 (pthread_cond_t *cond, const pthread_condattr_t *cond_attr),
94 (cond, cond_attr), 0)
95weak_alias(__pthread_cond_init, pthread_cond_init)
96
97FORWARD (__pthread_cond_signal, (pthread_cond_t *cond), (cond), 0)
98weak_alias(__pthread_cond_signal, pthread_cond_signal)
99
100FORWARD (__pthread_cond_wait, (pthread_cond_t *cond, pthread_mutex_t *mutex),
101 (cond, mutex), 0)
102weak_alias(__pthread_cond_wait, pthread_cond_wait)
103
104FORWARD (__pthread_cond_timedwait,
105 (pthread_cond_t *cond, pthread_mutex_t *mutex,
106 const struct timespec *abstime), (cond, mutex, abstime), 0)
107weak_alias(__pthread_cond_timedwait, pthread_cond_timedwait)
108
109
110FORWARD (pthread_equal, (pthread_t thread1, pthread_t thread2),
111 (thread1, thread2), 1)
112
113
114/* Use an alias to avoid warning, as pthread_exit is declared noreturn. */
115FORWARD2 (__pthread_exit, void, (void *retval), (retval), exit (EXIT_SUCCESS))
116strong_alias (__pthread_exit, pthread_exit);
117
118
119FORWARD (pthread_getschedparam,
120 (pthread_t target_thread, int *policy, struct sched_param *param),
121 (target_thread, policy, param), 0)
122FORWARD (pthread_setschedparam,
123 (pthread_t target_thread, int policy,
124 const struct sched_param *param), (target_thread, policy, param), 0)
125
126
127FORWARD (pthread_mutex_destroy, (pthread_mutex_t *mutex), (mutex), 0)
128
129FORWARD (pthread_mutex_init,
130 (pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr),
131 (mutex, mutexattr), 0)
132
133FORWARD (pthread_mutex_lock, (pthread_mutex_t *mutex), (mutex), 0)
134weak_alias (pthread_mutex_lock, __pthread_mutex_lock)
135
136FORWARD (pthread_mutex_unlock, (pthread_mutex_t *mutex), (mutex), 0)
137weak_alias (pthread_mutex_unlock, __pthread_mutex_unlock)
138
139FORWARD2 (pthread_self, pthread_t, (void), (), return 0)
140
141
142FORWARD (pthread_setcancelstate, (int state, int *oldstate), (state, oldstate),
143 0)
144
145FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0)
146
147#define return /* value is void */
148FORWARD2(_pthread_cleanup_push_defer,
149 void, (struct _pthread_cleanup_buffer *buffer, void (*routine)(void *), void *arg),
150 (buffer, routine, arg),
151 { buffer->__routine = routine; buffer->__arg = arg; });
152
153FORWARD2(_pthread_cleanup_pop_restore,
154 void, (struct _pthread_cleanup_buffer *buffer, int execute),
155 (buffer, execute),
156 if (execute) { buffer->__routine(buffer->__arg); });
157
158FORWARD2(__pthread_unwind,
159 void attribute_hidden __attribute ((noreturn)) __cleanup_fct_attribute,
160 (__pthread_unwind_buf_t *buf), (buf), {
161 /* We cannot call abort() here. */
162 INTERNAL_SYSCALL_DECL (err);
163 INTERNAL_SYSCALL (kill, err, 1, SIGKILL);
164 })
165#undef return