Update build-many-glibcs.py for binutils ia64 obsoletion.
[glibc.git] / sysdeps / htl / libc-lockP.h
blob4ba3930a13aeee48a03bc68ff3e09756e6251ff4
1 /* Private libc-internal interface for mutex locks.
2 Copyright (C) 2015-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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 License as
7 published by the Free Software Foundation; either version 2.1 of the
8 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; see the file COPYING.LIB. If
17 not, see <https://www.gnu.org/licenses/>. */
19 #ifndef _BITS_LIBC_LOCKP_H
20 #define _BITS_LIBC_LOCKP_H 1
22 #include <pthread.h>
23 #include <pthread-functions.h>
25 /* Type for key to thread-specific data. */
26 typedef pthread_key_t __libc_key_t;
28 /* If we check for a weakly referenced symbol and then perform a
29 normal jump to it te code generated for some platforms in case of
30 PIC is unnecessarily slow. What would happen is that the function
31 is first referenced as data and then it is called indirectly
32 through the PLT. We can make this a direct jump. */
33 #ifdef __PIC__
34 # define __libc_maybe_call(FUNC, ARGS, ELSE) \
35 (__extension__ ({ __typeof (FUNC) *_fn = (FUNC); \
36 _fn != NULL ? (*_fn) ARGS : ELSE; }))
37 #else
38 # define __libc_maybe_call(FUNC, ARGS, ELSE) \
39 (FUNC != NULL ? FUNC ARGS : ELSE)
40 #endif
42 /* Call thread functions through the function pointer table. */
43 #if defined SHARED && IS_IN (libc)
44 # define PTFAVAIL(NAME) __libc_pthread_functions_init
45 # define __libc_ptf_call(FUNC, ARGS, ELSE) \
46 (__libc_pthread_functions_init ? PTHFCT_CALL (ptr_##FUNC, ARGS) : ELSE)
47 # define __libc_ptf_call_always(FUNC, ARGS) \
48 PTHFCT_CALL (ptr_##FUNC, ARGS)
49 #elif IS_IN (libpthread)
50 # define PTFAVAIL(NAME) 1
51 # define __libc_ptf_call(FUNC, ARGS, ELSE) \
52 FUNC ARGS
53 # define __libc_ptf_call_always(FUNC, ARGS) \
54 FUNC ARGS
55 #else
56 # define PTFAVAIL(NAME) (NAME != NULL)
57 # define __libc_ptf_call(FUNC, ARGS, ELSE) \
58 __libc_maybe_call (FUNC, ARGS, ELSE)
59 # define __libc_ptf_call_always(FUNC, ARGS) \
60 FUNC ARGS
61 #endif
63 /* Create thread-specific key. */
64 #define __libc_key_create(KEY, DESTRUCTOR) \
65 __libc_ptf_call (__pthread_key_create, (KEY, DESTRUCTOR), 1)
67 /* Get thread-specific data. */
68 #define __libc_getspecific(KEY) \
69 __libc_ptf_call (__pthread_getspecific, (KEY), NULL)
71 /* Set thread-specific data. */
72 #define __libc_setspecific(KEY, VALUE) \
73 __libc_ptf_call (__pthread_setspecific, (KEY, VALUE), 0)
76 /* Functions that are used by this file and are internal to the GNU C
77 library. */
79 extern int __pthread_mutex_init (pthread_mutex_t *__mutex,
80 const pthread_mutexattr_t *__mutex_attr);
82 extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
84 extern int __pthread_mutex_trylock (pthread_mutex_t *__mutex);
86 extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
88 extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex);
90 extern int __pthread_mutexattr_init (pthread_mutexattr_t *__attr);
92 extern int __pthread_mutexattr_destroy (pthread_mutexattr_t *__attr);
94 extern int __pthread_mutexattr_settype (pthread_mutexattr_t *__attr,
95 int __kind);
97 extern int __pthread_rwlock_init (pthread_rwlock_t *__rwlock,
98 const pthread_rwlockattr_t *__attr);
100 extern int __pthread_rwlock_destroy (pthread_rwlock_t *__rwlock);
102 extern int __pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock);
104 extern int __pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock);
106 extern int __pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock);
108 extern int __pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock);
110 extern int __pthread_rwlock_unlock (pthread_rwlock_t *__rwlock);
112 extern int __pthread_key_create (pthread_key_t *__key,
113 void (*__destr_function) (void *));
115 extern int __pthread_key_delete (pthread_key_t __key);
117 extern int __pthread_setspecific (pthread_key_t __key,
118 const void *__pointer);
120 extern void *__pthread_getspecific (pthread_key_t __key);
122 extern int __pthread_once (pthread_once_t *__once_control,
123 void (*__init_routine) (void));
125 extern int __pthread_atfork (void (*__prepare) (void),
126 void (*__parent) (void),
127 void (*__child) (void));
131 /* Make the pthread functions weak so that we can elide them from
132 single-threaded processes. */
133 #if !defined(__NO_WEAK_PTHREAD_ALIASES) && !IS_IN (libpthread)
134 # ifdef weak_extern
135 weak_extern (__pthread_mutex_init)
136 weak_extern (__pthread_mutex_destroy)
137 weak_extern (__pthread_mutex_lock)
138 weak_extern (__pthread_mutex_trylock)
139 weak_extern (__pthread_mutex_unlock)
140 weak_extern (__pthread_mutexattr_init)
141 weak_extern (__pthread_mutexattr_destroy)
142 weak_extern (__pthread_mutexattr_settype)
143 weak_extern (__pthread_rwlock_init)
144 weak_extern (__pthread_rwlock_destroy)
145 weak_extern (__pthread_rwlock_rdlock)
146 weak_extern (__pthread_rwlock_tryrdlock)
147 weak_extern (__pthread_rwlock_wrlock)
148 weak_extern (__pthread_rwlock_trywrlock)
149 weak_extern (__pthread_rwlock_unlock)
150 weak_extern (__pthread_key_create)
151 weak_extern (__pthread_setspecific)
152 weak_extern (__pthread_getspecific)
153 weak_extern (__pthread_once)
154 weak_extern (__pthread_initialize)
155 weak_extern (__pthread_atfork)
156 weak_extern (__pthread_setcancelstate)
157 # else
158 # pragma weak __pthread_mutex_init
159 # pragma weak __pthread_mutex_destroy
160 # pragma weak __pthread_mutex_lock
161 # pragma weak __pthread_mutex_trylock
162 # pragma weak __pthread_mutex_unlock
163 # pragma weak __pthread_mutexattr_init
164 # pragma weak __pthread_mutexattr_destroy
165 # pragma weak __pthread_mutexattr_settype
166 # pragma weak __pthread_rwlock_destroy
167 # pragma weak __pthread_rwlock_rdlock
168 # pragma weak __pthread_rwlock_tryrdlock
169 # pragma weak __pthread_rwlock_wrlock
170 # pragma weak __pthread_rwlock_trywrlock
171 # pragma weak __pthread_rwlock_unlock
172 # pragma weak __pthread_key_create
173 # pragma weak __pthread_setspecific
174 # pragma weak __pthread_getspecific
175 # pragma weak __pthread_once
176 # pragma weak __pthread_initialize
177 # pragma weak __pthread_atfork
178 # pragma weak __pthread_setcancelstate
179 # endif
180 #endif
182 #endif /* bits/libc-lockP.h */