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/>. */
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) \
37 if (!__libc_pthread_functions_init) { \
40 return PTHFCT_CALL (ptr_##name, params); \
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
),
64 FORWARD (pthread_attr_getschedparam
,
65 (const pthread_attr_t
*attr
, struct sched_param
*param
),
67 FORWARD (pthread_attr_setschedparam
,
68 (pthread_attr_t
*attr
, const struct sched_param
*param
),
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
),
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
),
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
),
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
),
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
),
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();