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;
126 template<
typename _Callable,
typename... _Args>
128 thread(_Callable&& __f, _Args&&... __args)
130 #ifdef GTHR_ACTIVE_PROXY
132 auto __depend =
reinterpret_cast<void(*)()
>(&pthread_create);
134 auto __depend =
nullptr;
136 _M_start_thread(_S_make_state(
137 std::__bind_simple(std::forward<_Callable>(__f),
138 std::forward<_Args>(__args)...)),
148 thread& operator=(
const thread&) =
delete;
150 thread& operator=(thread&& __t) noexcept
159 swap(thread& __t) noexcept
163 joinable() const noexcept
164 {
return !(_M_id == id()); }
173 get_id() const noexcept
180 {
return _M_id._M_thread; }
184 hardware_concurrency() noexcept;
187 template<typename _Callable>
188 struct _State_impl : public _State
192 _State_impl(_Callable&& __f) : _M_func(std::
forward<_Callable>(__f))
196 _M_run() { _M_func(); }
200 _M_start_thread(_State_ptr,
void (*)());
202 template<
typename _Callable>
204 _S_make_state(_Callable&& __f)
206 using _Impl = _State_impl<_Callable>;
207 return _State_ptr{
new _Impl{std::forward<_Callable>(__f)}};
209 #if _GLIBCXX_THREAD_ABI_COMPAT
212 typedef shared_ptr<_Impl_base> __shared_base_type;
215 __shared_base_type _M_this_ptr;
216 virtual ~_Impl_base() =
default;
217 virtual void _M_run() = 0;
222 _M_start_thread(__shared_base_type,
void (*)());
225 _M_start_thread(__shared_base_type);
230 swap(thread& __x, thread& __y) noexcept
234 operator!=(thread::id __x, thread::id __y) noexcept
235 {
return !(__x == __y); }
238 operator<=(thread::id __x, thread::id __y) noexcept
239 {
return !(__y < __x); }
242 operator>(thread::id __x, thread::id __y) noexcept
243 {
return __y < __x; }
246 operator>=(thread::id __x, thread::id __y) noexcept
247 {
return !(__x < __y); }
253 :
public __hash_base<size_t, thread::id>
256 operator()(
const thread::id& __id)
const noexcept
257 {
return std::_Hash_impl::hash(__id._M_thread); }
260 template<
class _CharT,
class _Traits>
262 operator<<(basic_ostream<_CharT, _Traits>& __out,
thread::id __id)
265 return __out <<
"thread::id of a non-executing thread";
267 return __out << __id._M_thread;
270 _GLIBCXX_END_NAMESPACE_VERSION
276 namespace this_thread
278 _GLIBCXX_BEGIN_NAMESPACE_VERSION
289 if (!__gthread_active_p())
299 #ifdef _GLIBCXX_USE_SCHED_YIELD
308 template<
typename _Rep,
typename _Period>
312 if (__rtime <= __rtime.zero())
316 #ifdef _GLIBCXX_USE_NANOSLEEP
317 __gthread_time_t __ts =
319 static_cast<std::time_t
>(__s.count()),
320 static_cast<long>(__ns.count())
322 while (::nanosleep(&__ts, &__ts) == -1 && errno == EINTR)
325 __sleep_for(__s, __ns);
330 template<
typename _Clock,
typename _Duration>
334 auto __now = _Clock::now();
335 if (_Clock::is_steady)
341 while (__now < __atime)
344 __now = _Clock::now();
348 _GLIBCXX_END_NAMESPACE_VERSION
355 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
359 #endif // _GLIBCXX_THREAD
void sleep_for(const chrono::duration< _Rep, _Period > &__rtime)
sleep_for
20.7.1.2 unique_ptr for single objects.
Primary class template hash.
thread::id get_id() noexcept
get_id
Template class basic_ostream.
constexpr enable_if< __is_duration< _ToDur >::value, _ToDur >::type duration_cast(const duration< _Rep, _Period > &__d)
duration_cast
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
void yield() noexcept
yield
void sleep_until(const chrono::time_point< _Clock, _Duration > &__atime)
sleep_until
void swap(basic_filebuf< _CharT, _Traits > &__x, basic_filebuf< _CharT, _Traits > &__y)
Swap specialization for filebufs.
void terminate() noexcept __attribute__((__noreturn__))
native_handle_type native_handle()