Skip to content

Commit 21e68f3

Browse files
committed
Move configuration arguments to only constructor
1 parent d15cd78 commit 21e68f3

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

core/mbed-rtos/rtos/Thread.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,42 @@
2626

2727
namespace rtos {
2828

29-
Thread::Thread() {
29+
Thread::Thread(osPriority priority,
30+
uint32_t stack_size, unsigned char *stack_pointer) {
3031
_tid = NULL;
32+
_priority = priority;
33+
_stack_size = stack_size;
34+
_stack_pointer = stack_pointer;
3135
}
3236

3337
Thread::Thread(void (*task)(void const *argument), void *argument,
3438
osPriority priority, uint32_t stack_size, unsigned char *stack_pointer) {
3539
_tid = NULL;
36-
start(task, argument, priority, stack_size, stack_pointer);
40+
_priority = priority;
41+
_stack_size = stack_size;
42+
_stack_pointer = stack_pointer;
43+
start(task, argument);
3744
}
3845

39-
osStatus Thread::start(void (*task)(void const *argument), void *argument,
40-
osPriority priority, uint32_t stack_size, unsigned char *stack_pointer) {
46+
osStatus Thread::start(void (*task)(void const *argument), void *argument) {
4147
if (_tid != NULL) {
4248
return osErrorParameter;
4349
}
4450

4551
#ifdef __MBED_CMSIS_RTOS_CM
4652
_thread_def.pthread = task;
47-
_thread_def.tpriority = priority;
48-
_thread_def.stacksize = stack_size;
49-
if (stack_pointer != NULL) {
50-
_thread_def.stack_pointer = (uint32_t*)stack_pointer;
51-
_dynamic_stack = false;
53+
_thread_def.tpriority = _priority;
54+
_thread_def.stacksize = _stack_size;
55+
if (_stack_pointer != NULL) {
56+
_thread_def.stack_pointer = (uint32_t*)_stack_pointer;
5257
} else {
53-
_thread_def.stack_pointer = new uint32_t[stack_size/sizeof(uint32_t)];
58+
_thread_def.stack_pointer = new uint32_t[_stack_size/sizeof(uint32_t)];
5459
if (_thread_def.stack_pointer == NULL)
5560
error("Error allocating the stack memory\n");
56-
_dynamic_stack = true;
5761
}
5862

5963
//Fill the stack with a magic word for maximum usage checking
60-
for (uint32_t i = 0; i < (stack_size / sizeof(uint32_t)); i++) {
64+
for (uint32_t i = 0; i < (_stack_size / sizeof(uint32_t)); i++) {
6165
_thread_def.stack_pointer[i] = 0xE25A2EA5;
6266
}
6367
#endif
@@ -191,7 +195,7 @@ void Thread::attach_idle_hook(void (*fptr)(void)) {
191195
Thread::~Thread() {
192196
terminate();
193197
#ifdef __MBED_CMSIS_RTOS_CM
194-
if (_dynamic_stack) {
198+
if (_stack_pointer == NULL) {
195199
delete[] (_thread_def.stack_pointer);
196200
}
197201
#endif

core/mbed-rtos/rtos/Thread.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ namespace rtos {
3131
class Thread {
3232
public:
3333
/** Allocate a new thread without starting execution
34+
@param priority initial priority of the thread function. (default: osPriorityNormal).
35+
@param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
36+
@param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
3437
*/
35-
Thread();
38+
Thread(osPriority priority=osPriorityNormal,
39+
uint32_t stack_size=DEFAULT_STACK_SIZE,
40+
unsigned char *stack_pointer=NULL);
3641

3742
/** Create a new thread, and start it executing the specified function.
3843
@param task function to be executed by this thread.
@@ -49,15 +54,9 @@ class Thread {
4954
/** Starts a thread executing the specified function.
5055
@param task function to be executed by this thread.
5156
@param argument pointer that is passed to the thread function as start argument. (default: NULL).
52-
@param priority initial priority of the thread function. (default: osPriorityNormal).
53-
@param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
54-
@param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
5557
@return status code that indicates the execution status of the function.
5658
*/
57-
osStatus start(void (*task)(void const *argument), void *argument=NULL,
58-
osPriority priority=osPriorityNormal,
59-
uint32_t stack_size=DEFAULT_STACK_SIZE,
60-
unsigned char *stack_pointer=NULL);
59+
osStatus start(void (*task)(void const *argument), void *argument=NULL);
6160

6261
/** Wait for thread to terminate
6362
@return status code that indicates the execution status of the function.
@@ -164,7 +163,10 @@ class Thread {
164163
private:
165164
osThreadId _tid;
166165
osThreadDef_t _thread_def;
167-
bool _dynamic_stack;
166+
167+
osPriority _priority;
168+
uint32_t _stack_size;
169+
unsigned char *_stack_pointer;
168170
};
169171

170172
}

0 commit comments

Comments
 (0)