roo_threads
API Documentation for roo_threads
Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1#pragma once
2
4
5#if (defined ROO_THREADS_USE_FREERTOS)
6
7/// If both cppstd and FreeRTOS are available (e.g. ESP32), prefer FreeRTOS
8/// because it offers more control over thread attributes.
9
11
12namespace roo {
13
14/// @brief Thread abstraction for the selected backend.
15using thread = ::roo_threads::freertos::thread;
16namespace this_thread {
17
18/// @brief Returns the id of the calling thread.
19inline thread::id get_id() noexcept {
20 return roo_threads::freertos::this_thread::get_id();
21}
22
23/// @brief Hints the scheduler to switch to another thread.
24inline void yield() noexcept { roo_threads::freertos::this_thread::yield(); }
25
26/// @brief Suspends execution for at least the specified duration.
27/// @param duration sleep interval.
28inline void sleep_for(const roo_time::Duration& duration) {
29 roo_threads::freertos::this_thread::sleep_for(duration);
30}
31
32/// @brief Suspends execution until the specified uptime point.
33/// @param when wake-up time.
34inline void sleep_until(const roo_time::Uptime& when) {
35 roo_threads::freertos::this_thread::sleep_until(when);
36}
37
38} // namespace this_thread
39
40} // namespace roo
41
42#elif (defined ROO_THREADS_USE_CPPSTD)
43
45
46namespace roo {
47
48/// @brief Thread abstraction for the selected backend.
49using thread = roo_threads::cppstd::thread;
50
51namespace this_thread {
52
53/// @brief Returns the id of the calling thread.
54inline thread::id get_id() noexcept {
55 return roo_threads::cppstd::this_thread::get_id();
56}
57
58/// @brief Hints the scheduler to switch to another thread.
59inline void yield() noexcept { roo_threads::cppstd::this_thread::yield(); }
60
61/// @brief Suspends execution for at least the specified duration.
62/// @param duration sleep interval.
63inline void sleep_for(const roo_time::Duration& duration) {
64 roo_threads::cppstd::this_thread::sleep_for(duration);
65}
66
67/// @brief Suspends execution until the specified uptime point.
68/// @param when wake-up time.
69inline void sleep_until(const roo_time::Uptime& when) {
70 roo_threads::cppstd::this_thread::sleep_until(when);
71}
72
73} // namespace this_thread
74
75} // namespace roo
76
77#elif (defined ROO_THREADS_USE_ROO_TESTING)
78
79#include "roo_threads/impl/roo_testing/thread.h"
80
81namespace roo {
82
83/// @brief Thread abstraction for the selected backend.
84using thread = ::roo_threads::roo_testing::thread;
85
86namespace this_thread {
87
88/// @brief Returns the id of the calling thread.
89inline thread::id get_id() noexcept {
90 return roo_threads::roo_testing::this_thread::get_id();
91}
92
93/// @brief Hints the scheduler to switch to another thread.
94inline void yield() noexcept { roo_threads::roo_testing::this_thread::yield(); }
95
96/// @brief Suspends execution for at least the specified duration.
97/// @param duration sleep interval.
98inline void sleep_for(const roo_time::Duration& duration) {
99 roo_threads::roo_testing::this_thread::sleep_for(duration);
100}
101
102/// @brief Suspends execution until the specified uptime point.
103/// @param when wake-up time.
104inline void sleep_until(const roo_time::Uptime& when) {
105 roo_threads::roo_testing::this_thread::sleep_until(when);
106}
107
108} // namespace this_thread
109
110} // namespace roo
111
112#elif (defined ROO_THREADS_SINGLETHREADED)
113
115
116namespace roo {
117
118/// @brief Thread abstraction for the selected backend.
119using thread = roo_threads::singlethreaded::thread;
120
121namespace this_thread {
122
123/// @brief Returns the id of the calling thread.
124inline thread::id get_id() noexcept {
125 return roo_threads::singlethreaded::this_thread::get_id();
126}
127
128/// @brief Hints the scheduler to switch to another thread.
129inline void yield() noexcept {
130 roo_threads::singlethreaded::this_thread::yield();
131}
132
133/// @brief Suspends execution for at least the specified duration.
134/// @param duration sleep interval.
135inline void sleep_for(const roo_time::Duration& duration) {
136 roo_threads::singlethreaded::this_thread::sleep_for(duration);
137}
138
139/// @brief Suspends execution until the specified uptime point.
140/// @param when wake-up time.
141inline void sleep_until(const roo_time::Uptime& when) {
142 roo_threads::singlethreaded::this_thread::sleep_until(when);
143}
144
145} // namespace this_thread
146
147} // namespace roo
148
149#endif
thread::id get_id() noexcept
Returns identifier of the current thread.
void yield() noexcept
Hints the scheduler to run another thread.
void sleep_until(const roo_time::Uptime &when)
Blocks the current thread until the specified time point.
void sleep_for(const roo_time::Duration &duration)
Blocks the current thread for at least the given duration.
Definition latch.h:6