1570af302Sopenharmony_ci/*
2570af302Sopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2020-2023. All rights reserved.
3570af302Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4570af302Sopenharmony_ci * you may not use this file except in compliance with the License.
5570af302Sopenharmony_ci * You may obtain a copy of the License at
6570af302Sopenharmony_ci *
7570af302Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8570af302Sopenharmony_ci *
9570af302Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10570af302Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11570af302Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12570af302Sopenharmony_ci * See the License for the specific language governing permissions and
13570af302Sopenharmony_ci * limitations under the License.
14570af302Sopenharmony_ci */
15570af302Sopenharmony_ci
16570af302Sopenharmony_ci#ifndef _PTHREAD_H
17570af302Sopenharmony_ci#define _PTHREAD_H
18570af302Sopenharmony_ci#ifdef __cplusplus
19570af302Sopenharmony_ciextern "C" {
20570af302Sopenharmony_ci#endif
21570af302Sopenharmony_ci
22570af302Sopenharmony_ci#include <features.h>
23570af302Sopenharmony_ci
24570af302Sopenharmony_ci/* Musl did not provide the "owner" macro directly,
25570af302Sopenharmony_ci * so users can not access the mutex-ower-ID.
26570af302Sopenharmony_ci * Thus we added this macro for getting the owner-ID
27570af302Sopenharmony_ci * of the mutex. */
28570af302Sopenharmony_ci
29570af302Sopenharmony_ci/* These macros provides macros for accessing inner
30570af302Sopenharmony_ci * attributes of the pthread_mutex_t struct.
31570af302Sopenharmony_ci * It is intended for solving the coompiling failure
32570af302Sopenharmony_ci * of Dopra codes which claims that .__data.* realm
33570af302Sopenharmony_ci * can not be found in pthread_mutex_t. */
34570af302Sopenharmony_ci
35570af302Sopenharmony_ci#define __NEED_time_t
36570af302Sopenharmony_ci#define __NEED_clockid_t
37570af302Sopenharmony_ci#define __NEED_struct_timespec
38570af302Sopenharmony_ci#define __NEED_sigset_t
39570af302Sopenharmony_ci#define __NEED_pthread_t
40570af302Sopenharmony_ci#define __NEED_pthread_attr_t
41570af302Sopenharmony_ci#define __NEED_pthread_mutexattr_t
42570af302Sopenharmony_ci#define __NEED_pthread_condattr_t
43570af302Sopenharmony_ci#define __NEED_pthread_rwlockattr_t
44570af302Sopenharmony_ci#define __NEED_pthread_barrierattr_t
45570af302Sopenharmony_ci#define __NEED_pthread_mutex_t
46570af302Sopenharmony_ci#define __NEED_pthread_cond_t
47570af302Sopenharmony_ci#define __NEED_pthread_rwlock_t
48570af302Sopenharmony_ci#define __NEED_pthread_barrier_t
49570af302Sopenharmony_ci#define __NEED_pthread_spinlock_t
50570af302Sopenharmony_ci#define __NEED_pthread_key_t
51570af302Sopenharmony_ci#define __NEED_pthread_once_t
52570af302Sopenharmony_ci#define __NEED_size_t
53570af302Sopenharmony_ci
54570af302Sopenharmony_ci#include <bits/alltypes.h>
55570af302Sopenharmony_ci
56570af302Sopenharmony_ci#include <sched.h>
57570af302Sopenharmony_ci#include <time.h>
58570af302Sopenharmony_ci
59570af302Sopenharmony_ci#define PTHREAD_CREATE_JOINABLE 0
60570af302Sopenharmony_ci#define PTHREAD_CREATE_DETACHED 1
61570af302Sopenharmony_ci
62570af302Sopenharmony_ci#define PTHREAD_MUTEX_NORMAL 0
63570af302Sopenharmony_ci#define PTHREAD_MUTEX_DEFAULT 0
64570af302Sopenharmony_ci#define PTHREAD_MUTEX_RECURSIVE 1
65570af302Sopenharmony_ci#define PTHREAD_MUTEX_ERRORCHECK 2
66570af302Sopenharmony_ci
67570af302Sopenharmony_ci#define PTHREAD_MUTEX_STALLED 0
68570af302Sopenharmony_ci#define PTHREAD_MUTEX_ROBUST 1
69570af302Sopenharmony_ci
70570af302Sopenharmony_ci#define PTHREAD_PRIO_NONE 0
71570af302Sopenharmony_ci#define PTHREAD_PRIO_INHERIT 1
72570af302Sopenharmony_ci#define PTHREAD_PRIO_PROTECT 2
73570af302Sopenharmony_ci
74570af302Sopenharmony_ci#define PTHREAD_INHERIT_SCHED 0
75570af302Sopenharmony_ci#define PTHREAD_EXPLICIT_SCHED 1
76570af302Sopenharmony_ci
77570af302Sopenharmony_ci#define PTHREAD_SCOPE_SYSTEM 0
78570af302Sopenharmony_ci#define PTHREAD_SCOPE_PROCESS 1
79570af302Sopenharmony_ci
80570af302Sopenharmony_ci#define PTHREAD_PROCESS_PRIVATE 0
81570af302Sopenharmony_ci#define PTHREAD_PROCESS_SHARED 1
82570af302Sopenharmony_ci
83570af302Sopenharmony_ci
84570af302Sopenharmony_ci#define PTHREAD_MUTEX_INITIALIZER {{{0}}}
85570af302Sopenharmony_ci#define PTHREAD_RWLOCK_INITIALIZER {{{0}}}
86570af302Sopenharmony_ci#define PTHREAD_COND_INITIALIZER {{{0}}}
87570af302Sopenharmony_ci#define PTHREAD_ONCE_INIT 0
88570af302Sopenharmony_ci
89570af302Sopenharmony_ci
90570af302Sopenharmony_ci#define PTHREAD_CANCEL_ENABLE 0
91570af302Sopenharmony_ci#define PTHREAD_CANCEL_DISABLE 1
92570af302Sopenharmony_ci#define PTHREAD_CANCEL_MASKED 2
93570af302Sopenharmony_ci
94570af302Sopenharmony_ci#define PTHREAD_CANCEL_DEFERRED 0
95570af302Sopenharmony_ci#define PTHREAD_CANCEL_ASYNCHRONOUS 1
96570af302Sopenharmony_ci
97570af302Sopenharmony_ci#define PTHREAD_CANCELED ((void *)-1)
98570af302Sopenharmony_ci
99570af302Sopenharmony_ci
100570af302Sopenharmony_ci#define PTHREAD_BARRIER_SERIAL_THREAD (-1)
101570af302Sopenharmony_ci
102570af302Sopenharmony_ci
103570af302Sopenharmony_ci#define PTHREAD_NULL ((pthread_t)0)
104570af302Sopenharmony_ci
105570af302Sopenharmony_ci
106570af302Sopenharmony_ciint pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict);
107570af302Sopenharmony_ciint pthread_detach(pthread_t);
108570af302Sopenharmony_ci_Noreturn void pthread_exit(void *);
109570af302Sopenharmony_ciint pthread_join(pthread_t, void **);
110570af302Sopenharmony_cipid_t pthread_gettid_np(pthread_t);
111570af302Sopenharmony_ci
112570af302Sopenharmony_ci#ifdef __GNUC__
113570af302Sopenharmony_ci__attribute__((const))
114570af302Sopenharmony_ci#endif
115570af302Sopenharmony_cipthread_t pthread_self(void);
116570af302Sopenharmony_ci
117570af302Sopenharmony_ciint pthread_equal(pthread_t, pthread_t);
118570af302Sopenharmony_ci#ifndef __cplusplus
119570af302Sopenharmony_ci#define pthread_equal(x,y) ((x)==(y))
120570af302Sopenharmony_ci#endif
121570af302Sopenharmony_ci
122570af302Sopenharmony_ciint pthread_setcancelstate(int, int *);
123570af302Sopenharmony_ciint pthread_setcanceltype(int, int *);
124570af302Sopenharmony_civoid pthread_testcancel(void);
125570af302Sopenharmony_ciint pthread_cancel(pthread_t);
126570af302Sopenharmony_ci
127570af302Sopenharmony_ciint pthread_getschedparam(pthread_t, int *__restrict, struct sched_param *__restrict);
128570af302Sopenharmony_ciint pthread_setschedparam(pthread_t, int, const struct sched_param *);
129570af302Sopenharmony_ciint pthread_setschedprio(pthread_t, int);
130570af302Sopenharmony_ci
131570af302Sopenharmony_ciint pthread_once(pthread_once_t *, void (*)(void));
132570af302Sopenharmony_ci
133570af302Sopenharmony_ciint pthread_mutex_init(pthread_mutex_t *__restrict, const pthread_mutexattr_t *__restrict);
134570af302Sopenharmony_ciint pthread_mutex_lock(pthread_mutex_t *);
135570af302Sopenharmony_ciint pthread_mutex_unlock(pthread_mutex_t *);
136570af302Sopenharmony_ciint pthread_mutex_trylock(pthread_mutex_t *);
137570af302Sopenharmony_ciint pthread_mutex_timedlock(pthread_mutex_t *__restrict, const struct timespec *__restrict);
138570af302Sopenharmony_ciint pthread_mutex_destroy(pthread_mutex_t *);
139570af302Sopenharmony_ciint pthread_mutex_consistent(pthread_mutex_t *);
140570af302Sopenharmony_ci/**
141570af302Sopenharmony_ci  * @brief lock the mutex object referenced by mutex. If the mutex is already locked,
142570af302Sopenharmony_ci  *        the calling thread shall block until the mutex becomes available as in the
143570af302Sopenharmony_ci  *        pthread_mutex_lock() function. If the mutex cannot be locked without waiting for
144570af302Sopenharmony_ci  *        another thread to unlock the mutex, this wait shall be terminated when the specified
145570af302Sopenharmony_ci  *        timeout expires. The timeout shall be based on the CLOCK_REALTIME or CLOCK_MONOTONIC clock.
146570af302Sopenharmony_ci  *        The resolution of the timeout shall be the resolution of the clock on which it is based.
147570af302Sopenharmony_ci  * @param mutex a robust mutex and the process containing the owning thread terminated while holding the mutex lock.
148570af302Sopenharmony_ci  * @param clock_id specified CLOCK_REALTIME or CLOCK_MONOTONIC clock.
149570af302Sopenharmony_ci  * @param timespec the timeout shall expire specified by abstime passes.
150570af302Sopenharmony_ci  * @return clocklock result.
151570af302Sopenharmony_ci  * @retval 0 is returned on success.
152570af302Sopenharmony_ci  * @retval -1 is returned on failure, and errno is set to indicate the error.
153570af302Sopenharmony_ci  */
154570af302Sopenharmony_ciint pthread_mutex_clocklock(pthread_mutex_t *__restrict, clockid_t, const struct timespec *__restrict);
155570af302Sopenharmony_ci/**
156570af302Sopenharmony_ci  * @brief lock the mutex object referenced by mutex. If the mutex is already locked,
157570af302Sopenharmony_ci  *        the calling thread shall block until the mutex becomes available as in the
158570af302Sopenharmony_ci  *        pthread_mutex_lock() function. If the mutex cannot be locked without waiting for
159570af302Sopenharmony_ci  *        another thread to unlock the mutex, this wait shall be terminated when the specified
160570af302Sopenharmony_ci  *        timeout expires. The timeout shall be based on the CLOCK_MONOTONIC clock.
161570af302Sopenharmony_ci  *        The resolution of the timeout shall be the resolution of the clock on which it is based.
162570af302Sopenharmony_ci  * @param mutex a robust mutex and the process containing the owning thread terminated while holding the mutex lock.
163570af302Sopenharmony_ci  * @param timespec the timeout shall expire specified by abstime passes.
164570af302Sopenharmony_ci  * @return clocklock result.
165570af302Sopenharmony_ci  * @retval 0 is returned on success.
166570af302Sopenharmony_ci  * @retval -1 is returned on failure, and errno is set to indicate the error.
167570af302Sopenharmony_ci  */
168570af302Sopenharmony_ciint pthread_mutex_timedlock_monotonic_np(pthread_mutex_t *__restrict, const struct timespec *__restrict);
169570af302Sopenharmony_ci/**
170570af302Sopenharmony_ci  * @brief lock the mutex object referenced by mutex. If the mutex is already locked,
171570af302Sopenharmony_ci  *        the calling thread shall block until the mutex becomes available as in the
172570af302Sopenharmony_ci  *        pthread_mutex_lock() function. If the mutex cannot be locked without waiting for
173570af302Sopenharmony_ci  *        another thread to unlock the mutex, this wait shall be terminated when the specified
174570af302Sopenharmony_ci  *        timeout expires. The timeout shall be based on the CLOCK_MONOTONIC clock.
175570af302Sopenharmony_ci  *        The resolution of the timeout shall be the resolution of the clock on which it is based.
176570af302Sopenharmony_ci  * @param mutex a robust mutex and the process containing the owning thread terminated while holding the mutex lock.
177570af302Sopenharmony_ci  * @param ms the timeout shall expire specified by relative time(ms) passes.
178570af302Sopenharmony_ci  * @return clocklock result.
179570af302Sopenharmony_ci  * @retval 0 is returned on success.
180570af302Sopenharmony_ci  * @retval -1 is returned on failure, and errno is set to indicate the error.
181570af302Sopenharmony_ci  */
182570af302Sopenharmony_ciint pthread_mutex_lock_timeout_np(pthread_mutex_t *__restrict, unsigned int);
183570af302Sopenharmony_ci
184570af302Sopenharmony_ciint pthread_mutex_getprioceiling(const pthread_mutex_t *__restrict, int *__restrict);
185570af302Sopenharmony_ciint pthread_mutex_setprioceiling(pthread_mutex_t *__restrict, int, int *__restrict);
186570af302Sopenharmony_ci
187570af302Sopenharmony_ciint pthread_cond_init(pthread_cond_t *__restrict, const pthread_condattr_t *__restrict);
188570af302Sopenharmony_ciint pthread_cond_destroy(pthread_cond_t *);
189570af302Sopenharmony_ciint pthread_cond_wait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict);
190570af302Sopenharmony_ciint pthread_cond_timedwait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict, const struct timespec *__restrict);
191570af302Sopenharmony_ci/**
192570af302Sopenharmony_ci  * @brief The thread waits for a signal to trigger, and if timeout or signal is triggered,
193570af302Sopenharmony_ci  *        the thread wakes up.
194570af302Sopenharmony_ci  * @param pthread_cond_t Condition variables for multithreading.
195570af302Sopenharmony_ci  * @param pthread_mutex_t Thread mutex variable.
196570af302Sopenharmony_ci  * @param clockid_t Clock ID used in clock and timer functions.
197570af302Sopenharmony_ci  * @param timespec The timeout shall expire specified by abstime passes.
198570af302Sopenharmony_ci  * @return pthread_cond_clockwait result.
199570af302Sopenharmony_ci  * @retval 0 pthread_cond_clockwait successful.
200570af302Sopenharmony_ci  * @retval ETIMEDOUT pthread_cond_clockwait Connection timed out.
201570af302Sopenharmony_ci  * @retval EINVAL pthread_cond_clockwait error.
202570af302Sopenharmony_ci  */
203570af302Sopenharmony_ciint pthread_cond_clockwait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict,
204570af302Sopenharmony_ci                           clockid_t, const struct timespec *__restrict);
205570af302Sopenharmony_ci
206570af302Sopenharmony_ci/**
207570af302Sopenharmony_ci  * @brief Condition variables have an initialization option to use CLOCK_MONOTONIC.
208570af302Sopenharmony_ci  *        The thread waits for a signal to trigger, and if timeout or signal is triggered,
209570af302Sopenharmony_ci  *        the thread wakes up.
210570af302Sopenharmony_ci  * @param pthread_cond_t Condition variables for multithreading.
211570af302Sopenharmony_ci  * @param pthread_mutex_t Thread mutex variable.
212570af302Sopenharmony_ci  * @param timespec The timeout shall expire specified by abstime passes.
213570af302Sopenharmony_ci  * @return pthread_cond_timedwait_monotonic_np result.
214570af302Sopenharmony_ci  * @retval 0 pthread_cond_timedwait_monotonic_np successful.
215570af302Sopenharmony_ci  * @retval ETIMEDOUT pthread_cond_timedwait_monotonic_np Connection timed out.
216570af302Sopenharmony_ci  * @retval EINVAL pthread_cond_timedwait_monotonic_np error.
217570af302Sopenharmony_ci  */
218570af302Sopenharmony_ciint pthread_cond_timedwait_monotonic_np(pthread_cond_t *__restrict, pthread_mutex_t *__restrict,
219570af302Sopenharmony_ci                                        const struct timespec *__restrict);
220570af302Sopenharmony_ci
221570af302Sopenharmony_ci/**
222570af302Sopenharmony_ci  * @brief Condition variables have an initialization option to use CLOCK_MONOTONIC and The time
223570af302Sopenharmony_ci  *        parameter is in milliseconds. The thread waits for a signal to trigger, and if timeout or
224570af302Sopenharmony_ci  *        signal is triggered, the thread wakes up.
225570af302Sopenharmony_ci  * @param pthread_cond_t Condition variables for multithreading.
226570af302Sopenharmony_ci  * @param pthread_mutex_t Thread mutex variable.
227570af302Sopenharmony_ci  * @param unsigned Timeout, in milliseconds.
228570af302Sopenharmony_ci  * @return pthread_cond_timeout_np result.
229570af302Sopenharmony_ci  * @retval 0 pthread_cond_timeout_np successful.
230570af302Sopenharmony_ci  * @retval ETIMEDOUT pthread_cond_timeout_np Connection timed out.
231570af302Sopenharmony_ci  * @retval EINVAL pthread_cond_timeout_np error.
232570af302Sopenharmony_ci  */
233570af302Sopenharmony_ciint pthread_cond_timeout_np(pthread_cond_t* __restrict, pthread_mutex_t* __restrict, unsigned int);
234570af302Sopenharmony_ciint pthread_cond_broadcast(pthread_cond_t *);
235570af302Sopenharmony_ciint pthread_cond_signal(pthread_cond_t *);
236570af302Sopenharmony_ci
237570af302Sopenharmony_ciint pthread_rwlock_init(pthread_rwlock_t *__restrict, const pthread_rwlockattr_t *__restrict);
238570af302Sopenharmony_ciint pthread_rwlock_destroy(pthread_rwlock_t *);
239570af302Sopenharmony_ciint pthread_rwlock_rdlock(pthread_rwlock_t *);
240570af302Sopenharmony_ciint pthread_rwlock_tryrdlock(pthread_rwlock_t *);
241570af302Sopenharmony_ciint pthread_rwlock_timedrdlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict);
242570af302Sopenharmony_ci/**
243570af302Sopenharmony_ci  * @brief Apply a read lock to the read-write lock referenced by rwlock as in the
244570af302Sopenharmony_ci  *        pthread_rwlock_rdlock() function. However, if the lock cannot be acquired without
245570af302Sopenharmony_ci  *        waiting for other threads to unlock the lock, this wait shall be terminated when
246570af302Sopenharmony_ci  *        the specified timeout expires. The timeout shall expire when the absolute time specified by
247570af302Sopenharmony_ci  *        abstime passes, as measured by the clock on which timeouts are based, or if the absolute time
248570af302Sopenharmony_ci  *        specified by abstime has already been passed at the time of the call.
249570af302Sopenharmony_ci  *        The timeout shall be based on the CLOCK_REALTIME or CLOCK_MONOTONIC clock.
250570af302Sopenharmony_ci  * @param rw a read lock to the read-write lock referenced.
251570af302Sopenharmony_ci  * @param clock_id specified CLOCK_REALTIME or CLOCK_MONOTONIC clock.
252570af302Sopenharmony_ci  * @param timespec the timeout shall expire specified by abstime passes.
253570af302Sopenharmony_ci  * @return clockrdlock result.
254570af302Sopenharmony_ci  * @retval 0 is returned on success.
255570af302Sopenharmony_ci  * @retval -1 is returned on failure, and errno is set to indicate the error.
256570af302Sopenharmony_ci  */
257570af302Sopenharmony_ciint pthread_rwlock_clockrdlock(pthread_rwlock_t *__restrict, clockid_t, const struct timespec *__restrict);
258570af302Sopenharmony_ci/**
259570af302Sopenharmony_ci  * @brief Apply a read lock to the read-write lock referenced by rwlock as in the
260570af302Sopenharmony_ci  *        pthread_rwlock_rdlock() function. However, if the lock cannot be acquired without
261570af302Sopenharmony_ci  *        waiting for other threads to unlock the lock, this wait shall be terminated when
262570af302Sopenharmony_ci  *        the specified timeout expires. The timeout shall expire when the absolute time specified by
263570af302Sopenharmony_ci  *        abstime passes, as measured by the clock on which timeouts are based, or if the absolute time
264570af302Sopenharmony_ci  *        specified by abstime has already been passed at the time of the call.
265570af302Sopenharmony_ci  *        The timeout shall be based on the CLOCK_MONOTONIC clock.
266570af302Sopenharmony_ci  * @param rw a read lock to the read-write lock referenced.
267570af302Sopenharmony_ci  * @param timespec the timeout shall expire specified by abstime passes.
268570af302Sopenharmony_ci  * @return clockrdlock result.
269570af302Sopenharmony_ci  * @retval 0 is returned on success.
270570af302Sopenharmony_ci  * @retval -1 is returned on failure, and errno is set to indicate the error.
271570af302Sopenharmony_ci  */
272570af302Sopenharmony_ciint pthread_rwlock_timedrdlock_monotonic_np(pthread_rwlock_t *__restrict, const struct timespec *__restrict);
273570af302Sopenharmony_ciint pthread_rwlock_wrlock(pthread_rwlock_t *);
274570af302Sopenharmony_ciint pthread_rwlock_trywrlock(pthread_rwlock_t *);
275570af302Sopenharmony_ciint pthread_rwlock_timedwrlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict);
276570af302Sopenharmony_ciint pthread_rwlock_unlock(pthread_rwlock_t *);
277570af302Sopenharmony_ci/**
278570af302Sopenharmony_ci  * @brief Read-write lock variables have an initialization option to use CLOCK_MONOTONIC.
279570af302Sopenharmony_ci  *        apply a read lock to the read-write lock referenced by rwlock as in the
280570af302Sopenharmony_ci  *        pthread_rwlock_wrlock() function. However, if the lock cannot be acquired without
281570af302Sopenharmony_ci  *        waiting for other threads to unlock the lock, this wait shall be terminated when
282570af302Sopenharmony_ci  *        the specified timeout expires. The timeout shall expire when the absolute time specified by
283570af302Sopenharmony_ci  *        abstime passes, as measured by the clock on which timeouts are based, or if the absolute time
284570af302Sopenharmony_ci  *        specified by abstime has already been passed at the time of the call.
285570af302Sopenharmony_ci  *        The timeout shall be based on the CLOCK_MONOTONIC clock.
286570af302Sopenharmony_ci  * @param rw a read lock to the read-write lock referenced.
287570af302Sopenharmony_ci  * @param timespec the timeout shall expire specified by abstime passes.
288570af302Sopenharmony_ci  * @return clockrdlock result.
289570af302Sopenharmony_ci  * @retval 0 is returned on success.
290570af302Sopenharmony_ci  * @retval -1 is returned on failure, and errno is set to indicate the error.
291570af302Sopenharmony_ci  */
292570af302Sopenharmony_ciint pthread_rwlock_timedwrlock_monotonic_np(pthread_rwlock_t *__restrict, const struct timespec *__restrict);
293570af302Sopenharmony_ci
294570af302Sopenharmony_ci/**
295570af302Sopenharmony_ci  * @brief Apply a read lock to the read-write lock referenced by rwlock as in the
296570af302Sopenharmony_ci  *        pthread_rwlock_wrlock() function. However, if the lock cannot be acquired without
297570af302Sopenharmony_ci  *        waiting for other threads to unlock the lock, this wait shall be terminated when
298570af302Sopenharmony_ci  *        the specified timeout expires. The timeout shall expire when the absolute time specified by
299570af302Sopenharmony_ci  *        abstime passes, as measured by the clock on which timeouts are based, or if the absolute time
300570af302Sopenharmony_ci  *        specified by abstime has already been passed at the time of the call.
301570af302Sopenharmony_ci  *        The timeout shall be based on the CLOCK_REALTIME or CLOCK_MONOTONIC clock.
302570af302Sopenharmony_ci  * @param rw a read lock to the read-write lock referenced.
303570af302Sopenharmony_ci  * @param clock_id specified CLOCK_REALTIME or CLOCK_MONOTONIC clock.
304570af302Sopenharmony_ci  * @param timespec the timeout shall expire specified by abstime passes.
305570af302Sopenharmony_ci  * @return clockrdlock result.
306570af302Sopenharmony_ci  * @retval 0 is returned on success.
307570af302Sopenharmony_ci  * @retval -1 is returned on failure, and errno is set to indicate the error.
308570af302Sopenharmony_ci  */
309570af302Sopenharmony_ciint pthread_rwlock_clockwrlock(pthread_rwlock_t *__restrict, clockid_t, const struct timespec *__restrict);
310570af302Sopenharmony_ci
311570af302Sopenharmony_ciint pthread_spin_init(pthread_spinlock_t *, int);
312570af302Sopenharmony_ciint pthread_spin_destroy(pthread_spinlock_t *);
313570af302Sopenharmony_ciint pthread_spin_lock(pthread_spinlock_t *);
314570af302Sopenharmony_ciint pthread_spin_trylock(pthread_spinlock_t *);
315570af302Sopenharmony_ciint pthread_spin_unlock(pthread_spinlock_t *);
316570af302Sopenharmony_ci
317570af302Sopenharmony_ciint pthread_barrier_init(pthread_barrier_t *__restrict, const pthread_barrierattr_t *__restrict, unsigned);
318570af302Sopenharmony_ciint pthread_barrier_destroy(pthread_barrier_t *);
319570af302Sopenharmony_ciint pthread_barrier_wait(pthread_barrier_t *);
320570af302Sopenharmony_ci
321570af302Sopenharmony_ciint pthread_key_create(pthread_key_t *, void (*)(void *));
322570af302Sopenharmony_ciint pthread_key_delete(pthread_key_t);
323570af302Sopenharmony_civoid *pthread_getspecific(pthread_key_t);
324570af302Sopenharmony_ciint pthread_setspecific(pthread_key_t, const void *);
325570af302Sopenharmony_ci
326570af302Sopenharmony_ciint pthread_attr_init(pthread_attr_t *);
327570af302Sopenharmony_ciint pthread_attr_destroy(pthread_attr_t *);
328570af302Sopenharmony_ci
329570af302Sopenharmony_ciint pthread_attr_getguardsize(const pthread_attr_t *__restrict, size_t *__restrict);
330570af302Sopenharmony_ciint pthread_attr_setguardsize(pthread_attr_t *, size_t);
331570af302Sopenharmony_ciint pthread_attr_getstacksize(const pthread_attr_t *__restrict, size_t *__restrict);
332570af302Sopenharmony_ciint pthread_attr_setstacksize(pthread_attr_t *, size_t);
333570af302Sopenharmony_ciint pthread_attr_getdetachstate(const pthread_attr_t *, int *);
334570af302Sopenharmony_ciint pthread_attr_setdetachstate(pthread_attr_t *, int);
335570af302Sopenharmony_ciint pthread_attr_getstack(const pthread_attr_t *__restrict, void **__restrict, size_t *__restrict);
336570af302Sopenharmony_ciint pthread_attr_setstack(pthread_attr_t *, void *, size_t);
337570af302Sopenharmony_ciint pthread_attr_getscope(const pthread_attr_t *__restrict, int *__restrict);
338570af302Sopenharmony_ciint pthread_attr_setscope(pthread_attr_t *, int);
339570af302Sopenharmony_ciint pthread_attr_getschedpolicy(const pthread_attr_t *__restrict, int *__restrict);
340570af302Sopenharmony_ciint pthread_attr_setschedpolicy(pthread_attr_t *, int);
341570af302Sopenharmony_ciint pthread_attr_getschedparam(const pthread_attr_t *__restrict, struct sched_param *__restrict);
342570af302Sopenharmony_ciint pthread_attr_setschedparam(pthread_attr_t *__restrict, const struct sched_param *__restrict);
343570af302Sopenharmony_ciint pthread_attr_getinheritsched(const pthread_attr_t *__restrict, int *__restrict);
344570af302Sopenharmony_ciint pthread_attr_setinheritsched(pthread_attr_t *, int);
345570af302Sopenharmony_ci
346570af302Sopenharmony_ciint pthread_mutexattr_destroy(pthread_mutexattr_t *);
347570af302Sopenharmony_ciint pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *__restrict, int *__restrict);
348570af302Sopenharmony_ciint pthread_mutexattr_getprotocol(const pthread_mutexattr_t *__restrict, int *__restrict);
349570af302Sopenharmony_ciint pthread_mutexattr_getpshared(const pthread_mutexattr_t *__restrict, int *__restrict);
350570af302Sopenharmony_ciint pthread_mutexattr_getrobust(const pthread_mutexattr_t *__restrict, int *__restrict);
351570af302Sopenharmony_ciint pthread_mutexattr_gettype(const pthread_mutexattr_t *__restrict, int *__restrict);
352570af302Sopenharmony_ciint pthread_mutexattr_init(pthread_mutexattr_t *);
353570af302Sopenharmony_ciint pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int);
354570af302Sopenharmony_ciint pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int);
355570af302Sopenharmony_ciint pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
356570af302Sopenharmony_ciint pthread_mutexattr_setrobust(pthread_mutexattr_t *, int);
357570af302Sopenharmony_ciint pthread_mutexattr_settype(pthread_mutexattr_t *, int);
358570af302Sopenharmony_ci
359570af302Sopenharmony_ciint pthread_condattr_init(pthread_condattr_t *);
360570af302Sopenharmony_ciint pthread_condattr_destroy(pthread_condattr_t *);
361570af302Sopenharmony_ciint pthread_condattr_setclock(pthread_condattr_t *, clockid_t);
362570af302Sopenharmony_ciint pthread_condattr_setpshared(pthread_condattr_t *, int);
363570af302Sopenharmony_ciint pthread_condattr_getclock(const pthread_condattr_t *__restrict, clockid_t *__restrict);
364570af302Sopenharmony_ciint pthread_condattr_getpshared(const pthread_condattr_t *__restrict, int *__restrict);
365570af302Sopenharmony_ci
366570af302Sopenharmony_ciint pthread_rwlockattr_init(pthread_rwlockattr_t *);
367570af302Sopenharmony_ciint pthread_rwlockattr_destroy(pthread_rwlockattr_t *);
368570af302Sopenharmony_ciint pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int);
369570af302Sopenharmony_ciint pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *__restrict, int *__restrict);
370570af302Sopenharmony_ci
371570af302Sopenharmony_ciint pthread_barrierattr_destroy(pthread_barrierattr_t *);
372570af302Sopenharmony_ciint pthread_barrierattr_getpshared(const pthread_barrierattr_t *__restrict, int *__restrict);
373570af302Sopenharmony_ciint pthread_barrierattr_init(pthread_barrierattr_t *);
374570af302Sopenharmony_ciint pthread_barrierattr_setpshared(pthread_barrierattr_t *, int);
375570af302Sopenharmony_ci
376570af302Sopenharmony_ciint pthread_atfork(void (*)(void), void (*)(void), void (*)(void));
377570af302Sopenharmony_ci
378570af302Sopenharmony_ciint pthread_getconcurrency(void);
379570af302Sopenharmony_ciint pthread_setconcurrency(int);
380570af302Sopenharmony_ci
381570af302Sopenharmony_ciint pthread_getcpuclockid(pthread_t, clockid_t *);
382570af302Sopenharmony_ci
383570af302Sopenharmony_cistruct __ptcb {
384570af302Sopenharmony_ci	void (*__f)(void *);
385570af302Sopenharmony_ci	void *__x;
386570af302Sopenharmony_ci	struct __ptcb *__next;
387570af302Sopenharmony_ci};
388570af302Sopenharmony_ci
389570af302Sopenharmony_civoid _pthread_cleanup_push(struct __ptcb *, void (*)(void *), void *);
390570af302Sopenharmony_civoid _pthread_cleanup_pop(struct __ptcb *, int);
391570af302Sopenharmony_ci
392570af302Sopenharmony_ci#define pthread_cleanup_push(f, x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x);
393570af302Sopenharmony_ci#define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0)
394570af302Sopenharmony_ci
395570af302Sopenharmony_ci#ifdef _GNU_SOURCE
396570af302Sopenharmony_cistruct cpu_set_t;
397570af302Sopenharmony_ciint pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *);
398570af302Sopenharmony_ciint pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *);
399570af302Sopenharmony_ciint pthread_getattr_np(pthread_t, pthread_attr_t *);
400570af302Sopenharmony_ciint pthread_setname_np(pthread_t, const char *);
401570af302Sopenharmony_ciint pthread_getname_np(pthread_t, char *, size_t);
402570af302Sopenharmony_ciint pthread_getattr_default_np(pthread_attr_t *);
403570af302Sopenharmony_ciint pthread_setattr_default_np(const pthread_attr_t *);
404570af302Sopenharmony_ciint pthread_tryjoin_np(pthread_t, void **);
405570af302Sopenharmony_ciint pthread_timedjoin_np(pthread_t, void **, const struct timespec *);
406570af302Sopenharmony_ci#endif
407570af302Sopenharmony_ci
408570af302Sopenharmony_ci#if _REDIR_TIME64
409570af302Sopenharmony_ci__REDIR(pthread_mutex_timedlock, __pthread_mutex_timedlock_time64);
410570af302Sopenharmony_ci__REDIR(pthread_cond_timedwait, __pthread_cond_timedwait_time64);
411570af302Sopenharmony_ci__REDIR(pthread_rwlock_timedrdlock, __pthread_rwlock_timedrdlock_time64);
412570af302Sopenharmony_ci__REDIR(pthread_rwlock_timedwrlock, __pthread_rwlock_timedwrlock_time64);
413570af302Sopenharmony_ci#ifdef _GNU_SOURCE
414570af302Sopenharmony_ci__REDIR(pthread_timedjoin_np, __pthread_timedjoin_np_time64);
415570af302Sopenharmony_ci#endif
416570af302Sopenharmony_ci#endif
417570af302Sopenharmony_ci
418570af302Sopenharmony_ci#ifdef __cplusplus
419570af302Sopenharmony_ci}
420570af302Sopenharmony_ci#endif
421570af302Sopenharmony_ci#endif
422