29#pragma GCC diagnostic push
31#pragma clang diagnostic ignored "-Wc++98-compat"
67 id (
const id&) =
default;
80 operator== (thread::id x, thread::id y) noexcept;
83 operator< (thread::id x, thread::id y) noexcept;
86 native_handle_type native_thread_;
89 thread () noexcept = default;
93 explicit thread (F&& f, Args&&... args);
97 thread (const thread&) = delete;
98 thread (thread&& t) noexcept;
101 operator= (const thread&)
104 operator= (thread&& t) noexcept;
109 swap (thread& t) noexcept;
112 joinable (void) const noexcept;
121 get_id (void) const noexcept;
127 hardware_concurrency (void) noexcept;
130 template <typename F_T>
132 run_function_object (const void* func_object);
134 template <typename F_T>
136 delete_function_object (const void* func_obj);
139 delete_system_thread (void);
146 using function_object_deleter_t = void (*) (void*);
147 function_object_deleter_t function_object_deleter_ = nullptr;
153static_assert (std::is_trivially_copyable<thread::id>::value,
154 "thread::id must be trivially copyable");
159swap (thread& x, thread& y) noexcept;
166operator== (thread::id x, thread::id y) noexcept;
168operator!= (thread::id x, thread::id y) noexcept;
170operator< (thread::id x, thread::id y) noexcept;
172operator<= (thread::id x, thread::id y) noexcept;
174operator> (thread::id x, thread::id y) noexcept;
176operator>= (thread::id x, thread::id y) noexcept;
179template<class charT, class traits>
180basic_ostream<charT, traits>&
181operator<<(basic_ostream<charT, traits>& out, thread::id id);
189struct hash<thread::id>;
219 template <typename Clock_T = os::estd::chrono::systick_clock, typename Rep_T,
222 sleep_for (const std::chrono::duration<Rep_T, Period_T>& rel_time);
228 template <typename Clock_T, typename Duration_T>
230 sleep_until (const std::chrono::time_point<Clock_T, Duration_T>& abs_time);
240swap (thread& x, thread& y) noexcept
246operator== (thread::id x, thread::id y) noexcept
248 return x.native_thread_ == y.native_thread_;
252operator!= (thread::id x, thread::id y) noexcept
258operator< (thread::id x, thread::id y) noexcept
260 return x.native_thread_ < y.native_thread_;
264operator<= (thread::id x, thread::id y) noexcept
270operator> (thread::id x, thread::id y) noexcept
276operator>= (thread::id x, thread::id y) noexcept
283inline thread::id::id () noexcept : native_thread_ (nullptr)
287inline thread::id::id (native_handle_type native_thread) noexcept
288 : native_thread_ (native_thread)
295thread::get_id () const noexcept
300inline thread::native_handle_type
301thread::native_handle ()
303 return id_.native_thread_;
307thread::hardware_concurrency () noexcept
312template <typename F_T>
314thread::run_function_object (const void* func_obj)
316 os::trace::printf ("%s()\n", __PRETTY_FUNCTION__);
318 using Function_object = F_T;
319 const Function_object* f = static_cast<const Function_object*> (func_obj);
323template <typename F_T>
325thread::delete_function_object (const void* func_obj)
327 os::trace::printf ("%s()\n", __PRETTY_FUNCTION__);
329 using Function_object = F_T;
330 const Function_object* f = static_cast<const Function_object*> (func_obj);
337#pragma GCC diagnostic push
338#if defined(__clang__)
339#elif defined(__GNUC__)
340#pragma GCC diagnostic ignored "-Waggregate-return"
343template <typename Callable_T, typename... Args_T>
344thread::thread (Callable_T&& f, Args_T&&... args)
349 os::trace::printf ("%s() @%p\n", __PRETTY_FUNCTION__, this);
351 using Function_object = decltype (std::bind (
352 std::forward<Callable_T> (f), std::forward<Args_T> (args)...));
358 Function_object* funct_obj = new Function_object (std::bind (
359 std::forward<Callable_T> (f), std::forward<Args_T> (args)...));
363#pragma GCC diagnostic push
364#if defined(__clang__)
365#pragma clang diagnostic ignored "-Wcast-function-type"
366#elif defined(__GNUC__)
367#pragma GCC diagnostic ignored "-Wcast-function-type"
369 id_ = id{ new os::rtos::thread (
370 reinterpret_cast<os::rtos::thread::func_t> (
371 &run_function_object<Function_object>),
372 reinterpret_cast<os::rtos::thread::func_args_t> (funct_obj)) };
373#pragma GCC diagnostic pop
375#pragma GCC diagnostic push
376#if defined(__clang__)
377#pragma clang diagnostic ignored "-Wcast-function-type-strict"
380 function_object_deleter_ = reinterpret_cast<function_object_deleter_t> (
381 &delete_function_object<Function_object>);
382#pragma GCC diagnostic pop
385#pragma GCC diagnostic pop
392 inline void __attribute__ ((always_inline))
395 os::rtos::this_thread::yield ();
398#pragma GCC diagnostic push
399#if defined(__clang__)
400#elif defined(__GNUC__)
401#pragma GCC diagnostic ignored "-Waggregate-return"
407 return thread::id (&os::rtos::this_thread::thread ());
410#pragma GCC diagnostic pop
422 template<class Rep_T, class Period_T>
424 sleep_for (const std::chrono::duration<Rep_T, Period_T>& rel_time)
426 using namespace std::chrono;
428 if (rel_time > duration<Rep_T, Period_T>::zero ())
431 microseconds micros =
432 os::estd::chrono::ceil<microseconds> (rel_time);
437#pragma GCC diagnostic push
438#if defined(__clang__)
439#elif defined(__GNUC__)
440#pragma GCC diagnostic ignored "-Waggregate-return"
442 os::rtos::thread::sleep (
443 (os::rtos::systicks_t) (os::estd::chrono::ceil<
444 systicks> (micros).count ()));
445#pragma GCC diagnostic pop
450 os::rtos::Systick_clock::sleep_for (
451 os::rtos::Systick_clock::ticks_cast (
459#pragma GCC diagnostic push
460#if defined(__clang__)
461#elif defined(__GNUC__)
462#pragma GCC diagnostic ignored "-Waggregate-return"
465 template <typename Clock_T, class Rep_T, class Period_T>
467 sleep_for (const std::chrono::duration<Rep_T, Period_T>& rel_time)
469 using namespace std::chrono;
471 using clock = Clock_T;
472 using sleep_rep = typename clock::sleep_rep;
474 if (rel_time > duration<Rep_T, Period_T>::zero ())
476 sleep_rep d = static_cast<sleep_rep> (
477 os::estd::chrono::ceil<typename clock::duration> (rel_time)
480 clock::sleep_for (d);
484#pragma GCC diagnostic pop
486 template <typename Clock_T, typename Duration_T>
488 sleep_until (const std::chrono::time_point<Clock_T, Duration_T>& abs_time)
490 using clock = Clock_T;
492#pragma GCC diagnostic push
493#if defined(__clang__)
494#elif defined(__GNUC__)
495#pragma GCC diagnostic ignored "-Waggregate-return"
498 auto now = clock::now ();
500 while (now < abs_time)
502 sleep_for (abs_time - now);
506#pragma GCC diagnostic pop
509 template <typename Duration_T>
511 sleep_until (const std::chrono::time_point<os::estd::chrono::realtime_clock,
512 Duration_T>& abs_time)
514 using clock = os::estd::chrono::realtime_clock;
516#pragma GCC diagnostic push
517#if defined(__clang__)
518#elif defined(__GNUC__)
519#pragma GCC diagnostic ignored "-Waggregate-return"
522 auto now = clock::now ();
523 while (now < abs_time)
525 typename clock::sleep_rep d
526 = (os::estd::chrono::ceil<typename clock::sleep_duration> (abs_time
529 clock::sleep_for (d);
533#pragma GCC diagnostic pop
536 template <typename Duration_T>
538 sleep_until (const std::chrono::time_point<os::estd::chrono::systick_clock,
539 Duration_T>& abs_time)
541 using clock = os::estd::chrono::systick_clock;
543#pragma GCC diagnostic push
544#if defined(__clang__)
545#elif defined(__GNUC__)
546#pragma GCC diagnostic ignored "-Waggregate-return"
549 auto now = clock::now ();
550 while (now < abs_time)
552 typename clock::sleep_rep d
553 = (os::estd::chrono::ceil<typename clock::sleep_duration> (abs_time
556 clock::sleep_for (d);
560#pragma GCC diagnostic pop
564#pragma GCC diagnostic pop
POSIX compliant thread, using the default RTOS allocator.
id & operator=(const id &)=default