Use clock_settime to implement stime; withdraw stime.
[glibc.git] / sysdeps / htl / libc-lockP.h
blob6c009e8e50c749e5a2277d4bd83c64006a6633c4
1 /* Private libc-internal interface for mutex locks.
2 Copyright (C) 2015-2019 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_setspecific (pthread_key_t __key,
116 const void *__pointer);
118 extern void *__pthread_getspecific (pthread_key_t __key);
120 extern int __pthread_once (pthread_once_t *__once_control,
121 void (*__init_routine) (void));
123 extern int __pthread_atfork (void (*__prepare) (void),
124 void (*__parent) (void),
125 void (*__child) (void));
129 /* Make the pthread functions weak so that we can elide them from
130 single-threaded processes. */
131 #if !defined(__NO_WEAK_PTHREAD_ALIASES) && !IS_IN (libpthread)
132 # ifdef weak_extern
133 weak_extern (__pthread_mutex_init)
134 weak_extern (__pthread_mutex_destroy)
135 weak_extern (__pthread_mutex_lock)
136 weak_extern (__pthread_mutex_trylock)
137 weak_extern (__pthread_mutex_unlock)
138 weak_extern (__pthread_mutexattr_init)
139 weak_extern (__pthread_mutexattr_destroy)
140 weak_extern (__pthread_mutexattr_settype)
141 weak_extern (__pthread_rwlock_init)
142 weak_extern (__pthread_rwlock_destroy)
143 weak_extern (__pthread_rwlock_rdlock)
144 weak_extern (__pthread_rwlock_tryrdlock)
145 weak_extern (__pthread_rwlock_wrlock)
146 weak_extern (__pthread_rwlock_trywrlock)
147 weak_extern (__pthread_rwlock_unlock)
148 weak_extern (__pthread_key_create)
149 weak_extern (__pthread_setspecific)
150 weak_extern (__pthread_getspecific)
151 weak_extern (__pthread_once)
152 weak_extern (__pthread_initialize)
153 weak_extern (__pthread_atfork)
154 weak_extern (__pthread_setcancelstate)
155 # else
156 # pragma weak __pthread_mutex_init
157 # pragma weak __pthread_mutex_destroy
158 # pragma weak __pthread_mutex_lock
159 # pragma weak __pthread_mutex_trylock
160 # pragma weak __pthread_mutex_unlock
161 # pragma weak __pthread_mutexattr_init
162 # pragma weak __pthread_mutexattr_destroy
163 # pragma weak __pthread_mutexattr_settype
164 # pragma weak __pthread_rwlock_destroy
165 # pragma weak __pthread_rwlock_rdlock
166 # pragma weak __pthread_rwlock_tryrdlock
167 # pragma weak __pthread_rwlock_wrlock
168 # pragma weak __pthread_rwlock_trywrlock
169 # pragma weak __pthread_rwlock_unlock
170 # pragma weak __pthread_key_create
171 # pragma weak __pthread_setspecific
172 # pragma weak __pthread_getspecific
173 # pragma weak __pthread_once
174 # pragma weak __pthread_initialize
175 # pragma weak __pthread_atfork
176 # pragma weak __pthread_setcancelstate
177 # endif
178 #endif
180 #endif /* bits/libc-lockP.h */