30#pragma GCC diagnostic push
32#pragma clang diagnostic ignored "-Wc++98-compat"
70 id (
const id&) =
default;
83 operator== (thread::id x, thread::id y) noexcept;
86 operator< (thread::id x, thread::id y) noexcept;
89 native_handle_type native_thread_;
92 thread () noexcept = default;
97 thread (F&& f, Args&&... args);
101 thread (const thread&) = delete;
102 thread (thread&& t) noexcept;
105 operator= (const thread&) = delete;
107 operator= (thread&& t) noexcept;
112 swap (thread& t) noexcept;
115 joinable (void) const noexcept;
124 get_id (void) const noexcept;
130 hardware_concurrency (void) noexcept;
134 template<typename F_T>
136 run_function_object (const void* func_object);
138 template<typename F_T>
140 delete_function_object (const void* func_obj);
143 delete_system_thread (void);
150 using function_object_deleter_t = void (*) (void*);
151 function_object_deleter_t function_object_deleter_ = nullptr;
158static_assert(std::is_trivially_copyable<thread::id>::value,
159 "thread::id must be trivially copyable");
164swap (thread& x, thread& y) noexcept;
171operator== (thread::id x, thread::id y) noexcept;
173operator!= (thread::id x, thread::id y) noexcept;
175operator< (thread::id x, thread::id y) noexcept;
177operator<= (thread::id x, thread::id y) noexcept;
179operator> (thread::id x, thread::id y) noexcept;
181operator>= (thread::id x, thread::id y) noexcept;
184template<class charT, class traits>
185basic_ostream<charT, traits>&
186operator<<(basic_ostream<charT, traits>& out, thread::id id);
194 struct hash<thread::id> ;
223 template<typename Clock_T = os::estd::chrono::systick_clock, typename Rep_T,
226 sleep_for (const std::chrono::duration<Rep_T, Period_T>& rel_time);
232 template<typename Clock_T, typename Duration_T>
234 sleep_until (const std::chrono::time_point<Clock_T, Duration_T>& abs_time);
244swap (thread& x, thread& y) noexcept
250operator== (thread::id x, thread::id y) noexcept
252 return x.native_thread_ == y.native_thread_;
256operator!= (thread::id x, thread::id y) noexcept
262operator< (thread::id x, thread::id y) noexcept
264 return x.native_thread_ < y.native_thread_;
268operator<= (thread::id x, thread::id y) noexcept
274operator> (thread::id x, thread::id y) noexcept
280operator>= (thread::id x, thread::id y) noexcept
288thread::id::id () noexcept :
289native_thread_ ( nullptr)
294thread::id::id (native_handle_type native_thread) noexcept :
295native_thread_ ( native_thread)
302thread::get_id () const noexcept
307inline thread::native_handle_type
308thread::native_handle ()
310 return id_.native_thread_;
314thread::hardware_concurrency () noexcept
319template<typename F_T>
321 thread::run_function_object (const void* func_obj)
323 os::trace::printf ("%s()\n", __PRETTY_FUNCTION__);
325 using Function_object = F_T;
326 const Function_object* f = static_cast<const Function_object*> (func_obj);
330template<typename F_T>
332 thread::delete_function_object (const void* func_obj)
334 os::trace::printf ("%s()\n", __PRETTY_FUNCTION__);
336 using Function_object = F_T;
337 const Function_object* f = static_cast<const Function_object*> (func_obj);
344#pragma GCC diagnostic push
345#if defined(__clang__)
346#elif defined(__GNUC__)
347#pragma GCC diagnostic ignored "-Waggregate-return"
350template<typename Callable_T, typename ... Args_T>
351 thread::thread (Callable_T&& f, Args_T&&... args)
355 os::trace::printf ("%s() @%p\n", __PRETTY_FUNCTION__, this);
357 using Function_object = decltype(std::bind (std::forward<Callable_T> (f),
358 std::forward<Args_T>(args)...));
364 Function_object* funct_obj = new Function_object (
365 std::bind (std::forward<Callable_T> (f),
366 std::forward<Args_T>(args)...));
370#pragma GCC diagnostic push
371#if defined(__clang__)
372#pragma clang diagnostic ignored "-Wcast-function-type"
373#elif defined(__GNUC__)
374#pragma GCC diagnostic ignored "-Wcast-function-type"
377 { new os::rtos::thread (
378 reinterpret_cast<os::rtos::thread::func_t> (&run_function_object<
380 reinterpret_cast<os::rtos::thread::func_args_t> (funct_obj)) };
381#pragma GCC diagnostic pop
384 function_object_deleter_ =
385 reinterpret_cast<function_object_deleter_t> (&delete_function_object<
389#pragma GCC diagnostic pop
397 __attribute__((always_inline))
400 os::rtos::this_thread::yield ();
403#pragma GCC diagnostic push
404#if defined(__clang__)
405#elif defined(__GNUC__)
406#pragma GCC diagnostic ignored "-Waggregate-return"
412 return thread::id (&os::rtos::this_thread::thread ());
415#pragma GCC diagnostic pop
427 template<class Rep_T, class Period_T>
429 sleep_for (const std::chrono::duration<Rep_T, Period_T>& rel_time)
431 using namespace std::chrono;
433 if (rel_time > duration<Rep_T, Period_T>::zero ())
436 microseconds micros =
437 os::estd::chrono::ceil<microseconds> (rel_time);
442#pragma GCC diagnostic push
443#if defined(__clang__)
444#elif defined(__GNUC__)
445#pragma GCC diagnostic ignored "-Waggregate-return"
447 os::rtos::thread::sleep (
448 (os::rtos::systicks_t) (os::estd::chrono::ceil<
449 systicks> (micros).count ()));
450#pragma GCC diagnostic pop
455 os::rtos::Systick_clock::sleep_for (
456 os::rtos::Systick_clock::ticks_cast (
464#pragma GCC diagnostic push
465#if defined(__clang__)
466#elif defined(__GNUC__)
467#pragma GCC diagnostic ignored "-Waggregate-return"
470 template<typename Clock_T, class Rep_T, class Period_T>
472 sleep_for (const std::chrono::duration<Rep_T, Period_T>& rel_time)
474 using namespace std::chrono;
476 using clock = Clock_T;
477 using sleep_rep = typename clock::sleep_rep;
479 if (rel_time > duration<Rep_T, Period_T>::zero ())
481 sleep_rep d = static_cast<sleep_rep> (os::estd::chrono::ceil<
482 typename clock::duration> (rel_time).count ());
484 clock::sleep_for (d);
488#pragma GCC diagnostic pop
490 template<typename Clock_T, typename Duration_T>
492 sleep_until (const std::chrono::time_point<Clock_T, Duration_T>& abs_time)
494 using clock = Clock_T;
496#pragma GCC diagnostic push
497#if defined(__clang__)
498#elif defined(__GNUC__)
499#pragma GCC diagnostic ignored "-Waggregate-return"
502 auto now = clock::now ();
504 while (now < abs_time)
506 sleep_for (abs_time - now);
510#pragma GCC diagnostic pop
514 template<typename Duration_T>
517 const std::chrono::time_point<os::estd::chrono::realtime_clock,
518 Duration_T>& abs_time)
520 using clock = os::estd::chrono::realtime_clock;
522#pragma GCC diagnostic push
523#if defined(__clang__)
524#elif defined(__GNUC__)
525#pragma GCC diagnostic ignored "-Waggregate-return"
528 auto now = clock::now ();
529 while (now < abs_time)
531 typename clock::sleep_rep d = (os::estd::chrono::ceil<
532 typename clock::sleep_duration> (abs_time - now)).count ();
533 clock::sleep_for (d);
537#pragma GCC diagnostic pop
541 template<typename Duration_T>
544 const std::chrono::time_point<os::estd::chrono::systick_clock,
545 Duration_T>& abs_time)
547 using clock = os::estd::chrono::systick_clock;
549#pragma GCC diagnostic push
550#if defined(__clang__)
551#elif defined(__GNUC__)
552#pragma GCC diagnostic ignored "-Waggregate-return"
555 auto now = clock::now ();
556 while (now < abs_time)
558 typename clock::sleep_rep d = (os::estd::chrono::ceil<
559 typename clock::sleep_duration> (abs_time - now)).count ();
560 clock::sleep_for (d);
564#pragma GCC diagnostic pop
569#pragma GCC diagnostic pop
POSIX compliant thread, using the default RTOS allocator.
id & operator=(const id &)=default