30 #ifndef _GLIBCXX_THREAD_H 31 #define _GLIBCXX_THREAD_H 1 33 #pragma GCC system_header 35 #if __cplusplus >= 201103L 45 #ifdef _GLIBCXX_HAS_GTHREADS 46 # include <bits/gthr.h> 52 namespace std _GLIBCXX_VISIBILITY(default)
54 _GLIBCXX_BEGIN_NAMESPACE_VERSION
56 #if __glibcxx_formatters 57 template<
typename,
typename>
class formatter;
85 #ifdef _GLIBCXX_HAS_GTHREADS 86 using native_handle_type = __gthread_t;
88 using native_handle_type = int;
98 native_handle_type _M_thread;
101 id() noexcept : _M_thread() { }
104 id(native_handle_type __id) : _M_thread(__id) { }
111 operator==(
id __x,
id __y) noexcept;
113 #if __cpp_lib_three_way_comparison 114 friend strong_ordering
115 operator<=>(
id __x,
id __y) noexcept;
121 template<
class _CharT,
class _Traits>
123 operator<<(basic_ostream<_CharT, _Traits>& __out,
id __id);
125 #if __glibcxx_formatters 126 friend formatter<id, char>;
127 friend formatter<id, wchar_t>;
137 template<
typename _Tp>
138 using __not_same = __not_<is_same<__remove_cvref_t<_Tp>,
thread>>;
141 thread() noexcept = default;
143 #ifdef _GLIBCXX_HAS_GTHREADS 152 _M_thread_deps_never_run() {
153 #ifdef GTHR_ACTIVE_PROXY 154 reinterpret_cast<void (*)(
void)
>(&pthread_create)();
155 reinterpret_cast<void (*)(
void)
>(&pthread_join)();
160 template<
typename _Callable,
typename... _Args,
161 typename = _Require<__not_same<_Callable>>>
163 thread(_Callable&& __f, _Args&&... __args)
165 static_assert( __is_invocable<
typename decay<_Callable>::type,
166 typename decay<_Args>::type...>::value,
167 "std::thread arguments must be invocable after conversion to rvalues" 170 using _Wrapper = _Call_wrapper<_Callable, _Args...>;
173 _M_start_thread(_State_ptr(
new _State_impl<_Wrapper>(
174 std::forward<_Callable>(__f), std::forward<_Args>(__args)...)),
175 _M_thread_deps_never_run);
177 #endif // _GLIBCXX_HAS_GTHREADS 185 thread(
const thread&) =
delete;
187 thread(thread&& __t) noexcept
190 thread& operator=(
const thread&) =
delete;
192 thread& operator=(thread&& __t) noexcept
201 swap(thread& __t) noexcept
202 { std::swap(_M_id, __t._M_id); }
205 joinable() const noexcept
206 {
return !(_M_id == id()); }
222 {
return _M_id._M_thread; }
226 hardware_concurrency() noexcept;
228 #ifdef _GLIBCXX_HAS_GTHREADS 229 #ifndef _GLIBCXX_THREAD_IMPL 237 virtual void _M_run() = 0;
239 using _State_ptr = unique_ptr<_State>;
242 template<
typename _Callable>
243 struct _State_impl :
public _State
247 template<
typename... _Args>
248 _State_impl(_Args&&... __args)
253 _M_run() { _M_func(); }
257 _M_start_thread(_State_ptr,
void (*)());
259 #if _GLIBCXX_THREAD_ABI_COMPAT 262 typedef shared_ptr<_Impl_base> __shared_base_type;
265 __shared_base_type _M_this_ptr;
266 virtual ~_Impl_base() =
default;
267 virtual void _M_run() = 0;
272 _M_start_thread(__shared_base_type,
void (*)());
275 _M_start_thread(__shared_base_type);
280 template<
typename _Tuple>
283 template<
typename... _Args>
285 _Invoker(_Args&&... __args)
293 template<
typename _Fn,
typename... _Args>
294 struct __result<tuple<_Fn, _Args...>>
295 : __invoke_result<_Fn, _Args...>
298 template<
size_t... _Ind>
299 typename __result<_Tuple>::type
300 _M_invoke(_Index_tuple<_Ind...>)
303 typename __result<_Tuple>::type
307 =
typename _Build_index_tuple<tuple_size<_Tuple>::value>::__type;
308 return _M_invoke(_Indices());
314 template<
typename... _Tp>
315 using _Call_wrapper = _Invoker<tuple<typename decay<_Tp>::type...>>;
317 #endif // _GLIBCXX_HAS_GTHREADS 320 #ifndef _GLIBCXX_HAS_GTHREADS 321 inline void thread::join() { std::__throw_system_error(EINVAL); }
322 inline void thread::detach() { std::__throw_system_error(EINVAL); }
323 inline unsigned int thread::hardware_concurrency() noexcept {
return 0; }
339 return __x._M_thread == __y._M_thread;
348 :
public __hash_base<size_t, thread::id>
351 operator()(
const thread::id& __id)
const noexcept
352 {
return std::_Hash_impl::hash(__id._M_thread); }
355 namespace this_thread
361 #ifndef _GLIBCXX_HAS_GTHREADS 363 #elif defined _GLIBCXX_NATIVE_THREAD_ID 374 #if defined _GLIBCXX_HAS_GTHREADS && defined _GLIBCXX_USE_SCHED_YIELD 383 _GLIBCXX_END_NAMESPACE_VERSION
387 #endif // _GLIBCXX_THREAD_H ISO C++ entities toplevel namespace is std.
constexpr __invoke_result< _Callable, _Args... >::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_invocable< _Callable, _Args... >::value)
Invoke a callable object.
void swap(thread &__x, thread &__y) noexcept
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
native_handle_type native_handle()
void yield() noexcept
Allow the implementation to schedule a different thread.
bool operator==(thread::id __x, thread::id __y) noexcept
Primary class template hash.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Template class basic_ostream.
thread::id get_id() noexcept
The unique identifier of the current thread.
constexpr bool operator<(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)