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();
367 template<
size_t... Ind>
368 auto invoke(std::_Index_tuple<Ind...>)
369 noexcept(
noexcept(std::invoke(declval<Ind>()...)))
370 ->
decltype(std::invoke(declval<Ind>()...)) {
371 return std::invoke(std::get<Ind>(std::move(
p))...);
375 typename std::_Build_index_tuple<std::tuple_size<Parms>::value>::__type;
387 template<
typename Invoker>
388 struct state : state_base {
389 const attributes attr;
392 state(
const attributes& attr, Invoker&& i)
394 i(std::forward<Invoker>(i)) {
397 const attributes get_attributes()
override {
401 void run()
override {
410 template<
typename Invoker>
412 make_state(
const attributes& attr, Invoker&& i) {
413 using state_impl = state<Invoker>;
414 return state_ptr{
new state_impl(attr, std::forward<Invoker>(i)) };
421 template<
typename... T>
422 using decayed_tuple = std::tuple<typename std::decay<T>::type...>;
427 template<
typename F,
typename... Args>
428 static invoker<decayed_tuple<F, Args...>>
429 make_invoker(F&& func, Args&&... args)
432 decayed_tuple<F, Args...> {
433 std::forward<F>(func), std::forward<Args>(args)...
441 void start_thread(state_ptr s);
444 template<
typename F,
typename... Args>
450 make_invoker(decay_copy(std::forward<F>(func)),
451 decay_copy(std::forward<Args>(args))...))
455 inline std::thread::id thread::get_id() const noexcept {
456 return std::thread::id(id_.id_);
460 operator==(thread::id l, thread::id r)
noexcept {
461 return l.id_ == r.id_;
465 operator!=(thread::id l, thread::id r)
noexcept {
469 template<
class C,
class T>
470 inline std::basic_ostream<C, T>&
471 operator<<(std::basic_ostream<C, T>& out, thread::id id_) {
472 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:142
attributes()
Definition: thread.cpp:68
void set_name(const std::string &name)
Definition: thread.cpp:88
void set_scheduler(const std::string &scheduler)
Definition: thread.cpp:130
void set_scheduler_policy(sched_policy policy)
Definition: thread.cpp:154
void set_priority(int priority)
Definition: thread.cpp:106
sched_policy get_scheduler_policy() const
Definition: thread.cpp:161
sched_attr
Definition: thread.hpp:64
@ sched_explicit
Definition: thread.hpp:67
@ sched_inherit
Definition: thread.hpp:65
void update()
Definition: thread.cpp:231
const std::string & get_name() const
Definition: thread.cpp:100
void set_stack_size(size_t size)
Definition: thread.cpp:118
bool operator==(const attributes &attr) const
Definition: thread.cpp:309
size_t get_stack_size() const
Definition: thread.cpp:124
int get_priority() const
Definition: thread.cpp:112
sched_attr get_scheduler_attr() const
Definition: thread.cpp:148
void commit()
Definition: thread.cpp:167
attributes & operator=(const attributes &attr)
Definition: thread.cpp:298
Definition: thread.hpp:285
Create a thread with thread attributes.
Definition: thread.hpp:251
thread() noexcept=default
thread & operator=(thread &&thread_)
Definition: thread.cpp:332
typename std::enable_if< std::is_same< DecayA, attributes >::value >::type enable_if_attributes
Definition: thread.hpp:279
unsigned p
Definition: tte.h:17