annotate libcxx/include/__threading_support @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 1f2b6ac9f198
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // -*- C++ -*-
anatofuz
parents:
diff changeset
2 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
3 //
anatofuz
parents:
diff changeset
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
5 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
7 //
anatofuz
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
9
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
10 #ifndef _LIBCPP___THREADING_SUPPORT
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
11 #define _LIBCPP___THREADING_SUPPORT
150
anatofuz
parents:
diff changeset
12
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
13 #include <__availability>
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
14 #include <__chrono/convert_to_timespec.h>
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
15 #include <__chrono/duration.h>
150
anatofuz
parents:
diff changeset
16 #include <__config>
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
17 #include <__thread/poll_with_backoff.h>
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
18 #include <errno.h>
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
19
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
20 #ifdef __MVS__
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
21 # include <__support/ibm/nanosleep.h>
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
22 #endif
150
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
25 # pragma GCC system_header
150
anatofuz
parents:
diff changeset
26 #endif
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
anatofuz
parents:
diff changeset
29 # include <__external_threading>
anatofuz
parents:
diff changeset
30 #elif !defined(_LIBCPP_HAS_NO_THREADS)
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
33 // Some platforms require <bits/atomic_wide_counter.h> in order for
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
34 // PTHREAD_COND_INITIALIZER to be expanded. Normally that would come
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
35 // in via <pthread.h>, but it's a non-modular header on those platforms,
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
36 // so libc++'s <math.h> usually absorbs atomic_wide_counter.h into the
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
37 // module with <math.h> and makes atomic_wide_counter.h invisible.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
38 // Include <math.h> here to work around that.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
39 # include <math.h>
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
40
150
anatofuz
parents:
diff changeset
41 # include <pthread.h>
anatofuz
parents:
diff changeset
42 # include <sched.h>
anatofuz
parents:
diff changeset
43 #elif defined(_LIBCPP_HAS_THREAD_API_C11)
anatofuz
parents:
diff changeset
44 # include <threads.h>
anatofuz
parents:
diff changeset
45 #endif
anatofuz
parents:
diff changeset
46
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
47 #if defined(_LIBCPP_HAS_THREAD_API_WIN32)
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
48 #define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_EXPORTED_FROM_ABI
150
anatofuz
parents:
diff changeset
49 #else
anatofuz
parents:
diff changeset
50 #define _LIBCPP_THREAD_ABI_VISIBILITY inline _LIBCPP_INLINE_VISIBILITY
anatofuz
parents:
diff changeset
51 #endif
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 typedef ::timespec __libcpp_timespec_t;
anatofuz
parents:
diff changeset
54 #endif // !defined(_LIBCPP_HAS_NO_THREADS)
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 _LIBCPP_BEGIN_NAMESPACE_STD
anatofuz
parents:
diff changeset
57
anatofuz
parents:
diff changeset
58 #if !defined(_LIBCPP_HAS_NO_THREADS)
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
anatofuz
parents:
diff changeset
61 // Mutex
anatofuz
parents:
diff changeset
62 typedef pthread_mutex_t __libcpp_mutex_t;
anatofuz
parents:
diff changeset
63 #define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 typedef pthread_mutex_t __libcpp_recursive_mutex_t;
anatofuz
parents:
diff changeset
66
anatofuz
parents:
diff changeset
67 // Condition Variable
anatofuz
parents:
diff changeset
68 typedef pthread_cond_t __libcpp_condvar_t;
anatofuz
parents:
diff changeset
69 #define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
anatofuz
parents:
diff changeset
70
anatofuz
parents:
diff changeset
71 // Execute once
anatofuz
parents:
diff changeset
72 typedef pthread_once_t __libcpp_exec_once_flag;
anatofuz
parents:
diff changeset
73 #define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
anatofuz
parents:
diff changeset
74
anatofuz
parents:
diff changeset
75 // Thread id
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
76 #if defined(__MVS__)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
77 typedef unsigned long long __libcpp_thread_id;
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
78 #else
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
79 typedef pthread_t __libcpp_thread_id;
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
80 #endif
150
anatofuz
parents:
diff changeset
81
anatofuz
parents:
diff changeset
82 // Thread
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
83 #define _LIBCPP_NULL_THREAD ((__libcpp_thread_t()))
150
anatofuz
parents:
diff changeset
84 typedef pthread_t __libcpp_thread_t;
anatofuz
parents:
diff changeset
85
anatofuz
parents:
diff changeset
86 // Thread Local Storage
anatofuz
parents:
diff changeset
87 typedef pthread_key_t __libcpp_tls_key;
anatofuz
parents:
diff changeset
88
anatofuz
parents:
diff changeset
89 #define _LIBCPP_TLS_DESTRUCTOR_CC
anatofuz
parents:
diff changeset
90 #elif defined(_LIBCPP_HAS_THREAD_API_C11)
anatofuz
parents:
diff changeset
91 // Mutex
anatofuz
parents:
diff changeset
92 typedef mtx_t __libcpp_mutex_t;
anatofuz
parents:
diff changeset
93 // mtx_t is a struct so using {} for initialization is valid.
anatofuz
parents:
diff changeset
94 #define _LIBCPP_MUTEX_INITIALIZER {}
anatofuz
parents:
diff changeset
95
anatofuz
parents:
diff changeset
96 typedef mtx_t __libcpp_recursive_mutex_t;
anatofuz
parents:
diff changeset
97
anatofuz
parents:
diff changeset
98 // Condition Variable
anatofuz
parents:
diff changeset
99 typedef cnd_t __libcpp_condvar_t;
anatofuz
parents:
diff changeset
100 // cnd_t is a struct so using {} for initialization is valid.
anatofuz
parents:
diff changeset
101 #define _LIBCPP_CONDVAR_INITIALIZER {}
anatofuz
parents:
diff changeset
102
anatofuz
parents:
diff changeset
103 // Execute once
anatofuz
parents:
diff changeset
104 typedef once_flag __libcpp_exec_once_flag;
anatofuz
parents:
diff changeset
105 #define _LIBCPP_EXEC_ONCE_INITIALIZER ONCE_FLAG_INIT
anatofuz
parents:
diff changeset
106
anatofuz
parents:
diff changeset
107 // Thread id
anatofuz
parents:
diff changeset
108 typedef thrd_t __libcpp_thread_id;
anatofuz
parents:
diff changeset
109
anatofuz
parents:
diff changeset
110 // Thread
anatofuz
parents:
diff changeset
111 #define _LIBCPP_NULL_THREAD 0U
anatofuz
parents:
diff changeset
112
anatofuz
parents:
diff changeset
113 typedef thrd_t __libcpp_thread_t;
anatofuz
parents:
diff changeset
114
anatofuz
parents:
diff changeset
115 // Thread Local Storage
anatofuz
parents:
diff changeset
116 typedef tss_t __libcpp_tls_key;
anatofuz
parents:
diff changeset
117
anatofuz
parents:
diff changeset
118 #define _LIBCPP_TLS_DESTRUCTOR_CC
anatofuz
parents:
diff changeset
119 #elif !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
anatofuz
parents:
diff changeset
120 // Mutex
anatofuz
parents:
diff changeset
121 typedef void* __libcpp_mutex_t;
anatofuz
parents:
diff changeset
122 #define _LIBCPP_MUTEX_INITIALIZER 0
anatofuz
parents:
diff changeset
123
anatofuz
parents:
diff changeset
124 #if defined(_M_IX86) || defined(__i386__) || defined(_M_ARM) || defined(__arm__)
anatofuz
parents:
diff changeset
125 typedef void* __libcpp_recursive_mutex_t[6];
anatofuz
parents:
diff changeset
126 #elif defined(_M_AMD64) || defined(__x86_64__) || defined(_M_ARM64) || defined(__aarch64__)
anatofuz
parents:
diff changeset
127 typedef void* __libcpp_recursive_mutex_t[5];
anatofuz
parents:
diff changeset
128 #else
anatofuz
parents:
diff changeset
129 # error Unsupported architecture
anatofuz
parents:
diff changeset
130 #endif
anatofuz
parents:
diff changeset
131
anatofuz
parents:
diff changeset
132 // Condition Variable
anatofuz
parents:
diff changeset
133 typedef void* __libcpp_condvar_t;
anatofuz
parents:
diff changeset
134 #define _LIBCPP_CONDVAR_INITIALIZER 0
anatofuz
parents:
diff changeset
135
anatofuz
parents:
diff changeset
136 // Execute Once
anatofuz
parents:
diff changeset
137 typedef void* __libcpp_exec_once_flag;
anatofuz
parents:
diff changeset
138 #define _LIBCPP_EXEC_ONCE_INITIALIZER 0
anatofuz
parents:
diff changeset
139
anatofuz
parents:
diff changeset
140 // Thread ID
anatofuz
parents:
diff changeset
141 typedef long __libcpp_thread_id;
anatofuz
parents:
diff changeset
142
anatofuz
parents:
diff changeset
143 // Thread
anatofuz
parents:
diff changeset
144 #define _LIBCPP_NULL_THREAD 0U
anatofuz
parents:
diff changeset
145
anatofuz
parents:
diff changeset
146 typedef void* __libcpp_thread_t;
anatofuz
parents:
diff changeset
147
anatofuz
parents:
diff changeset
148 // Thread Local Storage
anatofuz
parents:
diff changeset
149 typedef long __libcpp_tls_key;
anatofuz
parents:
diff changeset
150
anatofuz
parents:
diff changeset
151 #define _LIBCPP_TLS_DESTRUCTOR_CC __stdcall
anatofuz
parents:
diff changeset
152 #endif // !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
anatofuz
parents:
diff changeset
153
anatofuz
parents:
diff changeset
154 #if !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
anatofuz
parents:
diff changeset
155 // Mutex
anatofuz
parents:
diff changeset
156 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
157 int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m);
anatofuz
parents:
diff changeset
158
anatofuz
parents:
diff changeset
159 _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
anatofuz
parents:
diff changeset
160 int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m);
anatofuz
parents:
diff changeset
161
anatofuz
parents:
diff changeset
162 _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
anatofuz
parents:
diff changeset
163 bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m);
anatofuz
parents:
diff changeset
164
anatofuz
parents:
diff changeset
165 _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
anatofuz
parents:
diff changeset
166 int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m);
anatofuz
parents:
diff changeset
167
anatofuz
parents:
diff changeset
168 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
169 int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m);
anatofuz
parents:
diff changeset
170
anatofuz
parents:
diff changeset
171 _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
anatofuz
parents:
diff changeset
172 int __libcpp_mutex_lock(__libcpp_mutex_t *__m);
anatofuz
parents:
diff changeset
173
anatofuz
parents:
diff changeset
174 _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
anatofuz
parents:
diff changeset
175 bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m);
anatofuz
parents:
diff changeset
176
anatofuz
parents:
diff changeset
177 _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
anatofuz
parents:
diff changeset
178 int __libcpp_mutex_unlock(__libcpp_mutex_t *__m);
anatofuz
parents:
diff changeset
179
anatofuz
parents:
diff changeset
180 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
181 int __libcpp_mutex_destroy(__libcpp_mutex_t *__m);
anatofuz
parents:
diff changeset
182
anatofuz
parents:
diff changeset
183 // Condition variable
anatofuz
parents:
diff changeset
184 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
185 int __libcpp_condvar_signal(__libcpp_condvar_t* __cv);
anatofuz
parents:
diff changeset
186
anatofuz
parents:
diff changeset
187 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
188 int __libcpp_condvar_broadcast(__libcpp_condvar_t* __cv);
anatofuz
parents:
diff changeset
189
anatofuz
parents:
diff changeset
190 _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
anatofuz
parents:
diff changeset
191 int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m);
anatofuz
parents:
diff changeset
192
anatofuz
parents:
diff changeset
193 _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
anatofuz
parents:
diff changeset
194 int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,
anatofuz
parents:
diff changeset
195 __libcpp_timespec_t *__ts);
anatofuz
parents:
diff changeset
196
anatofuz
parents:
diff changeset
197 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
198 int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv);
anatofuz
parents:
diff changeset
199
anatofuz
parents:
diff changeset
200 // Execute once
anatofuz
parents:
diff changeset
201 _LIBCPP_THREAD_ABI_VISIBILITY
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
202 int __libcpp_execute_once(__libcpp_exec_once_flag *__flag,
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
203 void (*__init_routine)());
150
anatofuz
parents:
diff changeset
204
anatofuz
parents:
diff changeset
205 // Thread id
anatofuz
parents:
diff changeset
206 _LIBCPP_THREAD_ABI_VISIBILITY
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
207 bool __libcpp_thread_id_equal(__libcpp_thread_id __t1, __libcpp_thread_id __t2);
150
anatofuz
parents:
diff changeset
208
anatofuz
parents:
diff changeset
209 _LIBCPP_THREAD_ABI_VISIBILITY
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
210 bool __libcpp_thread_id_less(__libcpp_thread_id __t1, __libcpp_thread_id __t2);
150
anatofuz
parents:
diff changeset
211
anatofuz
parents:
diff changeset
212 // Thread
anatofuz
parents:
diff changeset
213 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
214 bool __libcpp_thread_isnull(const __libcpp_thread_t *__t);
anatofuz
parents:
diff changeset
215
anatofuz
parents:
diff changeset
216 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
217 int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
anatofuz
parents:
diff changeset
218 void *__arg);
anatofuz
parents:
diff changeset
219
anatofuz
parents:
diff changeset
220 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
221 __libcpp_thread_id __libcpp_thread_get_current_id();
anatofuz
parents:
diff changeset
222
anatofuz
parents:
diff changeset
223 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
224 __libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t);
anatofuz
parents:
diff changeset
225
anatofuz
parents:
diff changeset
226 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
227 int __libcpp_thread_join(__libcpp_thread_t *__t);
anatofuz
parents:
diff changeset
228
anatofuz
parents:
diff changeset
229 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
230 int __libcpp_thread_detach(__libcpp_thread_t *__t);
anatofuz
parents:
diff changeset
231
anatofuz
parents:
diff changeset
232 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
233 void __libcpp_thread_yield();
anatofuz
parents:
diff changeset
234
anatofuz
parents:
diff changeset
235 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
236 void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns);
anatofuz
parents:
diff changeset
237
anatofuz
parents:
diff changeset
238 // Thread local storage
anatofuz
parents:
diff changeset
239 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
240 int __libcpp_tls_create(__libcpp_tls_key* __key,
anatofuz
parents:
diff changeset
241 void(_LIBCPP_TLS_DESTRUCTOR_CC* __at_exit)(void*));
anatofuz
parents:
diff changeset
242
anatofuz
parents:
diff changeset
243 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
244 void *__libcpp_tls_get(__libcpp_tls_key __key);
anatofuz
parents:
diff changeset
245
anatofuz
parents:
diff changeset
246 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
247 int __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
anatofuz
parents:
diff changeset
248
anatofuz
parents:
diff changeset
249 #endif // !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
anatofuz
parents:
diff changeset
250
anatofuz
parents:
diff changeset
251 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
anatofuz
parents:
diff changeset
252
anatofuz
parents:
diff changeset
253 int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m)
anatofuz
parents:
diff changeset
254 {
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
255 pthread_mutexattr_t __attr;
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
256 int __ec = pthread_mutexattr_init(&__attr);
150
anatofuz
parents:
diff changeset
257 if (__ec)
anatofuz
parents:
diff changeset
258 return __ec;
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
259 __ec = pthread_mutexattr_settype(&__attr, PTHREAD_MUTEX_RECURSIVE);
150
anatofuz
parents:
diff changeset
260 if (__ec) {
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
261 pthread_mutexattr_destroy(&__attr);
150
anatofuz
parents:
diff changeset
262 return __ec;
anatofuz
parents:
diff changeset
263 }
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
264 __ec = pthread_mutex_init(__m, &__attr);
150
anatofuz
parents:
diff changeset
265 if (__ec) {
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
266 pthread_mutexattr_destroy(&__attr);
150
anatofuz
parents:
diff changeset
267 return __ec;
anatofuz
parents:
diff changeset
268 }
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
269 __ec = pthread_mutexattr_destroy(&__attr);
150
anatofuz
parents:
diff changeset
270 if (__ec) {
anatofuz
parents:
diff changeset
271 pthread_mutex_destroy(__m);
anatofuz
parents:
diff changeset
272 return __ec;
anatofuz
parents:
diff changeset
273 }
anatofuz
parents:
diff changeset
274 return 0;
anatofuz
parents:
diff changeset
275 }
anatofuz
parents:
diff changeset
276
anatofuz
parents:
diff changeset
277 int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m)
anatofuz
parents:
diff changeset
278 {
anatofuz
parents:
diff changeset
279 return pthread_mutex_lock(__m);
anatofuz
parents:
diff changeset
280 }
anatofuz
parents:
diff changeset
281
anatofuz
parents:
diff changeset
282 bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m)
anatofuz
parents:
diff changeset
283 {
anatofuz
parents:
diff changeset
284 return pthread_mutex_trylock(__m) == 0;
anatofuz
parents:
diff changeset
285 }
anatofuz
parents:
diff changeset
286
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
287 int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m)
150
anatofuz
parents:
diff changeset
288 {
anatofuz
parents:
diff changeset
289 return pthread_mutex_unlock(__m);
anatofuz
parents:
diff changeset
290 }
anatofuz
parents:
diff changeset
291
anatofuz
parents:
diff changeset
292 int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m)
anatofuz
parents:
diff changeset
293 {
anatofuz
parents:
diff changeset
294 return pthread_mutex_destroy(__m);
anatofuz
parents:
diff changeset
295 }
anatofuz
parents:
diff changeset
296
anatofuz
parents:
diff changeset
297 int __libcpp_mutex_lock(__libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
298 {
anatofuz
parents:
diff changeset
299 return pthread_mutex_lock(__m);
anatofuz
parents:
diff changeset
300 }
anatofuz
parents:
diff changeset
301
anatofuz
parents:
diff changeset
302 bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
303 {
anatofuz
parents:
diff changeset
304 return pthread_mutex_trylock(__m) == 0;
anatofuz
parents:
diff changeset
305 }
anatofuz
parents:
diff changeset
306
anatofuz
parents:
diff changeset
307 int __libcpp_mutex_unlock(__libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
308 {
anatofuz
parents:
diff changeset
309 return pthread_mutex_unlock(__m);
anatofuz
parents:
diff changeset
310 }
anatofuz
parents:
diff changeset
311
anatofuz
parents:
diff changeset
312 int __libcpp_mutex_destroy(__libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
313 {
anatofuz
parents:
diff changeset
314 return pthread_mutex_destroy(__m);
anatofuz
parents:
diff changeset
315 }
anatofuz
parents:
diff changeset
316
anatofuz
parents:
diff changeset
317 // Condition Variable
anatofuz
parents:
diff changeset
318 int __libcpp_condvar_signal(__libcpp_condvar_t *__cv)
anatofuz
parents:
diff changeset
319 {
anatofuz
parents:
diff changeset
320 return pthread_cond_signal(__cv);
anatofuz
parents:
diff changeset
321 }
anatofuz
parents:
diff changeset
322
anatofuz
parents:
diff changeset
323 int __libcpp_condvar_broadcast(__libcpp_condvar_t *__cv)
anatofuz
parents:
diff changeset
324 {
anatofuz
parents:
diff changeset
325 return pthread_cond_broadcast(__cv);
anatofuz
parents:
diff changeset
326 }
anatofuz
parents:
diff changeset
327
anatofuz
parents:
diff changeset
328 int __libcpp_condvar_wait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
329 {
anatofuz
parents:
diff changeset
330 return pthread_cond_wait(__cv, __m);
anatofuz
parents:
diff changeset
331 }
anatofuz
parents:
diff changeset
332
anatofuz
parents:
diff changeset
333 int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,
anatofuz
parents:
diff changeset
334 __libcpp_timespec_t *__ts)
anatofuz
parents:
diff changeset
335 {
anatofuz
parents:
diff changeset
336 return pthread_cond_timedwait(__cv, __m, __ts);
anatofuz
parents:
diff changeset
337 }
anatofuz
parents:
diff changeset
338
anatofuz
parents:
diff changeset
339 int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv)
anatofuz
parents:
diff changeset
340 {
anatofuz
parents:
diff changeset
341 return pthread_cond_destroy(__cv);
anatofuz
parents:
diff changeset
342 }
anatofuz
parents:
diff changeset
343
anatofuz
parents:
diff changeset
344 // Execute once
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
345 int __libcpp_execute_once(__libcpp_exec_once_flag *__flag,
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
346 void (*__init_routine)()) {
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
347 return pthread_once(__flag, __init_routine);
150
anatofuz
parents:
diff changeset
348 }
anatofuz
parents:
diff changeset
349
anatofuz
parents:
diff changeset
350 // Thread id
anatofuz
parents:
diff changeset
351 // Returns non-zero if the thread ids are equal, otherwise 0
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
352 bool __libcpp_thread_id_equal(__libcpp_thread_id __t1, __libcpp_thread_id __t2)
150
anatofuz
parents:
diff changeset
353 {
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
354 return __t1 == __t2;
150
anatofuz
parents:
diff changeset
355 }
anatofuz
parents:
diff changeset
356
anatofuz
parents:
diff changeset
357 // Returns non-zero if t1 < t2, otherwise 0
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
358 bool __libcpp_thread_id_less(__libcpp_thread_id __t1, __libcpp_thread_id __t2)
150
anatofuz
parents:
diff changeset
359 {
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
360 return __t1 < __t2;
150
anatofuz
parents:
diff changeset
361 }
anatofuz
parents:
diff changeset
362
anatofuz
parents:
diff changeset
363 // Thread
anatofuz
parents:
diff changeset
364 bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) {
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
365 return __libcpp_thread_get_id(__t) == 0;
150
anatofuz
parents:
diff changeset
366 }
anatofuz
parents:
diff changeset
367
anatofuz
parents:
diff changeset
368 int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
anatofuz
parents:
diff changeset
369 void *__arg)
anatofuz
parents:
diff changeset
370 {
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
371 return pthread_create(__t, nullptr, __func, __arg);
150
anatofuz
parents:
diff changeset
372 }
anatofuz
parents:
diff changeset
373
anatofuz
parents:
diff changeset
374 __libcpp_thread_id __libcpp_thread_get_current_id()
anatofuz
parents:
diff changeset
375 {
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
376 const __libcpp_thread_t __current_thread = pthread_self();
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
377 return __libcpp_thread_get_id(&__current_thread);
150
anatofuz
parents:
diff changeset
378 }
anatofuz
parents:
diff changeset
379
anatofuz
parents:
diff changeset
380 __libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t)
anatofuz
parents:
diff changeset
381 {
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
382 #if defined(__MVS__)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
383 return __t->__;
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
384 #else
150
anatofuz
parents:
diff changeset
385 return *__t;
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
386 #endif
150
anatofuz
parents:
diff changeset
387 }
anatofuz
parents:
diff changeset
388
anatofuz
parents:
diff changeset
389 int __libcpp_thread_join(__libcpp_thread_t *__t)
anatofuz
parents:
diff changeset
390 {
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
391 return pthread_join(*__t, nullptr);
150
anatofuz
parents:
diff changeset
392 }
anatofuz
parents:
diff changeset
393
anatofuz
parents:
diff changeset
394 int __libcpp_thread_detach(__libcpp_thread_t *__t)
anatofuz
parents:
diff changeset
395 {
anatofuz
parents:
diff changeset
396 return pthread_detach(*__t);
anatofuz
parents:
diff changeset
397 }
anatofuz
parents:
diff changeset
398
anatofuz
parents:
diff changeset
399 void __libcpp_thread_yield()
anatofuz
parents:
diff changeset
400 {
anatofuz
parents:
diff changeset
401 sched_yield();
anatofuz
parents:
diff changeset
402 }
anatofuz
parents:
diff changeset
403
anatofuz
parents:
diff changeset
404 void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
anatofuz
parents:
diff changeset
405 {
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
406 __libcpp_timespec_t __ts = _VSTD::__convert_to_timespec<__libcpp_timespec_t>(__ns);
150
anatofuz
parents:
diff changeset
407 while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR);
anatofuz
parents:
diff changeset
408 }
anatofuz
parents:
diff changeset
409
anatofuz
parents:
diff changeset
410 // Thread local storage
anatofuz
parents:
diff changeset
411 int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *))
anatofuz
parents:
diff changeset
412 {
anatofuz
parents:
diff changeset
413 return pthread_key_create(__key, __at_exit);
anatofuz
parents:
diff changeset
414 }
anatofuz
parents:
diff changeset
415
anatofuz
parents:
diff changeset
416 void *__libcpp_tls_get(__libcpp_tls_key __key)
anatofuz
parents:
diff changeset
417 {
anatofuz
parents:
diff changeset
418 return pthread_getspecific(__key);
anatofuz
parents:
diff changeset
419 }
anatofuz
parents:
diff changeset
420
anatofuz
parents:
diff changeset
421 int __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
anatofuz
parents:
diff changeset
422 {
anatofuz
parents:
diff changeset
423 return pthread_setspecific(__key, __p);
anatofuz
parents:
diff changeset
424 }
anatofuz
parents:
diff changeset
425
anatofuz
parents:
diff changeset
426 #elif defined(_LIBCPP_HAS_THREAD_API_C11)
anatofuz
parents:
diff changeset
427
anatofuz
parents:
diff changeset
428 int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m)
anatofuz
parents:
diff changeset
429 {
anatofuz
parents:
diff changeset
430 return mtx_init(__m, mtx_plain | mtx_recursive) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
431 }
anatofuz
parents:
diff changeset
432
anatofuz
parents:
diff changeset
433 int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m)
anatofuz
parents:
diff changeset
434 {
anatofuz
parents:
diff changeset
435 return mtx_lock(__m) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
436 }
anatofuz
parents:
diff changeset
437
anatofuz
parents:
diff changeset
438 bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m)
anatofuz
parents:
diff changeset
439 {
anatofuz
parents:
diff changeset
440 return mtx_trylock(__m) == thrd_success;
anatofuz
parents:
diff changeset
441 }
anatofuz
parents:
diff changeset
442
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
443 int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m)
150
anatofuz
parents:
diff changeset
444 {
anatofuz
parents:
diff changeset
445 return mtx_unlock(__m) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
446 }
anatofuz
parents:
diff changeset
447
anatofuz
parents:
diff changeset
448 int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m)
anatofuz
parents:
diff changeset
449 {
anatofuz
parents:
diff changeset
450 mtx_destroy(__m);
anatofuz
parents:
diff changeset
451 return 0;
anatofuz
parents:
diff changeset
452 }
anatofuz
parents:
diff changeset
453
anatofuz
parents:
diff changeset
454 int __libcpp_mutex_lock(__libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
455 {
anatofuz
parents:
diff changeset
456 return mtx_lock(__m) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
457 }
anatofuz
parents:
diff changeset
458
anatofuz
parents:
diff changeset
459 bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
460 {
anatofuz
parents:
diff changeset
461 return mtx_trylock(__m) == thrd_success;
anatofuz
parents:
diff changeset
462 }
anatofuz
parents:
diff changeset
463
anatofuz
parents:
diff changeset
464 int __libcpp_mutex_unlock(__libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
465 {
anatofuz
parents:
diff changeset
466 return mtx_unlock(__m) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
467 }
anatofuz
parents:
diff changeset
468
anatofuz
parents:
diff changeset
469 int __libcpp_mutex_destroy(__libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
470 {
anatofuz
parents:
diff changeset
471 mtx_destroy(__m);
anatofuz
parents:
diff changeset
472 return 0;
anatofuz
parents:
diff changeset
473 }
anatofuz
parents:
diff changeset
474
anatofuz
parents:
diff changeset
475 // Condition Variable
anatofuz
parents:
diff changeset
476 int __libcpp_condvar_signal(__libcpp_condvar_t *__cv)
anatofuz
parents:
diff changeset
477 {
anatofuz
parents:
diff changeset
478 return cnd_signal(__cv) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
479 }
anatofuz
parents:
diff changeset
480
anatofuz
parents:
diff changeset
481 int __libcpp_condvar_broadcast(__libcpp_condvar_t *__cv)
anatofuz
parents:
diff changeset
482 {
anatofuz
parents:
diff changeset
483 return cnd_broadcast(__cv) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
484 }
anatofuz
parents:
diff changeset
485
anatofuz
parents:
diff changeset
486 int __libcpp_condvar_wait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
487 {
anatofuz
parents:
diff changeset
488 return cnd_wait(__cv, __m) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
489 }
anatofuz
parents:
diff changeset
490
anatofuz
parents:
diff changeset
491 int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,
anatofuz
parents:
diff changeset
492 timespec *__ts)
anatofuz
parents:
diff changeset
493 {
anatofuz
parents:
diff changeset
494 int __ec = cnd_timedwait(__cv, __m, __ts);
anatofuz
parents:
diff changeset
495 return __ec == thrd_timedout ? ETIMEDOUT : __ec;
anatofuz
parents:
diff changeset
496 }
anatofuz
parents:
diff changeset
497
anatofuz
parents:
diff changeset
498 int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv)
anatofuz
parents:
diff changeset
499 {
anatofuz
parents:
diff changeset
500 cnd_destroy(__cv);
anatofuz
parents:
diff changeset
501 return 0;
anatofuz
parents:
diff changeset
502 }
anatofuz
parents:
diff changeset
503
anatofuz
parents:
diff changeset
504 // Execute once
anatofuz
parents:
diff changeset
505 int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
anatofuz
parents:
diff changeset
506 void (*init_routine)(void)) {
anatofuz
parents:
diff changeset
507 ::call_once(flag, init_routine);
anatofuz
parents:
diff changeset
508 return 0;
anatofuz
parents:
diff changeset
509 }
anatofuz
parents:
diff changeset
510
anatofuz
parents:
diff changeset
511 // Thread id
anatofuz
parents:
diff changeset
512 // Returns non-zero if the thread ids are equal, otherwise 0
anatofuz
parents:
diff changeset
513 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2)
anatofuz
parents:
diff changeset
514 {
anatofuz
parents:
diff changeset
515 return thrd_equal(t1, t2) != 0;
anatofuz
parents:
diff changeset
516 }
anatofuz
parents:
diff changeset
517
anatofuz
parents:
diff changeset
518 // Returns non-zero if t1 < t2, otherwise 0
anatofuz
parents:
diff changeset
519 bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2)
anatofuz
parents:
diff changeset
520 {
anatofuz
parents:
diff changeset
521 return t1 < t2;
anatofuz
parents:
diff changeset
522 }
anatofuz
parents:
diff changeset
523
anatofuz
parents:
diff changeset
524 // Thread
anatofuz
parents:
diff changeset
525 bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) {
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
526 return __libcpp_thread_get_id(__t) == 0;
150
anatofuz
parents:
diff changeset
527 }
anatofuz
parents:
diff changeset
528
anatofuz
parents:
diff changeset
529 int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
anatofuz
parents:
diff changeset
530 void *__arg)
anatofuz
parents:
diff changeset
531 {
anatofuz
parents:
diff changeset
532 int __ec = thrd_create(__t, reinterpret_cast<thrd_start_t>(__func), __arg);
anatofuz
parents:
diff changeset
533 return __ec == thrd_nomem ? ENOMEM : __ec;
anatofuz
parents:
diff changeset
534 }
anatofuz
parents:
diff changeset
535
anatofuz
parents:
diff changeset
536 __libcpp_thread_id __libcpp_thread_get_current_id()
anatofuz
parents:
diff changeset
537 {
anatofuz
parents:
diff changeset
538 return thrd_current();
anatofuz
parents:
diff changeset
539 }
anatofuz
parents:
diff changeset
540
anatofuz
parents:
diff changeset
541 __libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t)
anatofuz
parents:
diff changeset
542 {
anatofuz
parents:
diff changeset
543 return *__t;
anatofuz
parents:
diff changeset
544 }
anatofuz
parents:
diff changeset
545
anatofuz
parents:
diff changeset
546 int __libcpp_thread_join(__libcpp_thread_t *__t)
anatofuz
parents:
diff changeset
547 {
anatofuz
parents:
diff changeset
548 return thrd_join(*__t, nullptr) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
549 }
anatofuz
parents:
diff changeset
550
anatofuz
parents:
diff changeset
551 int __libcpp_thread_detach(__libcpp_thread_t *__t)
anatofuz
parents:
diff changeset
552 {
anatofuz
parents:
diff changeset
553 return thrd_detach(*__t) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
554 }
anatofuz
parents:
diff changeset
555
anatofuz
parents:
diff changeset
556 void __libcpp_thread_yield()
anatofuz
parents:
diff changeset
557 {
anatofuz
parents:
diff changeset
558 thrd_yield();
anatofuz
parents:
diff changeset
559 }
anatofuz
parents:
diff changeset
560
anatofuz
parents:
diff changeset
561 void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
anatofuz
parents:
diff changeset
562 {
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
563 __libcpp_timespec_t __ts = _VSTD::__convert_to_timespec<__libcpp_timespec_t>(__ns);
150
anatofuz
parents:
diff changeset
564 thrd_sleep(&__ts, nullptr);
anatofuz
parents:
diff changeset
565 }
anatofuz
parents:
diff changeset
566
anatofuz
parents:
diff changeset
567 // Thread local storage
anatofuz
parents:
diff changeset
568 int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *))
anatofuz
parents:
diff changeset
569 {
anatofuz
parents:
diff changeset
570 return tss_create(__key, __at_exit) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
571 }
anatofuz
parents:
diff changeset
572
anatofuz
parents:
diff changeset
573 void *__libcpp_tls_get(__libcpp_tls_key __key)
anatofuz
parents:
diff changeset
574 {
anatofuz
parents:
diff changeset
575 return tss_get(__key);
anatofuz
parents:
diff changeset
576 }
anatofuz
parents:
diff changeset
577
anatofuz
parents:
diff changeset
578 int __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
anatofuz
parents:
diff changeset
579 {
anatofuz
parents:
diff changeset
580 return tss_set(__key, __p) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
581 }
anatofuz
parents:
diff changeset
582
anatofuz
parents:
diff changeset
583 #endif
anatofuz
parents:
diff changeset
584
anatofuz
parents:
diff changeset
585 #endif // !_LIBCPP_HAS_NO_THREADS
anatofuz
parents:
diff changeset
586
anatofuz
parents:
diff changeset
587 _LIBCPP_END_NAMESPACE_STD
anatofuz
parents:
diff changeset
588
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
589 #endif // _LIBCPP___THREADING_SUPPORT