42#if !defined(RTEMS_THREAD_HPP)
43#define RTEMS_THREAD_HPP
101 void set_name(
const std::string& name);
116 const std::string&
get_name()
const;
217 std::string scheduler;
224 inline typename std::decay<T>::type
226 return std::forward<T>(t);
252 friend void* thread_generic_entry(
void* arg);
260 virtual ~state_base();
261 virtual const attributes get_attributes() = 0;
262 virtual void run() = 0;
269 using state_ptr = std::unique_ptr<state_base>;
277 template <typename A, class DecayA = typename std::decay<A>::type>
279 <std::is_same<DecayA, attributes>::value>::type;
287 id() noexcept : id_(0) { }
288 explicit id(pthread_t id_) : id_(id_) { }
295 template<
class CharT,
class Traits>
296 friend std::basic_ostream<CharT, Traits>&
297 operator<<(std::basic_ostream<CharT, Traits>& out,
thread::id id_);
310 template<typename F, typename... Args>
311 explicit
thread(F&& func, Args&&... args);
317 template <typename A, typename F, typename ...Args,
319 explicit
thread(A&& attr, F&& func, Args&&... args)
323 make_invoker(decay_copy(std::forward<F>(func)),
324 decay_copy(std::forward<Args>(args))...))
333 void swap(
thread& thread_)
noexcept;
335 bool joinable() const noexcept;
349 std::
thread::
id get_id() const noexcept;
360 template<typename Parms>
364 template<
size_t Index>
365 static std::tuple_element_t<Index, Parms>&& declval();
369 template<
size_t _Num>
372#if __has_builtin(__make_integer_seq)
373 template<
typename,
size_t... _Indices>
377 using __type = __make_integer_seq<_IdxTuple, size_t, _Num>;
384 template<
size_t... Ind>
386 noexcept(
noexcept(std::invoke(declval<Ind>()...)))
387 ->
decltype(std::invoke(declval<Ind>()...)) {
388 return std::invoke(std::get<Ind>(std::move(p))...);
392 typename _Build_index_tuple<std::tuple_size<Parms>::value>::__type;
404 template<
typename Invoker>
405 struct state : state_base {
406 const attributes attr;
409 state(
const attributes& attr, Invoker&& i)
411 i(std::forward<Invoker>(i)) {
414 const attributes get_attributes()
override {
418 void run()
override {
427 template<
typename Invoker>
429 make_state(
const attributes& attr, Invoker&& i) {
430 using state_impl = state<Invoker>;
431 return state_ptr{
new state_impl(attr, std::forward<Invoker>(i)) };
438 template<
typename... T>
439 using decayed_tuple = std::tuple<typename std::decay<T>::type...>;
444 template<
typename F,
typename... Args>
445 static invoker<decayed_tuple<F, Args...>>
446 make_invoker(F&& func, Args&&... args)
449 decayed_tuple<F, Args...> {
450 std::forward<F>(func), std::forward<Args>(args)...
458 void start_thread(state_ptr s);
461 template<
typename F,
typename... Args>
467 make_invoker(decay_copy(std::forward<F>(func)),
468 decay_copy(std::forward<Args>(args))...))
472 inline std::thread::id thread::get_id() const noexcept {
476 return std::thread::id();
478 return std::thread::id(id_.id_);
483 operator==(thread::id l, thread::id r)
noexcept {
484 return l.id_ == r.id_;
488 operator!=(thread::id l, thread::id r)
noexcept {
492 template<
class C,
class T>
493 inline std::basic_ostream<C, T>&
494 operator<<(std::basic_ostream<C, T>& out, thread::id id_) {
496 return out << id_.id_;
498 return out << std::thread::id(id_.id_);
Manage the attributes of a thread.
Definition: thread.hpp:59
sched_policy
Definition: thread.hpp:74
@ sched_other
Definition: thread.hpp:75
@ sched_sporadic
Definition: thread.hpp:78
@ sched_roundrobin
Definition: thread.hpp:77
@ sched_fifo
Definition: thread.hpp:76
const std::string & get_scheduler()
Definition: thread.cpp:158
attributes()
Definition: thread.cpp:84
void set_name(const std::string &name)
Definition: thread.cpp:104
void set_scheduler(const std::string &scheduler)
Definition: thread.cpp:146
void set_scheduler_policy(sched_policy policy)
Definition: thread.cpp:170
void set_priority(int priority)
Definition: thread.cpp:122
sched_policy get_scheduler_policy() const
Definition: thread.cpp:177
sched_attr
Definition: thread.hpp:64
@ sched_explicit
Definition: thread.hpp:67
@ sched_inherit
Definition: thread.hpp:65
void update()
Definition: thread.cpp:248
const std::string & get_name() const
Definition: thread.cpp:116
void set_stack_size(size_t size)
Definition: thread.cpp:134
bool operator==(const attributes &attr) const
Definition: thread.cpp:340
size_t get_stack_size() const
Definition: thread.cpp:140
int get_priority() const
Definition: thread.cpp:128
sched_attr get_scheduler_attr() const
Definition: thread.cpp:164
void commit()
Definition: thread.cpp:183
attributes & operator=(const attributes &attr)
Definition: thread.cpp:329
Definition: thread.hpp:285
Create a thread with thread attributes.
Definition: thread.hpp:251
thread() noexcept=default
thread & operator=(thread &&thread_)
Definition: thread.cpp:363
typename std::enable_if< std::is_same< DecayA, attributes >::value >::type enable_if_attributes
Definition: thread.hpp:279
Definition: thread.hpp:371
Definition: thread.hpp:367