24
24
25
25
#include < stdint.h>
26
26
#include " cmsis_os.h"
27
+ #include " Callback.h"
27
28
28
29
namespace rtos {
29
30
@@ -46,10 +47,62 @@ class Thread {
46
47
@param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
47
48
@param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
48
49
*/
50
+ Thread (mbed::Callback<void ()> task,
51
+ osPriority priority=osPriorityNormal,
52
+ uint32_t stack_size=DEFAULT_STACK_SIZE,
53
+ unsigned char *stack_pointer=NULL ) {
54
+ constructor (task, priority, stack_size, stack_pointer);
55
+ }
56
+
57
+ /* * Create a new thread, and start it executing the specified function.
58
+ @param obj argument to task.
59
+ @param method function to be executed by this thread.
60
+ @param argument pointer that is passed to the thread function as start argument. (default: NULL).
61
+ @param priority initial priority of the thread function. (default: osPriorityNormal).
62
+ @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
63
+ @param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
64
+ */
65
+ template <typename T>
66
+ Thread (T *obj, void (T::*method)(),
67
+ osPriority priority=osPriorityNormal,
68
+ uint32_t stack_size=DEFAULT_STACK_SIZE,
69
+ unsigned char *stack_pointer=NULL ) {
70
+ constructor (mbed::Callback<void ()>(obj, method),
71
+ priority, stack_size, stack_pointer);
72
+ }
73
+
74
+ /* * Create a new thread, and start it executing the specified function.
75
+ @param obj argument to task.
76
+ @param method function to be executed by this thread.
77
+ @param argument pointer that is passed to the thread function as start argument. (default: NULL).
78
+ @param priority initial priority of the thread function. (default: osPriorityNormal).
79
+ @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
80
+ @param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
81
+ */
82
+ template <typename T>
83
+ Thread (T *obj, void (*method)(T *),
84
+ osPriority priority=osPriorityNormal,
85
+ uint32_t stack_size=DEFAULT_STACK_SIZE,
86
+ unsigned char *stack_pointer=NULL ) {
87
+ constructor (mbed::Callback<void ()>(obj, method),
88
+ priority, stack_size, stack_pointer);
89
+ }
90
+
91
+ /* * Create a new thread, and start it executing the specified function.
92
+ Provided for backwards compatibility
93
+ @param task function to be executed by this thread.
94
+ @param argument pointer that is passed to the thread function as start argument. (default: NULL).
95
+ @param priority initial priority of the thread function. (default: osPriorityNormal).
96
+ @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
97
+ @param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
98
+ */
49
99
Thread (void (*task)(void const *argument), void *argument=NULL ,
50
100
osPriority priority=osPriorityNormal,
51
101
uint32_t stack_size=DEFAULT_STACK_SIZE,
52
- unsigned char *stack_pointer=NULL );
102
+ unsigned char *stack_pointer=NULL ) {
103
+ constructor (mbed::Callback<void ()>(argument, (void (*)(void *))task),
104
+ priority, stack_size, stack_pointer);
105
+ }
53
106
54
107
/* * Starts a thread executing the specified function.
55
108
@param task function to be executed by this thread.
@@ -165,6 +218,14 @@ class Thread {
165
218
virtual ~Thread ();
166
219
167
220
private:
221
+ // Required to share definitions without
222
+ // delegated constructors
223
+ void constructor (mbed::Callback<void ()> task,
224
+ osPriority priority=osPriorityNormal,
225
+ uint32_t stack_size=DEFAULT_STACK_SIZE,
226
+ unsigned char *stack_pointer=NULL);
227
+
228
+ mbed::Callback<void ()> _task;
168
229
osThreadId _tid;
169
230
osThreadDef_t _thread_def;
170
231
bool _dynamic_stack;
0 commit comments