5#ifdef ROO_THREADS_USE_FREERTOS
10#define ROO_THREADS_ATTRIBUTES_SUPPORT_PRIORITY 1
11#define ROO_THREADS_ATTRIBUTES_SUPPORT_NAME 1
12#define ROO_THREADS_ATTRIBUTES_SUPPORT_STACK_SIZE 1
35 uint32_t stack_size()
const {
return stack_size_; }
37 uint16_t priority()
const {
return priority_; }
39 bool joinable()
const {
return joinable_; }
41 const char* name()
const {
return name_; }
44 void set_stack_size(uint32_t stack_size) { stack_size_ = stack_size; }
47 void set_priority(uint16_t priority) { priority_ = priority; }
50 void set_name(
const char* name) { name_ = name; }
62 thread() noexcept : state_(
nullptr) {}
64 thread(
const thread&) =
delete;
67 thread(thread&& other) noexcept : thread() { swap(other); }
71 typename Callable,
typename... Args,
72 typename =
typename std::enable_if<!std::is_same<
73 std::remove_reference_t<Callable>, thread::attributes>::value>::type,
75 typename std::enable_if<!std::is_same<Callable, thread>::value>::type>
76 explicit thread(Callable&& callable, Args&&... args) {
77 static_assert(std::is_invocable<typename std::decay<Callable>::type,
78 typename std::decay<Args>::type...>::value,
79 "roo::thread argument must be invocable");
81 MakeDynamicCallableWithArgs(std::forward<Callable>(callable),
82 std::forward<Args>(args)...));
87 template <
typename Callable,
typename... Args,
88 typename =
typename std::enable_if<
89 !std::is_same<Callable, thread>::value>::type>
90 explicit thread(
const attributes& attrs, Callable&& callable,
92 static_assert(std::is_invocable<typename std::decay<Callable>::type,
93 typename std::decay<Args>::type...>::value,
94 "roo::thread argument must be invocable");
96 start(attrs, MakeDynamicCallableWithArgs(std::forward<Callable>(callable),
97 std::forward<Args>(args)...));
103 thread& operator=(
const thread&) =
delete;
106 thread& operator=(thread&& other)
noexcept;
109 void swap(thread& other)
noexcept;
112 bool joinable() const noexcept;
121 thread::
id get_id() const noexcept;
124 void start(const attributes& attributes, std::unique_ptr<VirtualCallable>);
129namespace this_thread {
133thread::id
get_id() noexcept;
137void yield() noexcept;
142void sleep_for(const roo_time::Duration& duration);
147void sleep_until(const roo_time::Uptime& when);
154 id() : id_(nullptr) {}
156 bool operator==(
const id& other)
const {
return id_ == other.id_; }
158 bool operator!=(
const id& other)
const {
return id_ != other.id_; }
160 bool operator<(
const id& other)
const {
return id_ < other.id_; }
162 bool operator<=(
const id& other)
const {
return id_ <= other.id_; }
164 bool operator>(
const id& other)
const {
return id_ > other.id_; }
166 bool operator>=(
const id& other)
const {
return id_ >= other.id_; }
169 id(
void*
id) : id_(id) {}
172 friend id this_thread::get_id() noexcept;
thread::id get_id() noexcept
Returns identifier of the current thread.