2424
2525#include < stdint.h>
2626#include " cmsis_os.h"
27+ #include " Callback.h"
2728
2829namespace rtos {
2930
@@ -37,26 +38,87 @@ class Thread {
3738 */
3839 Thread (osPriority priority=osPriorityNormal,
3940 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+ }
4144
4245 /* * Create a new thread, and start it executing the specified function.
4346 @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).
4547 @param priority initial priority of the thread function. (default: osPriorityNormal).
4648 @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
4749 @param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
4850 */
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+ */
4998 Thread (void (*task)(void const *argument), void *argument=NULL ,
5099 osPriority priority=osPriorityNormal,
51100 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+ }
53105
54106 /* * Starts a thread executing the specified function.
55107 @param task function to be executed by this thread.
56108 @param argument pointer that is passed to the thread function as start argument. (default: NULL).
57109 @return status code that indicates the execution status of the function.
58110 */
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+ }
60122
61123 /* * Wait for thread to terminate
62124 @return status code that indicates the execution status of the function.
@@ -165,6 +227,17 @@ class Thread {
165227 virtual ~Thread ();
166228
167229private:
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;
168241 osThreadId _tid;
169242 osThreadDef_t _thread_def;
170243 bool _dynamic_stack;
0 commit comments