29 #ifndef _GLIBCXX_THREAD 30 #define _GLIBCXX_THREAD 1 32 #pragma GCC system_header 34 #if __cplusplus < 201103L 44 #include <bits/gthr.h> 46 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) 48 namespace std _GLIBCXX_VISIBILITY(default)
50 _GLIBCXX_BEGIN_NAMESPACE_VERSION
69 virtual void _M_run() = 0;
73 typedef __gthread_t native_handle_type;
78 native_handle_type _M_thread;
81 id() noexcept : _M_thread() { }
84 id(native_handle_type __id) : _M_thread(__id) { }
88 friend class hash<thread::
id>;
91 operator==(thread::id __x, thread::id __y) noexcept
97 return __x._M_thread == __y._M_thread;
105 return __x._M_thread < __y._M_thread;
108 template<
class _CharT,
class _Traits>
110 operator<<(basic_ostream<_CharT, _Traits>& __out,
thread::id __id);
117 thread() noexcept =
default;
127 template<
typename _Callable,
typename... _Args>
129 thread(_Callable&& __f, _Args&&... __args)
131 #ifdef GTHR_ACTIVE_PROXY 133 auto __depend =
reinterpret_cast<void(*)()
>(&pthread_create);
135 auto __depend =
nullptr;
137 _M_start_thread(_S_make_state(
138 std::__bind_simple(std::forward<_Callable>(__f),
139 std::forward<_Args>(__args)...)),
160 swap(
thread& __t) noexcept
161 { std::swap(_M_id, __t._M_id); }
164 joinable()
const noexcept
165 {
return !(_M_id ==
id()); }
174 get_id()
const noexcept
181 {
return _M_id._M_thread; }
185 hardware_concurrency() noexcept;
188 template<
typename _Callable>
189 struct _State_impl :
public _State
193 _State_impl(_Callable&& __f) : _M_func(std::forward<_Callable>(__f))
197 _M_run() { _M_func(); }
203 template<
typename _Callable>
205 _S_make_state(_Callable&& __f)
207 using _Impl = _State_impl<_Callable>;
208 return _State_ptr{
new _Impl{std::forward<_Callable>(__f)}};
210 #if _GLIBCXX_THREAD_ABI_COMPAT 216 __shared_base_type _M_this_ptr;
217 virtual ~_Impl_base() =
default;
218 virtual void _M_run() = 0;
223 _M_start_thread(__shared_base_type,
void (*)());
226 _M_start_thread(__shared_base_type);
236 {
return !(__x == __y); }
240 {
return !(__y < __x); }
244 {
return __y < __x; }
248 {
return !(__x < __y); }
254 :
public __hash_base<size_t, thread::id>
257 operator()(
const thread::id& __id)
const noexcept
258 {
return std::_Hash_impl::hash(__id._M_thread); }
261 template<
class _CharT,
class _Traits>
263 operator<<(basic_ostream<_CharT, _Traits>& __out,
thread::id __id)
266 return __out <<
"thread::id of a non-executing thread";
268 return __out << __id._M_thread;
271 _GLIBCXX_END_NAMESPACE_VERSION
277 namespace this_thread
279 _GLIBCXX_BEGIN_NAMESPACE_VERSION
290 if (!__gthread_active_p())
300 #ifdef _GLIBCXX_USE_SCHED_YIELD 309 template<
typename _Rep,
typename _Period>
313 if (__rtime <= __rtime.zero())
317 #ifdef _GLIBCXX_USE_NANOSLEEP 318 __gthread_time_t __ts =
320 static_cast<std::time_t
>(__s.count()),
321 static_cast<long>(__ns.count())
323 while (::nanosleep(&__ts, &__ts) == -1 && errno == EINTR)
326 __sleep_for(__s, __ns);
331 template<
typename _Clock,
typename _Duration>
335 auto __now = _Clock::now();
336 if (_Clock::is_steady)
342 while (__now < __atime)
345 __now = _Clock::now();
349 _GLIBCXX_END_NAMESPACE_VERSION
356 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 360 #endif // _GLIBCXX_THREAD
void sleep_for(const chrono::duration< _Rep, _Period > &__rtime)
sleep_for
Template class basic_ostream.
void sleep_until(const chrono::time_point< _Clock, _Duration > &__atime)
sleep_until
A smart pointer with reference-counted copy semantics.
void terminate() noexcept __attribute__((__noreturn__))
void yield() noexcept
yield
native_handle_type native_handle()
constexpr enable_if< __is_duration< _ToDur >::value, _ToDur >::type duration_cast(const duration< _Rep, _Period > &__d)
duration_cast
20.7.1.2 unique_ptr for single objects.
ISO C++ entities toplevel namespace is std.
thread::id get_id() noexcept
get_id
Primary class template hash.