31
31
32
32
namespace rtos {
33
33
34
- /* * The Thread class allow defining, creating, and controlling thread functions in the system. */
34
+ /* * The Thread class allow defining, creating, and controlling thread functions in the system.
35
+ *
36
+ * Example:
37
+ * @code
38
+ * #include "mbed.h"
39
+ * #include "rtos.h"
40
+ *
41
+ * Thread thread;
42
+ * DigitalOut led1(LED1);
43
+ * volatile bool running = true;
44
+ *
45
+ * // Blink function toggles the led in a long running loop
46
+ * void blink(DigitalOut *led) {
47
+ * while (running) {
48
+ * *led = !*led;
49
+ * Thread::wait(1000);
50
+ * }
51
+ * }
52
+ *
53
+ * // Spawns a thread to run blink for 5 seconds
54
+ * int main() {
55
+ * thread.start(led1, blink);
56
+ * Thread::wait(5000);
57
+ * running = false;
58
+ * thread.join();
59
+ * }
60
+ * @endcode
61
+ */
35
62
class Thread {
36
63
public:
37
64
/* * Allocate a new thread without starting execution
@@ -52,15 +79,20 @@ class Thread {
52
79
@param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
53
80
@param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
54
81
@deprecated
55
- Thread-spawning constructors hide errors and may lead to complex
56
- program state when a thread is declared.
82
+ Thread-spawning constructors hide errors. Replaced by thread.start(task).
57
83
58
- The explicit Thread::start member function should be used to spawn
59
- a thread.
84
+ @code
85
+ Thread thread(priority, stack_size, stack_pointer);
86
+
87
+ osStatus status = thread.start(task);
88
+ if (status != osOK) {
89
+ error("oh no!");
90
+ }
91
+ @endcode
60
92
*/
61
93
MBED_DEPRECATED_SINCE (" mbed-os-5.1" ,
62
- " Thread-spawning constructors hide errors and may lead to complex "
63
- " program state when a thread is declared " )
94
+ " Thread-spawning constructors hide errors. "
95
+ " Replaced by thread.start(task). " )
64
96
Thread (mbed::Callback<void ()> task,
65
97
osPriority priority=osPriorityNormal,
66
98
uint32_t stack_size=DEFAULT_STACK_SIZE,
@@ -76,21 +108,26 @@ class Thread {
76
108
@param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
77
109
@param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
78
110
@deprecated
79
- Thread-spawning constructors hide errors and may lead to complex
80
- program state when a thread is declared.
111
+ Thread-spawning constructors hide errors. Replaced by thread.start(callback(argument, task)).
112
+
113
+ @code
114
+ Thread thread(priority, stack_size, stack_pointer);
81
115
82
- The explicit Thread::start member function should be used to spawn
83
- a thread.
116
+ osStatus status = thread.start(callback(argument, task));
117
+ if (status != osOK) {
118
+ error("oh no!");
119
+ }
120
+ @endcode
84
121
*/
85
122
template <typename T>
86
123
MBED_DEPRECATED_SINCE (" mbed-os-5.1" ,
87
- " Thread-spawning constructors hide errors and may lead to complex "
88
- " program state when a thread is declared " )
89
- Thread (T *obj , void (T::*method )(),
124
+ " Thread-spawning constructors hide errors. "
125
+ " Replaced by thread.start(callback(argument, task)). " )
126
+ Thread (T *argument , void (T::*task )(),
90
127
osPriority priority=osPriorityNormal,
91
128
uint32_t stack_size=DEFAULT_STACK_SIZE,
92
129
unsigned char *stack_pointer=NULL ) {
93
- constructor (mbed::callback (obj, method ),
130
+ constructor (mbed::callback (argument, task ),
94
131
priority, stack_size, stack_pointer);
95
132
}
96
133
@@ -102,21 +139,26 @@ class Thread {
102
139
@param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
103
140
@param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
104
141
@deprecated
105
- Thread-spawning constructors hide errors and may lead to complex
106
- program state when a thread is declared.
142
+ Thread-spawning constructors hide errors. Replaced by thread.start(callback(argument, task)).
107
143
108
- The explicit Thread::start member function should be used to spawn
109
- a thread.
144
+ @code
145
+ Thread thread(priority, stack_size, stack_pointer);
146
+
147
+ osStatus status = thread.start(callback(argument, task));
148
+ if (status != osOK) {
149
+ error("oh no!");
150
+ }
151
+ @endcode
110
152
*/
111
153
template <typename T>
112
154
MBED_DEPRECATED_SINCE (" mbed-os-5.1" ,
113
- " Thread-spawning constructors hide errors and may lead to complex "
114
- " program state when a thread is declared " )
115
- Thread (T *obj , void (*method )(T *),
155
+ " Thread-spawning constructors hide errors. "
156
+ " Replaced by thread.start(callback(argument, task)). " )
157
+ Thread (T *argument , void (*task )(T *),
116
158
osPriority priority=osPriorityNormal,
117
159
uint32_t stack_size=DEFAULT_STACK_SIZE,
118
160
unsigned char *stack_pointer=NULL ) {
119
- constructor (mbed::callback (obj, method ),
161
+ constructor (mbed::callback (argument, task ),
120
162
priority, stack_size, stack_pointer);
121
163
}
122
164
@@ -128,15 +170,20 @@ class Thread {
128
170
@param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
129
171
@param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
130
172
@deprecated
131
- Thread-spawning constructors hide errors and may lead to complex
132
- program state when a thread is declared.
173
+ Thread-spawning constructors hide errors. Replaced by thread.start(callback(argument, task)).
174
+
175
+ @code
176
+ Thread thread(priority, stack_size, stack_pointer);
133
177
134
- The explicit Thread::start member function should be used to spawn
135
- a thread.
178
+ osStatus status = thread.start(callback(argument, task));
179
+ if (status != osOK) {
180
+ error("oh no!");
181
+ }
182
+ @endcode
136
183
*/
137
184
MBED_DEPRECATED_SINCE (" mbed-os-5.1" ,
138
- " Thread-spawning constructors hide errors and may lead to complex "
139
- " program state when a thread is declared " )
185
+ " Thread-spawning constructors hide errors. "
186
+ " Replaced by thread.start(callback(argument, task)). " )
140
187
Thread (void (*task)(void const *argument), void *argument=NULL ,
141
188
osPriority priority=osPriorityNormal,
142
189
uint32_t stack_size=DEFAULT_STACK_SIZE,
@@ -156,13 +203,12 @@ class Thread {
156
203
@param method function to be executed by this thread.
157
204
@return status code that indicates the execution status of the function.
158
205
@deprecated
159
- The start function does not support cv-qualifiers. Replaced by
160
- start(callback(obj, method)).
206
+ The start function does not support cv-qualifiers. Replaced by start(callback(obj, method)).
161
207
*/
162
208
template <typename T, typename M>
163
209
MBED_DEPRECATED_SINCE (" mbed-os-5.1" ,
164
- " The start function does not support cv-qualifiers. Replaced by "
165
- " start(callback(obj, method))." )
210
+ " The start function does not support cv-qualifiers. "
211
+ " Replaced by thread. start(callback(obj, method))." )
166
212
osStatus start (T *obj, M method) {
167
213
return start (mbed::callback (obj, method));
168
214
}
0 commit comments