annotate libcxx/include/__threading_support @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 0572611fdcc8
children c4bab56944e8
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
anatofuz
parents:
diff changeset
10 #ifndef _LIBCPP_THREADING_SUPPORT
anatofuz
parents:
diff changeset
11 #define _LIBCPP_THREADING_SUPPORT
anatofuz
parents:
diff changeset
12
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
13 #include <__availability>
150
anatofuz
parents:
diff changeset
14 #include <__config>
anatofuz
parents:
diff changeset
15 #include <chrono>
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
16 #include <errno.h>
150
anatofuz
parents:
diff changeset
17 #include <iosfwd>
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
18 #include <limits>
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
19
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
20 #ifdef __MVS__
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
21 # include <__support/ibm/nanosleep.h>
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
anatofuz
parents:
diff changeset
25 #pragma GCC system_header
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
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
32 #if defined(__APPLE__) || defined(__MVS__)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
33 # define _LIBCPP_NO_NATIVE_SEMAPHORES
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
34 #endif
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
35
150
anatofuz
parents:
diff changeset
36 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
anatofuz
parents:
diff changeset
37 # include <pthread.h>
anatofuz
parents:
diff changeset
38 # include <sched.h>
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
39 # ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
40 # include <semaphore.h>
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
41 # endif
150
anatofuz
parents:
diff changeset
42 #elif defined(_LIBCPP_HAS_THREAD_API_C11)
anatofuz
parents:
diff changeset
43 # include <threads.h>
anatofuz
parents:
diff changeset
44 #endif
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 #if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
anatofuz
parents:
diff changeset
47 defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL) || \
anatofuz
parents:
diff changeset
48 defined(_LIBCPP_HAS_THREAD_API_WIN32)
anatofuz
parents:
diff changeset
49 #define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS
anatofuz
parents:
diff changeset
50 #else
anatofuz
parents:
diff changeset
51 #define _LIBCPP_THREAD_ABI_VISIBILITY inline _LIBCPP_INLINE_VISIBILITY
anatofuz
parents:
diff changeset
52 #endif
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54 #if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(no_thread_safety_analysis)
anatofuz
parents:
diff changeset
55 #define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis))
anatofuz
parents:
diff changeset
56 #else
anatofuz
parents:
diff changeset
57 #define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
anatofuz
parents:
diff changeset
58 #endif
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 typedef ::timespec __libcpp_timespec_t;
anatofuz
parents:
diff changeset
61 #endif // !defined(_LIBCPP_HAS_NO_THREADS)
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 _LIBCPP_PUSH_MACROS
anatofuz
parents:
diff changeset
64 #include <__undef_macros>
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 _LIBCPP_BEGIN_NAMESPACE_STD
anatofuz
parents:
diff changeset
67
anatofuz
parents:
diff changeset
68 #if !defined(_LIBCPP_HAS_NO_THREADS)
anatofuz
parents:
diff changeset
69
anatofuz
parents:
diff changeset
70 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
anatofuz
parents:
diff changeset
71 // Mutex
anatofuz
parents:
diff changeset
72 typedef pthread_mutex_t __libcpp_mutex_t;
anatofuz
parents:
diff changeset
73 #define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
anatofuz
parents:
diff changeset
74
anatofuz
parents:
diff changeset
75 typedef pthread_mutex_t __libcpp_recursive_mutex_t;
anatofuz
parents:
diff changeset
76
anatofuz
parents:
diff changeset
77 // Condition Variable
anatofuz
parents:
diff changeset
78 typedef pthread_cond_t __libcpp_condvar_t;
anatofuz
parents:
diff changeset
79 #define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
anatofuz
parents:
diff changeset
80
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
81 #ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
82 // Semaphore
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
83 typedef sem_t __libcpp_semaphore_t;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
84 # define _LIBCPP_SEMAPHORE_MAX SEM_VALUE_MAX
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
85 #endif
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
86
150
anatofuz
parents:
diff changeset
87 // Execute once
anatofuz
parents:
diff changeset
88 typedef pthread_once_t __libcpp_exec_once_flag;
anatofuz
parents:
diff changeset
89 #define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
anatofuz
parents:
diff changeset
90
anatofuz
parents:
diff changeset
91 // Thread id
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
92 #if defined(__MVS__)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
93 typedef unsigned long long __libcpp_thread_id;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
94 #else
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
95 typedef pthread_t __libcpp_thread_id;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
96 #endif
150
anatofuz
parents:
diff changeset
97
anatofuz
parents:
diff changeset
98 // Thread
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
99 #define _LIBCPP_NULL_THREAD ((__libcpp_thread_t()))
150
anatofuz
parents:
diff changeset
100 typedef pthread_t __libcpp_thread_t;
anatofuz
parents:
diff changeset
101
anatofuz
parents:
diff changeset
102 // Thread Local Storage
anatofuz
parents:
diff changeset
103 typedef pthread_key_t __libcpp_tls_key;
anatofuz
parents:
diff changeset
104
anatofuz
parents:
diff changeset
105 #define _LIBCPP_TLS_DESTRUCTOR_CC
anatofuz
parents:
diff changeset
106 #elif defined(_LIBCPP_HAS_THREAD_API_C11)
anatofuz
parents:
diff changeset
107 // Mutex
anatofuz
parents:
diff changeset
108 typedef mtx_t __libcpp_mutex_t;
anatofuz
parents:
diff changeset
109 // mtx_t is a struct so using {} for initialization is valid.
anatofuz
parents:
diff changeset
110 #define _LIBCPP_MUTEX_INITIALIZER {}
anatofuz
parents:
diff changeset
111
anatofuz
parents:
diff changeset
112 typedef mtx_t __libcpp_recursive_mutex_t;
anatofuz
parents:
diff changeset
113
anatofuz
parents:
diff changeset
114 // Condition Variable
anatofuz
parents:
diff changeset
115 typedef cnd_t __libcpp_condvar_t;
anatofuz
parents:
diff changeset
116 // cnd_t is a struct so using {} for initialization is valid.
anatofuz
parents:
diff changeset
117 #define _LIBCPP_CONDVAR_INITIALIZER {}
anatofuz
parents:
diff changeset
118
anatofuz
parents:
diff changeset
119 // Execute once
anatofuz
parents:
diff changeset
120 typedef once_flag __libcpp_exec_once_flag;
anatofuz
parents:
diff changeset
121 #define _LIBCPP_EXEC_ONCE_INITIALIZER ONCE_FLAG_INIT
anatofuz
parents:
diff changeset
122
anatofuz
parents:
diff changeset
123 // Thread id
anatofuz
parents:
diff changeset
124 typedef thrd_t __libcpp_thread_id;
anatofuz
parents:
diff changeset
125
anatofuz
parents:
diff changeset
126 // Thread
anatofuz
parents:
diff changeset
127 #define _LIBCPP_NULL_THREAD 0U
anatofuz
parents:
diff changeset
128
anatofuz
parents:
diff changeset
129 typedef thrd_t __libcpp_thread_t;
anatofuz
parents:
diff changeset
130
anatofuz
parents:
diff changeset
131 // Thread Local Storage
anatofuz
parents:
diff changeset
132 typedef tss_t __libcpp_tls_key;
anatofuz
parents:
diff changeset
133
anatofuz
parents:
diff changeset
134 #define _LIBCPP_TLS_DESTRUCTOR_CC
anatofuz
parents:
diff changeset
135 #elif !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
anatofuz
parents:
diff changeset
136 // Mutex
anatofuz
parents:
diff changeset
137 typedef void* __libcpp_mutex_t;
anatofuz
parents:
diff changeset
138 #define _LIBCPP_MUTEX_INITIALIZER 0
anatofuz
parents:
diff changeset
139
anatofuz
parents:
diff changeset
140 #if defined(_M_IX86) || defined(__i386__) || defined(_M_ARM) || defined(__arm__)
anatofuz
parents:
diff changeset
141 typedef void* __libcpp_recursive_mutex_t[6];
anatofuz
parents:
diff changeset
142 #elif defined(_M_AMD64) || defined(__x86_64__) || defined(_M_ARM64) || defined(__aarch64__)
anatofuz
parents:
diff changeset
143 typedef void* __libcpp_recursive_mutex_t[5];
anatofuz
parents:
diff changeset
144 #else
anatofuz
parents:
diff changeset
145 # error Unsupported architecture
anatofuz
parents:
diff changeset
146 #endif
anatofuz
parents:
diff changeset
147
anatofuz
parents:
diff changeset
148 // Condition Variable
anatofuz
parents:
diff changeset
149 typedef void* __libcpp_condvar_t;
anatofuz
parents:
diff changeset
150 #define _LIBCPP_CONDVAR_INITIALIZER 0
anatofuz
parents:
diff changeset
151
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
152 // Semaphore
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
153 typedef void* __libcpp_semaphore_t;
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
154 #if defined(_LIBCPP_HAS_THREAD_API_WIN32)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
155 # define _LIBCPP_SEMAPHORE_MAX (::std::numeric_limits<long>::max())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
156 #endif
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
157
150
anatofuz
parents:
diff changeset
158 // Execute Once
anatofuz
parents:
diff changeset
159 typedef void* __libcpp_exec_once_flag;
anatofuz
parents:
diff changeset
160 #define _LIBCPP_EXEC_ONCE_INITIALIZER 0
anatofuz
parents:
diff changeset
161
anatofuz
parents:
diff changeset
162 // Thread ID
anatofuz
parents:
diff changeset
163 typedef long __libcpp_thread_id;
anatofuz
parents:
diff changeset
164
anatofuz
parents:
diff changeset
165 // Thread
anatofuz
parents:
diff changeset
166 #define _LIBCPP_NULL_THREAD 0U
anatofuz
parents:
diff changeset
167
anatofuz
parents:
diff changeset
168 typedef void* __libcpp_thread_t;
anatofuz
parents:
diff changeset
169
anatofuz
parents:
diff changeset
170 // Thread Local Storage
anatofuz
parents:
diff changeset
171 typedef long __libcpp_tls_key;
anatofuz
parents:
diff changeset
172
anatofuz
parents:
diff changeset
173 #define _LIBCPP_TLS_DESTRUCTOR_CC __stdcall
anatofuz
parents:
diff changeset
174 #endif // !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
anatofuz
parents:
diff changeset
175
anatofuz
parents:
diff changeset
176 #if !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
anatofuz
parents:
diff changeset
177 // Mutex
anatofuz
parents:
diff changeset
178 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
179 int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m);
anatofuz
parents:
diff changeset
180
anatofuz
parents:
diff changeset
181 _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
anatofuz
parents:
diff changeset
182 int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m);
anatofuz
parents:
diff changeset
183
anatofuz
parents:
diff changeset
184 _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
anatofuz
parents:
diff changeset
185 bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m);
anatofuz
parents:
diff changeset
186
anatofuz
parents:
diff changeset
187 _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
anatofuz
parents:
diff changeset
188 int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m);
anatofuz
parents:
diff changeset
189
anatofuz
parents:
diff changeset
190 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
191 int __libcpp_recursive_mutex_destroy(__libcpp_recursive_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_mutex_lock(__libcpp_mutex_t *__m);
anatofuz
parents:
diff changeset
195
anatofuz
parents:
diff changeset
196 _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
anatofuz
parents:
diff changeset
197 bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m);
anatofuz
parents:
diff changeset
198
anatofuz
parents:
diff changeset
199 _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
anatofuz
parents:
diff changeset
200 int __libcpp_mutex_unlock(__libcpp_mutex_t *__m);
anatofuz
parents:
diff changeset
201
anatofuz
parents:
diff changeset
202 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
203 int __libcpp_mutex_destroy(__libcpp_mutex_t *__m);
anatofuz
parents:
diff changeset
204
anatofuz
parents:
diff changeset
205 // Condition variable
anatofuz
parents:
diff changeset
206 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
207 int __libcpp_condvar_signal(__libcpp_condvar_t* __cv);
anatofuz
parents:
diff changeset
208
anatofuz
parents:
diff changeset
209 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
210 int __libcpp_condvar_broadcast(__libcpp_condvar_t* __cv);
anatofuz
parents:
diff changeset
211
anatofuz
parents:
diff changeset
212 _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
anatofuz
parents:
diff changeset
213 int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m);
anatofuz
parents:
diff changeset
214
anatofuz
parents:
diff changeset
215 _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
anatofuz
parents:
diff changeset
216 int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,
anatofuz
parents:
diff changeset
217 __libcpp_timespec_t *__ts);
anatofuz
parents:
diff changeset
218
anatofuz
parents:
diff changeset
219 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
220 int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv);
anatofuz
parents:
diff changeset
221
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
222 #ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
223
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
224 // Semaphore
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
225 _LIBCPP_THREAD_ABI_VISIBILITY
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
226 bool __libcpp_semaphore_init(__libcpp_semaphore_t* __sem, int __init);
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
227
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
228 _LIBCPP_THREAD_ABI_VISIBILITY
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
229 bool __libcpp_semaphore_destroy(__libcpp_semaphore_t* __sem);
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
230
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
231 _LIBCPP_THREAD_ABI_VISIBILITY
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
232 bool __libcpp_semaphore_post(__libcpp_semaphore_t* __sem);
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
233
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
234 _LIBCPP_THREAD_ABI_VISIBILITY
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
235 bool __libcpp_semaphore_wait(__libcpp_semaphore_t* __sem);
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
236
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
237 _LIBCPP_THREAD_ABI_VISIBILITY
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
238 bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem, chrono::nanoseconds const& __ns);
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
239
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
240 #endif // _LIBCPP_NO_NATIVE_SEMAPHORES
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
241
150
anatofuz
parents:
diff changeset
242 // Execute once
anatofuz
parents:
diff changeset
243 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
244 int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
anatofuz
parents:
diff changeset
245 void (*init_routine)());
anatofuz
parents:
diff changeset
246
anatofuz
parents:
diff changeset
247 // Thread id
anatofuz
parents:
diff changeset
248 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
249 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2);
anatofuz
parents:
diff changeset
250
anatofuz
parents:
diff changeset
251 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
252 bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2);
anatofuz
parents:
diff changeset
253
anatofuz
parents:
diff changeset
254 // Thread
anatofuz
parents:
diff changeset
255 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
256 bool __libcpp_thread_isnull(const __libcpp_thread_t *__t);
anatofuz
parents:
diff changeset
257
anatofuz
parents:
diff changeset
258 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
259 int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
anatofuz
parents:
diff changeset
260 void *__arg);
anatofuz
parents:
diff changeset
261
anatofuz
parents:
diff changeset
262 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
263 __libcpp_thread_id __libcpp_thread_get_current_id();
anatofuz
parents:
diff changeset
264
anatofuz
parents:
diff changeset
265 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
266 __libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t);
anatofuz
parents:
diff changeset
267
anatofuz
parents:
diff changeset
268 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
269 int __libcpp_thread_join(__libcpp_thread_t *__t);
anatofuz
parents:
diff changeset
270
anatofuz
parents:
diff changeset
271 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
272 int __libcpp_thread_detach(__libcpp_thread_t *__t);
anatofuz
parents:
diff changeset
273
anatofuz
parents:
diff changeset
274 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
275 void __libcpp_thread_yield();
anatofuz
parents:
diff changeset
276
anatofuz
parents:
diff changeset
277 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
278 void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns);
anatofuz
parents:
diff changeset
279
anatofuz
parents:
diff changeset
280 // Thread local storage
anatofuz
parents:
diff changeset
281 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
282 int __libcpp_tls_create(__libcpp_tls_key* __key,
anatofuz
parents:
diff changeset
283 void(_LIBCPP_TLS_DESTRUCTOR_CC* __at_exit)(void*));
anatofuz
parents:
diff changeset
284
anatofuz
parents:
diff changeset
285 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
286 void *__libcpp_tls_get(__libcpp_tls_key __key);
anatofuz
parents:
diff changeset
287
anatofuz
parents:
diff changeset
288 _LIBCPP_THREAD_ABI_VISIBILITY
anatofuz
parents:
diff changeset
289 int __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
anatofuz
parents:
diff changeset
290
anatofuz
parents:
diff changeset
291 #endif // !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
anatofuz
parents:
diff changeset
292
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
293 struct __libcpp_timed_backoff_policy {
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
294 _LIBCPP_INLINE_VISIBILITY
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
295 bool operator()(chrono::nanoseconds __elapsed) const
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
296 {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
297 if(__elapsed > chrono::milliseconds(128))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
298 __libcpp_thread_sleep_for(chrono::milliseconds(8));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
299 else if(__elapsed > chrono::microseconds(64))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
300 __libcpp_thread_sleep_for(__elapsed / 2);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
301 else if(__elapsed > chrono::microseconds(4))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
302 __libcpp_thread_yield();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
303 else
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
304 {} // poll
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
305 return false;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
306 }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
307 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
308
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
309 static _LIBCPP_CONSTEXPR const int __libcpp_polling_count = 64;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
310
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
311 template<class _Fn, class _BFn>
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
312 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
313 bool __libcpp_thread_poll_with_backoff(
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
314 _Fn && __f, _BFn && __bf, chrono::nanoseconds __max_elapsed = chrono::nanoseconds::zero())
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
315 {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
316 auto const __start = chrono::high_resolution_clock::now();
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
317 for(int __count = 0;;) {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
318 if(__f())
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
319 return true; // _Fn completion means success
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
320 if(__count < __libcpp_polling_count) {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
321 __count += 1;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
322 continue;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
323 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
324 chrono::nanoseconds const __elapsed = chrono::high_resolution_clock::now() - __start;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
325 if(__max_elapsed != chrono::nanoseconds::zero() && __max_elapsed < __elapsed)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
326 return false; // timeout failure
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
327 if(__bf(__elapsed))
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
328 return false; // _BFn completion means failure
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
329 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
330 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
331
150
anatofuz
parents:
diff changeset
332 #if (!defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
anatofuz
parents:
diff changeset
333 defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL))
anatofuz
parents:
diff changeset
334
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
335
150
anatofuz
parents:
diff changeset
336 namespace __thread_detail {
anatofuz
parents:
diff changeset
337
anatofuz
parents:
diff changeset
338 inline __libcpp_timespec_t __convert_to_timespec(const chrono::nanoseconds& __ns)
anatofuz
parents:
diff changeset
339 {
anatofuz
parents:
diff changeset
340 using namespace chrono;
anatofuz
parents:
diff changeset
341 seconds __s = duration_cast<seconds>(__ns);
anatofuz
parents:
diff changeset
342 __libcpp_timespec_t __ts;
anatofuz
parents:
diff changeset
343 typedef decltype(__ts.tv_sec) __ts_sec;
anatofuz
parents:
diff changeset
344 const __ts_sec __ts_sec_max = numeric_limits<__ts_sec>::max();
anatofuz
parents:
diff changeset
345
anatofuz
parents:
diff changeset
346 if (__s.count() < __ts_sec_max)
anatofuz
parents:
diff changeset
347 {
anatofuz
parents:
diff changeset
348 __ts.tv_sec = static_cast<__ts_sec>(__s.count());
anatofuz
parents:
diff changeset
349 __ts.tv_nsec = static_cast<decltype(__ts.tv_nsec)>((__ns - __s).count());
anatofuz
parents:
diff changeset
350 }
anatofuz
parents:
diff changeset
351 else
anatofuz
parents:
diff changeset
352 {
anatofuz
parents:
diff changeset
353 __ts.tv_sec = __ts_sec_max;
anatofuz
parents:
diff changeset
354 __ts.tv_nsec = 999999999; // (10^9 - 1)
anatofuz
parents:
diff changeset
355 }
anatofuz
parents:
diff changeset
356
anatofuz
parents:
diff changeset
357 return __ts;
anatofuz
parents:
diff changeset
358 }
anatofuz
parents:
diff changeset
359
anatofuz
parents:
diff changeset
360 }
anatofuz
parents:
diff changeset
361
anatofuz
parents:
diff changeset
362 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
anatofuz
parents:
diff changeset
363
anatofuz
parents:
diff changeset
364 int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m)
anatofuz
parents:
diff changeset
365 {
anatofuz
parents:
diff changeset
366 pthread_mutexattr_t attr;
anatofuz
parents:
diff changeset
367 int __ec = pthread_mutexattr_init(&attr);
anatofuz
parents:
diff changeset
368 if (__ec)
anatofuz
parents:
diff changeset
369 return __ec;
anatofuz
parents:
diff changeset
370 __ec = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
anatofuz
parents:
diff changeset
371 if (__ec) {
anatofuz
parents:
diff changeset
372 pthread_mutexattr_destroy(&attr);
anatofuz
parents:
diff changeset
373 return __ec;
anatofuz
parents:
diff changeset
374 }
anatofuz
parents:
diff changeset
375 __ec = pthread_mutex_init(__m, &attr);
anatofuz
parents:
diff changeset
376 if (__ec) {
anatofuz
parents:
diff changeset
377 pthread_mutexattr_destroy(&attr);
anatofuz
parents:
diff changeset
378 return __ec;
anatofuz
parents:
diff changeset
379 }
anatofuz
parents:
diff changeset
380 __ec = pthread_mutexattr_destroy(&attr);
anatofuz
parents:
diff changeset
381 if (__ec) {
anatofuz
parents:
diff changeset
382 pthread_mutex_destroy(__m);
anatofuz
parents:
diff changeset
383 return __ec;
anatofuz
parents:
diff changeset
384 }
anatofuz
parents:
diff changeset
385 return 0;
anatofuz
parents:
diff changeset
386 }
anatofuz
parents:
diff changeset
387
anatofuz
parents:
diff changeset
388 int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m)
anatofuz
parents:
diff changeset
389 {
anatofuz
parents:
diff changeset
390 return pthread_mutex_lock(__m);
anatofuz
parents:
diff changeset
391 }
anatofuz
parents:
diff changeset
392
anatofuz
parents:
diff changeset
393 bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m)
anatofuz
parents:
diff changeset
394 {
anatofuz
parents:
diff changeset
395 return pthread_mutex_trylock(__m) == 0;
anatofuz
parents:
diff changeset
396 }
anatofuz
parents:
diff changeset
397
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
398 int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m)
150
anatofuz
parents:
diff changeset
399 {
anatofuz
parents:
diff changeset
400 return pthread_mutex_unlock(__m);
anatofuz
parents:
diff changeset
401 }
anatofuz
parents:
diff changeset
402
anatofuz
parents:
diff changeset
403 int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m)
anatofuz
parents:
diff changeset
404 {
anatofuz
parents:
diff changeset
405 return pthread_mutex_destroy(__m);
anatofuz
parents:
diff changeset
406 }
anatofuz
parents:
diff changeset
407
anatofuz
parents:
diff changeset
408 int __libcpp_mutex_lock(__libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
409 {
anatofuz
parents:
diff changeset
410 return pthread_mutex_lock(__m);
anatofuz
parents:
diff changeset
411 }
anatofuz
parents:
diff changeset
412
anatofuz
parents:
diff changeset
413 bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
414 {
anatofuz
parents:
diff changeset
415 return pthread_mutex_trylock(__m) == 0;
anatofuz
parents:
diff changeset
416 }
anatofuz
parents:
diff changeset
417
anatofuz
parents:
diff changeset
418 int __libcpp_mutex_unlock(__libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
419 {
anatofuz
parents:
diff changeset
420 return pthread_mutex_unlock(__m);
anatofuz
parents:
diff changeset
421 }
anatofuz
parents:
diff changeset
422
anatofuz
parents:
diff changeset
423 int __libcpp_mutex_destroy(__libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
424 {
anatofuz
parents:
diff changeset
425 return pthread_mutex_destroy(__m);
anatofuz
parents:
diff changeset
426 }
anatofuz
parents:
diff changeset
427
anatofuz
parents:
diff changeset
428 // Condition Variable
anatofuz
parents:
diff changeset
429 int __libcpp_condvar_signal(__libcpp_condvar_t *__cv)
anatofuz
parents:
diff changeset
430 {
anatofuz
parents:
diff changeset
431 return pthread_cond_signal(__cv);
anatofuz
parents:
diff changeset
432 }
anatofuz
parents:
diff changeset
433
anatofuz
parents:
diff changeset
434 int __libcpp_condvar_broadcast(__libcpp_condvar_t *__cv)
anatofuz
parents:
diff changeset
435 {
anatofuz
parents:
diff changeset
436 return pthread_cond_broadcast(__cv);
anatofuz
parents:
diff changeset
437 }
anatofuz
parents:
diff changeset
438
anatofuz
parents:
diff changeset
439 int __libcpp_condvar_wait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
440 {
anatofuz
parents:
diff changeset
441 return pthread_cond_wait(__cv, __m);
anatofuz
parents:
diff changeset
442 }
anatofuz
parents:
diff changeset
443
anatofuz
parents:
diff changeset
444 int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,
anatofuz
parents:
diff changeset
445 __libcpp_timespec_t *__ts)
anatofuz
parents:
diff changeset
446 {
anatofuz
parents:
diff changeset
447 return pthread_cond_timedwait(__cv, __m, __ts);
anatofuz
parents:
diff changeset
448 }
anatofuz
parents:
diff changeset
449
anatofuz
parents:
diff changeset
450 int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv)
anatofuz
parents:
diff changeset
451 {
anatofuz
parents:
diff changeset
452 return pthread_cond_destroy(__cv);
anatofuz
parents:
diff changeset
453 }
anatofuz
parents:
diff changeset
454
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
455 #ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
456
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
457 // Semaphore
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
458 bool __libcpp_semaphore_init(__libcpp_semaphore_t* __sem, int __init)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
459 {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
460 return sem_init(__sem, 0, __init) == 0;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
461 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
462
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
463 bool __libcpp_semaphore_destroy(__libcpp_semaphore_t* __sem)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
464 {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
465 return sem_destroy(__sem) == 0;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
466 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
467
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
468 bool __libcpp_semaphore_post(__libcpp_semaphore_t* __sem)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
469 {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
470 return sem_post(__sem) == 0;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
471 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
472
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
473 bool __libcpp_semaphore_wait(__libcpp_semaphore_t* __sem)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
474 {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
475 return sem_wait(__sem) == 0;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
476 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
477
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
478 bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem, chrono::nanoseconds const& __ns)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
479 {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
480 auto const __abs_time = chrono::system_clock::now().time_since_epoch() + __ns;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
481 __libcpp_timespec_t __ts = __thread_detail::__convert_to_timespec(__abs_time);
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
482 return sem_timedwait(__sem, &__ts) == 0;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
483 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
484
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
485 #endif //_LIBCPP_NO_NATIVE_SEMAPHORES
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
486
150
anatofuz
parents:
diff changeset
487 // Execute once
anatofuz
parents:
diff changeset
488 int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
anatofuz
parents:
diff changeset
489 void (*init_routine)()) {
anatofuz
parents:
diff changeset
490 return pthread_once(flag, init_routine);
anatofuz
parents:
diff changeset
491 }
anatofuz
parents:
diff changeset
492
anatofuz
parents:
diff changeset
493 // Thread id
anatofuz
parents:
diff changeset
494 // Returns non-zero if the thread ids are equal, otherwise 0
anatofuz
parents:
diff changeset
495 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2)
anatofuz
parents:
diff changeset
496 {
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
497 return t1 == t2;
150
anatofuz
parents:
diff changeset
498 }
anatofuz
parents:
diff changeset
499
anatofuz
parents:
diff changeset
500 // Returns non-zero if t1 < t2, otherwise 0
anatofuz
parents:
diff changeset
501 bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2)
anatofuz
parents:
diff changeset
502 {
anatofuz
parents:
diff changeset
503 return t1 < t2;
anatofuz
parents:
diff changeset
504 }
anatofuz
parents:
diff changeset
505
anatofuz
parents:
diff changeset
506 // Thread
anatofuz
parents:
diff changeset
507 bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) {
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
508 return __libcpp_thread_get_id(__t) == 0;
150
anatofuz
parents:
diff changeset
509 }
anatofuz
parents:
diff changeset
510
anatofuz
parents:
diff changeset
511 int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
anatofuz
parents:
diff changeset
512 void *__arg)
anatofuz
parents:
diff changeset
513 {
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
514 return pthread_create(__t, nullptr, __func, __arg);
150
anatofuz
parents:
diff changeset
515 }
anatofuz
parents:
diff changeset
516
anatofuz
parents:
diff changeset
517 __libcpp_thread_id __libcpp_thread_get_current_id()
anatofuz
parents:
diff changeset
518 {
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
519 const __libcpp_thread_t thread = pthread_self();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
520 return __libcpp_thread_get_id(&thread);
150
anatofuz
parents:
diff changeset
521 }
anatofuz
parents:
diff changeset
522
anatofuz
parents:
diff changeset
523 __libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t)
anatofuz
parents:
diff changeset
524 {
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
525 #if defined(__MVS__)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
526 return __t->__;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
527 #else
150
anatofuz
parents:
diff changeset
528 return *__t;
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
529 #endif
150
anatofuz
parents:
diff changeset
530 }
anatofuz
parents:
diff changeset
531
anatofuz
parents:
diff changeset
532 int __libcpp_thread_join(__libcpp_thread_t *__t)
anatofuz
parents:
diff changeset
533 {
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
534 return pthread_join(*__t, nullptr);
150
anatofuz
parents:
diff changeset
535 }
anatofuz
parents:
diff changeset
536
anatofuz
parents:
diff changeset
537 int __libcpp_thread_detach(__libcpp_thread_t *__t)
anatofuz
parents:
diff changeset
538 {
anatofuz
parents:
diff changeset
539 return pthread_detach(*__t);
anatofuz
parents:
diff changeset
540 }
anatofuz
parents:
diff changeset
541
anatofuz
parents:
diff changeset
542 void __libcpp_thread_yield()
anatofuz
parents:
diff changeset
543 {
anatofuz
parents:
diff changeset
544 sched_yield();
anatofuz
parents:
diff changeset
545 }
anatofuz
parents:
diff changeset
546
anatofuz
parents:
diff changeset
547 void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
anatofuz
parents:
diff changeset
548 {
anatofuz
parents:
diff changeset
549 __libcpp_timespec_t __ts = __thread_detail::__convert_to_timespec(__ns);
anatofuz
parents:
diff changeset
550 while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR);
anatofuz
parents:
diff changeset
551 }
anatofuz
parents:
diff changeset
552
anatofuz
parents:
diff changeset
553 // Thread local storage
anatofuz
parents:
diff changeset
554 int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *))
anatofuz
parents:
diff changeset
555 {
anatofuz
parents:
diff changeset
556 return pthread_key_create(__key, __at_exit);
anatofuz
parents:
diff changeset
557 }
anatofuz
parents:
diff changeset
558
anatofuz
parents:
diff changeset
559 void *__libcpp_tls_get(__libcpp_tls_key __key)
anatofuz
parents:
diff changeset
560 {
anatofuz
parents:
diff changeset
561 return pthread_getspecific(__key);
anatofuz
parents:
diff changeset
562 }
anatofuz
parents:
diff changeset
563
anatofuz
parents:
diff changeset
564 int __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
anatofuz
parents:
diff changeset
565 {
anatofuz
parents:
diff changeset
566 return pthread_setspecific(__key, __p);
anatofuz
parents:
diff changeset
567 }
anatofuz
parents:
diff changeset
568
anatofuz
parents:
diff changeset
569 #elif defined(_LIBCPP_HAS_THREAD_API_C11)
anatofuz
parents:
diff changeset
570
anatofuz
parents:
diff changeset
571 int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m)
anatofuz
parents:
diff changeset
572 {
anatofuz
parents:
diff changeset
573 return mtx_init(__m, mtx_plain | mtx_recursive) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
574 }
anatofuz
parents:
diff changeset
575
anatofuz
parents:
diff changeset
576 int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m)
anatofuz
parents:
diff changeset
577 {
anatofuz
parents:
diff changeset
578 return mtx_lock(__m) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
579 }
anatofuz
parents:
diff changeset
580
anatofuz
parents:
diff changeset
581 bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m)
anatofuz
parents:
diff changeset
582 {
anatofuz
parents:
diff changeset
583 return mtx_trylock(__m) == thrd_success;
anatofuz
parents:
diff changeset
584 }
anatofuz
parents:
diff changeset
585
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
586 int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m)
150
anatofuz
parents:
diff changeset
587 {
anatofuz
parents:
diff changeset
588 return mtx_unlock(__m) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
589 }
anatofuz
parents:
diff changeset
590
anatofuz
parents:
diff changeset
591 int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m)
anatofuz
parents:
diff changeset
592 {
anatofuz
parents:
diff changeset
593 mtx_destroy(__m);
anatofuz
parents:
diff changeset
594 return 0;
anatofuz
parents:
diff changeset
595 }
anatofuz
parents:
diff changeset
596
anatofuz
parents:
diff changeset
597 int __libcpp_mutex_lock(__libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
598 {
anatofuz
parents:
diff changeset
599 return mtx_lock(__m) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
600 }
anatofuz
parents:
diff changeset
601
anatofuz
parents:
diff changeset
602 bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
603 {
anatofuz
parents:
diff changeset
604 return mtx_trylock(__m) == thrd_success;
anatofuz
parents:
diff changeset
605 }
anatofuz
parents:
diff changeset
606
anatofuz
parents:
diff changeset
607 int __libcpp_mutex_unlock(__libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
608 {
anatofuz
parents:
diff changeset
609 return mtx_unlock(__m) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
610 }
anatofuz
parents:
diff changeset
611
anatofuz
parents:
diff changeset
612 int __libcpp_mutex_destroy(__libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
613 {
anatofuz
parents:
diff changeset
614 mtx_destroy(__m);
anatofuz
parents:
diff changeset
615 return 0;
anatofuz
parents:
diff changeset
616 }
anatofuz
parents:
diff changeset
617
anatofuz
parents:
diff changeset
618 // Condition Variable
anatofuz
parents:
diff changeset
619 int __libcpp_condvar_signal(__libcpp_condvar_t *__cv)
anatofuz
parents:
diff changeset
620 {
anatofuz
parents:
diff changeset
621 return cnd_signal(__cv) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
622 }
anatofuz
parents:
diff changeset
623
anatofuz
parents:
diff changeset
624 int __libcpp_condvar_broadcast(__libcpp_condvar_t *__cv)
anatofuz
parents:
diff changeset
625 {
anatofuz
parents:
diff changeset
626 return cnd_broadcast(__cv) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
627 }
anatofuz
parents:
diff changeset
628
anatofuz
parents:
diff changeset
629 int __libcpp_condvar_wait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m)
anatofuz
parents:
diff changeset
630 {
anatofuz
parents:
diff changeset
631 return cnd_wait(__cv, __m) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
632 }
anatofuz
parents:
diff changeset
633
anatofuz
parents:
diff changeset
634 int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,
anatofuz
parents:
diff changeset
635 timespec *__ts)
anatofuz
parents:
diff changeset
636 {
anatofuz
parents:
diff changeset
637 int __ec = cnd_timedwait(__cv, __m, __ts);
anatofuz
parents:
diff changeset
638 return __ec == thrd_timedout ? ETIMEDOUT : __ec;
anatofuz
parents:
diff changeset
639 }
anatofuz
parents:
diff changeset
640
anatofuz
parents:
diff changeset
641 int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv)
anatofuz
parents:
diff changeset
642 {
anatofuz
parents:
diff changeset
643 cnd_destroy(__cv);
anatofuz
parents:
diff changeset
644 return 0;
anatofuz
parents:
diff changeset
645 }
anatofuz
parents:
diff changeset
646
anatofuz
parents:
diff changeset
647 // Execute once
anatofuz
parents:
diff changeset
648 int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
anatofuz
parents:
diff changeset
649 void (*init_routine)(void)) {
anatofuz
parents:
diff changeset
650 ::call_once(flag, init_routine);
anatofuz
parents:
diff changeset
651 return 0;
anatofuz
parents:
diff changeset
652 }
anatofuz
parents:
diff changeset
653
anatofuz
parents:
diff changeset
654 // Thread id
anatofuz
parents:
diff changeset
655 // Returns non-zero if the thread ids are equal, otherwise 0
anatofuz
parents:
diff changeset
656 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2)
anatofuz
parents:
diff changeset
657 {
anatofuz
parents:
diff changeset
658 return thrd_equal(t1, t2) != 0;
anatofuz
parents:
diff changeset
659 }
anatofuz
parents:
diff changeset
660
anatofuz
parents:
diff changeset
661 // Returns non-zero if t1 < t2, otherwise 0
anatofuz
parents:
diff changeset
662 bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2)
anatofuz
parents:
diff changeset
663 {
anatofuz
parents:
diff changeset
664 return t1 < t2;
anatofuz
parents:
diff changeset
665 }
anatofuz
parents:
diff changeset
666
anatofuz
parents:
diff changeset
667 // Thread
anatofuz
parents:
diff changeset
668 bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) {
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
669 return __libcpp_thread_get_id(__t) == 0;
150
anatofuz
parents:
diff changeset
670 }
anatofuz
parents:
diff changeset
671
anatofuz
parents:
diff changeset
672 int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
anatofuz
parents:
diff changeset
673 void *__arg)
anatofuz
parents:
diff changeset
674 {
anatofuz
parents:
diff changeset
675 int __ec = thrd_create(__t, reinterpret_cast<thrd_start_t>(__func), __arg);
anatofuz
parents:
diff changeset
676 return __ec == thrd_nomem ? ENOMEM : __ec;
anatofuz
parents:
diff changeset
677 }
anatofuz
parents:
diff changeset
678
anatofuz
parents:
diff changeset
679 __libcpp_thread_id __libcpp_thread_get_current_id()
anatofuz
parents:
diff changeset
680 {
anatofuz
parents:
diff changeset
681 return thrd_current();
anatofuz
parents:
diff changeset
682 }
anatofuz
parents:
diff changeset
683
anatofuz
parents:
diff changeset
684 __libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t)
anatofuz
parents:
diff changeset
685 {
anatofuz
parents:
diff changeset
686 return *__t;
anatofuz
parents:
diff changeset
687 }
anatofuz
parents:
diff changeset
688
anatofuz
parents:
diff changeset
689 int __libcpp_thread_join(__libcpp_thread_t *__t)
anatofuz
parents:
diff changeset
690 {
anatofuz
parents:
diff changeset
691 return thrd_join(*__t, nullptr) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
692 }
anatofuz
parents:
diff changeset
693
anatofuz
parents:
diff changeset
694 int __libcpp_thread_detach(__libcpp_thread_t *__t)
anatofuz
parents:
diff changeset
695 {
anatofuz
parents:
diff changeset
696 return thrd_detach(*__t) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
697 }
anatofuz
parents:
diff changeset
698
anatofuz
parents:
diff changeset
699 void __libcpp_thread_yield()
anatofuz
parents:
diff changeset
700 {
anatofuz
parents:
diff changeset
701 thrd_yield();
anatofuz
parents:
diff changeset
702 }
anatofuz
parents:
diff changeset
703
anatofuz
parents:
diff changeset
704 void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
anatofuz
parents:
diff changeset
705 {
anatofuz
parents:
diff changeset
706 __libcpp_timespec_t __ts = __thread_detail::__convert_to_timespec(__ns);
anatofuz
parents:
diff changeset
707 thrd_sleep(&__ts, nullptr);
anatofuz
parents:
diff changeset
708 }
anatofuz
parents:
diff changeset
709
anatofuz
parents:
diff changeset
710 // Thread local storage
anatofuz
parents:
diff changeset
711 int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *))
anatofuz
parents:
diff changeset
712 {
anatofuz
parents:
diff changeset
713 return tss_create(__key, __at_exit) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
714 }
anatofuz
parents:
diff changeset
715
anatofuz
parents:
diff changeset
716 void *__libcpp_tls_get(__libcpp_tls_key __key)
anatofuz
parents:
diff changeset
717 {
anatofuz
parents:
diff changeset
718 return tss_get(__key);
anatofuz
parents:
diff changeset
719 }
anatofuz
parents:
diff changeset
720
anatofuz
parents:
diff changeset
721 int __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
anatofuz
parents:
diff changeset
722 {
anatofuz
parents:
diff changeset
723 return tss_set(__key, __p) == thrd_success ? 0 : EINVAL;
anatofuz
parents:
diff changeset
724 }
anatofuz
parents:
diff changeset
725
anatofuz
parents:
diff changeset
726 #endif
anatofuz
parents:
diff changeset
727
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
728
150
anatofuz
parents:
diff changeset
729 #endif // !_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL || _LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL
anatofuz
parents:
diff changeset
730
anatofuz
parents:
diff changeset
731 class _LIBCPP_TYPE_VIS thread;
anatofuz
parents:
diff changeset
732 class _LIBCPP_TYPE_VIS __thread_id;
anatofuz
parents:
diff changeset
733
anatofuz
parents:
diff changeset
734 namespace this_thread
anatofuz
parents:
diff changeset
735 {
anatofuz
parents:
diff changeset
736
anatofuz
parents:
diff changeset
737 _LIBCPP_INLINE_VISIBILITY __thread_id get_id() _NOEXCEPT;
anatofuz
parents:
diff changeset
738
anatofuz
parents:
diff changeset
739 } // this_thread
anatofuz
parents:
diff changeset
740
anatofuz
parents:
diff changeset
741 template<> struct hash<__thread_id>;
anatofuz
parents:
diff changeset
742
anatofuz
parents:
diff changeset
743 class _LIBCPP_TEMPLATE_VIS __thread_id
anatofuz
parents:
diff changeset
744 {
anatofuz
parents:
diff changeset
745 // FIXME: pthread_t is a pointer on Darwin but a long on Linux.
anatofuz
parents:
diff changeset
746 // NULL is the no-thread value on Darwin. Someone needs to check
anatofuz
parents:
diff changeset
747 // on other platforms. We assume 0 works everywhere for now.
anatofuz
parents:
diff changeset
748 __libcpp_thread_id __id_;
anatofuz
parents:
diff changeset
749
anatofuz
parents:
diff changeset
750 public:
anatofuz
parents:
diff changeset
751 _LIBCPP_INLINE_VISIBILITY
anatofuz
parents:
diff changeset
752 __thread_id() _NOEXCEPT : __id_(0) {}
anatofuz
parents:
diff changeset
753
anatofuz
parents:
diff changeset
754 friend _LIBCPP_INLINE_VISIBILITY
anatofuz
parents:
diff changeset
755 bool operator==(__thread_id __x, __thread_id __y) _NOEXCEPT
anatofuz
parents:
diff changeset
756 { // don't pass id==0 to underlying routines
anatofuz
parents:
diff changeset
757 if (__x.__id_ == 0) return __y.__id_ == 0;
anatofuz
parents:
diff changeset
758 if (__y.__id_ == 0) return false;
anatofuz
parents:
diff changeset
759 return __libcpp_thread_id_equal(__x.__id_, __y.__id_);
anatofuz
parents:
diff changeset
760 }
anatofuz
parents:
diff changeset
761 friend _LIBCPP_INLINE_VISIBILITY
anatofuz
parents:
diff changeset
762 bool operator!=(__thread_id __x, __thread_id __y) _NOEXCEPT
anatofuz
parents:
diff changeset
763 {return !(__x == __y);}
anatofuz
parents:
diff changeset
764 friend _LIBCPP_INLINE_VISIBILITY
anatofuz
parents:
diff changeset
765 bool operator< (__thread_id __x, __thread_id __y) _NOEXCEPT
anatofuz
parents:
diff changeset
766 { // id==0 is always less than any other thread_id
anatofuz
parents:
diff changeset
767 if (__x.__id_ == 0) return __y.__id_ != 0;
anatofuz
parents:
diff changeset
768 if (__y.__id_ == 0) return false;
anatofuz
parents:
diff changeset
769 return __libcpp_thread_id_less(__x.__id_, __y.__id_);
anatofuz
parents:
diff changeset
770 }
anatofuz
parents:
diff changeset
771 friend _LIBCPP_INLINE_VISIBILITY
anatofuz
parents:
diff changeset
772 bool operator<=(__thread_id __x, __thread_id __y) _NOEXCEPT
anatofuz
parents:
diff changeset
773 {return !(__y < __x);}
anatofuz
parents:
diff changeset
774 friend _LIBCPP_INLINE_VISIBILITY
anatofuz
parents:
diff changeset
775 bool operator> (__thread_id __x, __thread_id __y) _NOEXCEPT
anatofuz
parents:
diff changeset
776 {return __y < __x ;}
anatofuz
parents:
diff changeset
777 friend _LIBCPP_INLINE_VISIBILITY
anatofuz
parents:
diff changeset
778 bool operator>=(__thread_id __x, __thread_id __y) _NOEXCEPT
anatofuz
parents:
diff changeset
779 {return !(__x < __y);}
anatofuz
parents:
diff changeset
780
anatofuz
parents:
diff changeset
781 _LIBCPP_INLINE_VISIBILITY
anatofuz
parents:
diff changeset
782 void __reset() { __id_ = 0; }
anatofuz
parents:
diff changeset
783
anatofuz
parents:
diff changeset
784 template<class _CharT, class _Traits>
anatofuz
parents:
diff changeset
785 friend
anatofuz
parents:
diff changeset
786 _LIBCPP_INLINE_VISIBILITY
anatofuz
parents:
diff changeset
787 basic_ostream<_CharT, _Traits>&
anatofuz
parents:
diff changeset
788 operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id);
anatofuz
parents:
diff changeset
789
anatofuz
parents:
diff changeset
790 private:
anatofuz
parents:
diff changeset
791 _LIBCPP_INLINE_VISIBILITY
anatofuz
parents:
diff changeset
792 __thread_id(__libcpp_thread_id __id) : __id_(__id) {}
anatofuz
parents:
diff changeset
793
anatofuz
parents:
diff changeset
794 friend __thread_id this_thread::get_id() _NOEXCEPT;
anatofuz
parents:
diff changeset
795 friend class _LIBCPP_TYPE_VIS thread;
anatofuz
parents:
diff changeset
796 friend struct _LIBCPP_TEMPLATE_VIS hash<__thread_id>;
anatofuz
parents:
diff changeset
797 };
anatofuz
parents:
diff changeset
798
anatofuz
parents:
diff changeset
799 namespace this_thread
anatofuz
parents:
diff changeset
800 {
anatofuz
parents:
diff changeset
801
anatofuz
parents:
diff changeset
802 inline _LIBCPP_INLINE_VISIBILITY
anatofuz
parents:
diff changeset
803 __thread_id
anatofuz
parents:
diff changeset
804 get_id() _NOEXCEPT
anatofuz
parents:
diff changeset
805 {
anatofuz
parents:
diff changeset
806 return __libcpp_thread_get_current_id();
anatofuz
parents:
diff changeset
807 }
anatofuz
parents:
diff changeset
808
anatofuz
parents:
diff changeset
809 } // this_thread
anatofuz
parents:
diff changeset
810
anatofuz
parents:
diff changeset
811 #endif // !_LIBCPP_HAS_NO_THREADS
anatofuz
parents:
diff changeset
812
anatofuz
parents:
diff changeset
813 _LIBCPP_END_NAMESPACE_STD
anatofuz
parents:
diff changeset
814
anatofuz
parents:
diff changeset
815 _LIBCPP_POP_MACROS
anatofuz
parents:
diff changeset
816
anatofuz
parents:
diff changeset
817 #endif // _LIBCPP_THREADING_SUPPORT