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
@@ -37,26 +38,87 @@ class Thread {
37
38
*/
38
39
Thread (osPriority priority=osPriorityNormal,
39
40
uint32_t stack_size=DEFAULT_STACK_SIZE,
40
- unsigned char *stack_pointer=NULL );
41
+ unsigned char *stack_pointer=NULL ) {
42
+ constructor (priority, stack_size, stack_pointer);
43
+ }
41
44
42
45
/* * Create a new thread, and start it executing the specified function.
43
46
@param task function to be executed by this thread.
44
- @param argument pointer that is passed to the thread function as start argument. (default: NULL).
45
47
@param priority initial priority of the thread function. (default: osPriorityNormal).
46
48
@param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
47
49
@param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
48
50
*/
51
+ Thread (mbed::Callback<void ()> task,
52
+ osPriority priority=osPriorityNormal,
53
+ uint32_t stack_size=DEFAULT_STACK_SIZE,
54
+ unsigned char *stack_pointer=NULL ) {
55
+ constructor (task, priority, stack_size, stack_pointer);
56
+ }
57
+
58
+ /* * Create a new thread, and start it executing the specified function.
59
+ @param obj argument to task.
60
+ @param method function to be executed by this thread.
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 priority initial priority of the thread function. (default: osPriorityNormal).
78
+ @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
79
+ @param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
80
+ */
81
+ template <typename T>
82
+ Thread (T *obj, void (*method)(T *),
83
+ osPriority priority=osPriorityNormal,
84
+ uint32_t stack_size=DEFAULT_STACK_SIZE,
85
+ unsigned char *stack_pointer=NULL ) {
86
+ constructor (mbed::Callback<void ()>(obj, method),
87
+ priority, stack_size, stack_pointer);
88
+ }
89
+
90
+ /* * Create a new thread, and start it executing the specified function.
91
+ Provided for backwards compatibility
92
+ @param task function to be executed by this thread.
93
+ @param argument pointer that is passed to the thread function as start argument. (default: NULL).
94
+ @param priority initial priority OF the thread function. (default: osPriorityNormal).
95
+ @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
96
+ @param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
97
+ */
49
98
Thread (void (*task)(void const *argument), void *argument=NULL ,
50
99
osPriority priority=osPriorityNormal,
51
100
uint32_t stack_size=DEFAULT_STACK_SIZE,
52
- unsigned char *stack_pointer=NULL );
101
+ unsigned char *stack_pointer=NULL ) {
102
+ constructor (mbed::Callback<void ()>(argument, (void (*)(void *))task),
103
+ priority, stack_size, stack_pointer);
104
+ }
53
105
54
106
/* * Starts a thread executing the specified function.
55
107
@param task function to be executed by this thread.
56
108
@param argument pointer that is passed to the thread function as start argument. (default: NULL).
57
109
@return status code that indicates the execution status of the function.
58
110
*/
59
- osStatus start (void (*task)(void const *argument), void *argument=NULL);
111
+ osStatus start (mbed::Callback<void ()> task);
112
+
113
+ /* * Starts a thread executing the specified function.
114
+ @param obj argument to task.
115
+ @param method function to be executed by this thread.
116
+ @return status code that indicates the execution status of the function.
117
+ */
118
+ template <typename T, typename M>
119
+ osStatus start (T *obj, M method) {
120
+ return start (mbed::Callback<void ()>(obj, method));
121
+ }
60
122
61
123
/* * Wait for thread to terminate
62
124
@return status code that indicates the execution status of the function.
@@ -165,6 +227,17 @@ class Thread {
165
227
virtual ~Thread ();
166
228
167
229
private:
230
+ // Required to share definitions without without
231
+ // delegated constructors
232
+ void constructor (osPriority priority=osPriorityNormal,
233
+ uint32_t stack_size=DEFAULT_STACK_SIZE,
234
+ unsigned char *stack_pointer=NULL );
235
+ void constructor (mbed::Callback<void ()> task,
236
+ osPriority priority=osPriorityNormal,
237
+ uint32_t stack_size=DEFAULT_STACK_SIZE,
238
+ unsigned char *stack_pointer=NULL);
239
+
240
+ mbed::Callback<void ()> _task;
168
241
osThreadId _tid;
169
242
osThreadDef_t _thread_def;
170
243
bool _dynamic_stack;
0 commit comments