45#pragma GCC diagnostic push
48#pragma clang diagnostic ignored "-Wc++98-compat"
86 id (
const id&) =
default;
99 operator== (thread::id x, thread::id y) noexcept;
102 operator< (thread::id x, thread::id y) noexcept;
105 native_handle_type native_thread_;
108 thread () noexcept = default;
113 thread (F&& f, Args&&... args);
117 thread (const thread&) = delete;
118 thread (thread&& t) noexcept;
121 operator= (const thread&) = delete;
123 operator= (thread&& t) noexcept;
128 swap (thread& t) noexcept;
131 joinable (void) const noexcept;
140 get_id (void) const noexcept;
146 hardware_concurrency (void) noexcept;
150 template<typename F_T>
152 run_function_object (const void* func_object);
154 template<typename F_T>
156 delete_function_object (const void* func_obj);
159 delete_system_thread (void);
166 using function_object_deleter_t = void (*) (void*);
167 function_object_deleter_t function_object_deleter_ = nullptr;
174static_assert(std::is_trivially_copyable<thread::id>::value,
175 "thread::id must be trivially copyable");
180swap (thread& x, thread& y) noexcept;
187operator== (thread::id x, thread::id y) noexcept;
189operator!= (thread::id x, thread::id y) noexcept;
191operator< (thread::id x, thread::id y) noexcept;
193operator<= (thread::id x, thread::id y) noexcept;
195operator> (thread::id x, thread::id y) noexcept;
197operator>= (thread::id x, thread::id y) noexcept;
200template<class charT, class traits>
201basic_ostream<charT, traits>&
202operator<<(basic_ostream<charT, traits>& out, thread::id id);
210 struct hash<thread::id> ;
239 template<typename Clock_T = os::estd::chrono::systick_clock, typename Rep_T,
242 sleep_for (const std::chrono::duration<Rep_T, Period_T>& rel_time);
248 template<typename Clock_T, typename Duration_T>
250 sleep_until (const std::chrono::time_point<Clock_T, Duration_T>& abs_time);
260swap (thread& x, thread& y) noexcept
266operator== (thread::id x, thread::id y) noexcept
268 return x.native_thread_ == y.native_thread_;
272operator!= (thread::id x, thread::id y) noexcept
278operator< (thread::id x, thread::id y) noexcept
280 return x.native_thread_ < y.native_thread_;
284operator<= (thread::id x, thread::id y) noexcept
290operator> (thread::id x, thread::id y) noexcept
296operator>= (thread::id x, thread::id y) noexcept
304thread::id::id () noexcept :
305native_thread_ ( nullptr)
311thread::id::id (native_handle_type native_thread) noexcept :
312native_thread_ ( native_thread)
320thread::get_id () const noexcept
325inline thread::native_handle_type
326thread::native_handle ()
328 return id_.native_thread_;
332thread::hardware_concurrency () noexcept
337template<typename F_T>
339 thread::run_function_object (const void* func_obj)
341 os::trace::printf ("%s()\n", __PRETTY_FUNCTION__);
343 using Function_object = F_T;
344 const Function_object* f = static_cast<const Function_object*> (func_obj);
348template<typename F_T>
350 thread::delete_function_object (const void* func_obj)
352 os::trace::printf ("%s()\n", __PRETTY_FUNCTION__);
354 using Function_object = F_T;
355 const Function_object* f = static_cast<const Function_object*> (func_obj);
362#pragma GCC diagnostic push
363#pragma GCC diagnostic ignored "-Waggregate-return"
365template<typename Callable_T, typename ... Args_T>
366 thread::thread (Callable_T&& f, Args_T&&... args)
370 os::trace::printf ("%s() @%p\n", __PRETTY_FUNCTION__, this);
372 using Function_object = decltype(std::bind (std::forward<Callable_T> (f),
373 std::forward<Args_T>(args)...));
379 Function_object* funct_obj = new Function_object (
380 std::bind (std::forward<Callable_T> (f),
381 std::forward<Args_T>(args)...));
385#pragma GCC diagnostic push
386#pragma GCC diagnostic ignored "-Wcast-function-type"
388 { new os::rtos::thread (
389 reinterpret_cast<os::rtos::thread::func_t> (&run_function_object<
391 reinterpret_cast<os::rtos::thread::func_args_t> (funct_obj)) };
392#pragma GCC diagnostic pop
395 function_object_deleter_ =
396 reinterpret_cast<function_object_deleter_t> (&delete_function_object<
400#pragma GCC diagnostic pop
408 __attribute__((always_inline))
411 os::rtos::this_thread::yield ();
417 return thread::id (&os::rtos::this_thread::thread ());
430 template<class Rep_T, class Period_T>
432 sleep_for (const std::chrono::duration<Rep_T, Period_T>& rel_time)
434 using namespace std::chrono;
436 if (rel_time > duration<Rep_T, Period_T>::zero ())
439 microseconds micros =
440 os::estd::chrono::ceil<microseconds> (rel_time);
445#pragma GCC diagnostic push
446#pragma GCC diagnostic ignored "-Waggregate-return"
448 os::rtos::thread::sleep (
449 (os::rtos::systicks_t) (os::estd::chrono::ceil<
450 systicks> (micros).count ()));
451#pragma GCC diagnostic pop
456 os::rtos::Systick_clock::sleep_for (
457 os::rtos::Systick_clock::ticks_cast (
465#pragma GCC diagnostic push
466#pragma GCC diagnostic ignored "-Waggregate-return"
468 template<typename Clock_T, class Rep_T, class Period_T>
470 sleep_for (const std::chrono::duration<Rep_T, Period_T>& rel_time)
472 using namespace std::chrono;
474 using clock = Clock_T;
475 using sleep_rep = typename clock::sleep_rep;
477 if (rel_time > duration<Rep_T, Period_T>::zero ())
479 sleep_rep d = static_cast<sleep_rep> (os::estd::chrono::ceil<
480 typename clock::duration> (rel_time).count ());
482 clock::sleep_for (d);
486#pragma GCC diagnostic pop
488 template<typename Clock_T, typename Duration_T>
490 sleep_until (const std::chrono::time_point<Clock_T, Duration_T>& abs_time)
492 using clock = Clock_T;
494#pragma GCC diagnostic push
495#pragma GCC diagnostic ignored "-Waggregate-return"
497 auto now = clock::now ();
499 while (now < abs_time)
501 sleep_for (abs_time - now);
505#pragma GCC diagnostic pop
509 template<typename Duration_T>
512 const std::chrono::time_point<os::estd::chrono::realtime_clock,
513 Duration_T>& abs_time)
515 using clock = os::estd::chrono::realtime_clock;
517#pragma GCC diagnostic push
518#pragma GCC diagnostic ignored "-Waggregate-return"
520 auto now = clock::now ();
521 while (now < abs_time)
523 typename clock::sleep_rep d = (os::estd::chrono::ceil<
524 typename clock::sleep_duration> (abs_time - now)).count ();
525 clock::sleep_for (d);
529#pragma GCC diagnostic pop
533 template<typename Duration_T>
536 const std::chrono::time_point<os::estd::chrono::systick_clock,
537 Duration_T>& abs_time)
539 using clock = os::estd::chrono::systick_clock;
541#pragma GCC diagnostic push
542#pragma GCC diagnostic ignored "-Waggregate-return"
544 auto now = clock::now ();
545 while (now < abs_time)
547 typename clock::sleep_rep d = (os::estd::chrono::ceil<
548 typename clock::sleep_duration> (abs_time - now)).count ();
549 clock::sleep_for (d);
553#pragma GCC diagnostic pop
558#pragma GCC diagnostic pop
POSIX compliant thread, using the default RTOS allocator.
id & operator=(const id &)=default