76 id (
const id&) =
default;
89 operator== (thread::id x, thread::id y) noexcept;
92 operator< (thread::id x, thread::id y) noexcept;
95 native_handle_type native_thread_;
98 thread () noexcept = default;
103 thread (F&& f, Args&&... args);
107 thread (const thread&) = delete;
108 thread (thread&& t) noexcept;
111 operator= (const thread&) = delete;
113 operator= (thread&& t) noexcept;
118 swap (thread& t) noexcept;
121 joinable (void) const noexcept;
130 get_id (void) const noexcept;
136 hardware_concurrency (void) noexcept;
140 template<typename F_T>
142 run_function_object (const void* func_object);
144 template<typename F_T>
146 delete_function_object (const void* func_obj);
149 delete_system_thread (void);
156 using function_object_deleter_t = void (*) (void*);
157 function_object_deleter_t function_object_deleter_ = nullptr;
164 static_assert(std::is_trivially_copyable<thread::id>::value,
165 "thread::id must be trivially copyable");
170 swap (thread& x, thread& y) noexcept;
177 operator== (thread::id x, thread::id y) noexcept;
179 operator!= (thread::id x, thread::id y) noexcept;
181 operator< (thread::id x, thread::id y) noexcept;
183 operator<= (thread::id x, thread::id y) noexcept;
185 operator> (thread::id x, thread::id y) noexcept;
187 operator>= (thread::id x, thread::id y) noexcept;
190 template<class charT, class traits>
191 basic_ostream<charT, traits>&
192 operator<<(basic_ostream<charT, traits>& out, thread::id id);
200 struct hash<thread::id> ;
208 namespace this_thread
229 template<typename Clock_T = os::estd::chrono::systick_clock, typename Rep_T,
232 sleep_for (const std::chrono::duration<Rep_T, Period_T>& rel_time);
238 template<typename Clock_T, typename Duration_T>
240 sleep_until (const std::chrono::time_point<Clock_T, Duration_T>& abs_time);
250 swap (thread& x, thread& y) noexcept
256 operator== (thread::id x, thread::id y) noexcept
258 return x.native_thread_ == y.native_thread_;
262 operator!= (thread::id x, thread::id y) noexcept
268 operator< (thread::id x, thread::id y) noexcept
270 return x.native_thread_ < y.native_thread_;
274 operator<= (thread::id x, thread::id y) noexcept
280 operator> (thread::id x, thread::id y) noexcept
286 operator>= (thread::id x, thread::id y) noexcept
294 thread::id::id () noexcept :
295 native_thread_ ( nullptr)
301 thread::id::id (native_handle_type native_thread) noexcept :
302 native_thread_ ( native_thread)
310 thread::get_id () const noexcept
315 inline thread::native_handle_type
316 thread::native_handle ()
318 return id_.native_thread_;
322 thread::hardware_concurrency () noexcept
327 template<typename F_T>
329 thread::run_function_object (const void* func_obj)
331 os::trace::printf ("%s()\n", __PRETTY_FUNCTION__);
333 using Function_object = F_T;
334 const Function_object* f = static_cast<const Function_object*> (func_obj);
338 template<typename F_T>
340 thread::delete_function_object (const void* func_obj)
342 os::trace::printf ("%s()\n", __PRETTY_FUNCTION__);
344 using Function_object = F_T;
345 const Function_object* f = static_cast<const Function_object*> (func_obj);
352 #pragma GCC diagnostic push
353 #pragma GCC diagnostic ignored "-Waggregate-return"
355 template<typename Callable_T, typename ... Args_T>
356 thread::thread (Callable_T&& f, Args_T&&... args)
360 os::trace::printf ("%s() @%p\n", __PRETTY_FUNCTION__, this);
362 using Function_object = decltype(std::bind (std::forward<Callable_T> (f),
363 std::forward<Args_T>(args)...));
369 Function_object* funct_obj = new Function_object (
370 std::bind (std::forward<Callable_T> (f),
371 std::forward<Args_T>(args)...));
376 { new os::rtos::thread (
377 reinterpret_cast<os::rtos::thread::func_t> (&run_function_object<
379 reinterpret_cast<os::rtos::thread::func_args_t> (funct_obj)) };
382 function_object_deleter_ =
383 reinterpret_cast<function_object_deleter_t> (&delete_function_object<
387 #pragma GCC diagnostic pop
391 namespace this_thread
395 __attribute__((always_inline))
398 os::rtos::this_thread::yield ();
404 return thread::id (&os::rtos::this_thread::thread ());
417 template<class Rep_T, class Period_T>
419 sleep_for (const std::chrono::duration<Rep_T, Period_T>& rel_time)
421 using namespace std::chrono;
423 if (rel_time > duration<Rep_T, Period_T>::zero ())
426 microseconds micros =
427 os::estd::chrono::ceil<microseconds> (rel_time);
432 #pragma GCC diagnostic push
433 #pragma GCC diagnostic ignored "-Waggregate-return"
435 os::rtos::thread::sleep (
436 (os::rtos::systicks_t) (os::estd::chrono::ceil<
437 systicks> (micros).count ()));
438 #pragma GCC diagnostic pop
443 os::rtos::Systick_clock::sleep_for (
444 os::rtos::Systick_clock::ticks_cast (
452 #pragma GCC diagnostic push
453 #pragma GCC diagnostic ignored "-Waggregate-return"
455 template<typename Clock_T, class Rep_T, class Period_T>
457 sleep_for (const std::chrono::duration<Rep_T, Period_T>& rel_time)
459 using namespace std::chrono;
461 using clock = Clock_T;
462 using sleep_rep = typename clock::sleep_rep;
464 if (rel_time > duration<Rep_T, Period_T>::zero ())
466 sleep_rep d = static_cast<sleep_rep> (os::estd::chrono::ceil<
467 typename clock::duration> (rel_time).count ());
469 clock::sleep_for (d);
473 #pragma GCC diagnostic pop
475 template<typename Clock_T, typename Duration_T>
477 sleep_until (const std::chrono::time_point<Clock_T, Duration_T>& abs_time)
479 using clock = Clock_T;
481 #pragma GCC diagnostic push
482 #pragma GCC diagnostic ignored "-Waggregate-return"
484 auto now = clock::now ();
486 while (now < abs_time)
488 sleep_for (abs_time - now);
492 #pragma GCC diagnostic pop
496 template<typename Duration_T>
499 const std::chrono::time_point<os::estd::chrono::realtime_clock,
500 Duration_T>& abs_time)
502 using clock = os::estd::chrono::realtime_clock;
504 #pragma GCC diagnostic push
505 #pragma GCC diagnostic ignored "-Waggregate-return"
507 auto now = clock::now ();
508 while (now < abs_time)
510 typename clock::sleep_rep d = (os::estd::chrono::ceil<
511 typename clock::sleep_duration> (abs_time - now)).count ();
512 clock::sleep_for (d);
516 #pragma GCC diagnostic pop
520 template<typename Duration_T>
523 const std::chrono::time_point<os::estd::chrono::systick_clock,
524 Duration_T>& abs_time)
526 using clock = os::estd::chrono::systick_clock;
528 #pragma GCC diagnostic push
529 #pragma GCC diagnostic ignored "-Waggregate-return"
531 auto now = clock::now ();
532 while (now < abs_time)
534 typename clock::sleep_rep d = (os::estd::chrono::ceil<
535 typename clock::sleep_duration> (abs_time - now)).count ();
536 clock::sleep_for (d);
540 #pragma GCC diagnostic pop
id & operator=(const id &)=default
POSIX compliant thread, using the default RTOS allocator.