15
15
* the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
16
16
* and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
17
17
*/
18
- #if defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832)
19
- #define STACK_SIZE 512
20
- #elif defined(TARGET_STM32F070RB) || defined(TARGET_STM32F072RB) || defined(TARGET_STM32F103RB) || defined(TARGET_STM32F091RC)
21
- #define STACK_SIZE 512
22
- #elif defined(TARGET_STM32F410RB)
23
- #define STACK_SIZE 512
24
- #elif defined(TARGET_STM32L073RZ)
25
- #define STACK_SIZE 512
26
- #elif defined(TARGET_XDOT_L151CC)
27
- #define STACK_SIZE 1024
28
- #elif defined(TARGET_HI2110)
29
- #define STACK_SIZE 512
30
- #elif defined(TARGET_EFR32)
31
- #define STACK_SIZE 512
32
- #else
33
- #define STACK_SIZE DEFAULT_STACK_SIZE
34
- #endif
18
+ #define PARALLEL_STACK_SIZE 512
35
19
36
20
using namespace utest ::v1;
37
21
@@ -55,7 +39,8 @@ void increment_with_wait(counter_t* counter) {
55
39
}
56
40
57
41
void increment_with_child (counter_t * counter) {
58
- Thread child (counter, increment, osPriorityNormal, STACK_SIZE);
42
+ Thread child;
43
+ child.start (callback (increment, counter));
59
44
child.join ();
60
45
}
61
46
@@ -64,7 +49,8 @@ void increment_with_murder(counter_t* counter) {
64
49
// take ownership of the counter mutex so it prevent the child to
65
50
// modify counter.
66
51
LockGuard lock (counter->internal_mutex ());
67
- Thread child (counter, increment, osPriorityNormal, STACK_SIZE);
52
+ Thread child;
53
+ child.start (callback (increment, counter));
68
54
child.terminate ();
69
55
}
70
56
@@ -81,7 +67,8 @@ void self_terminate(Thread *self) {
81
67
template <void (*F)(counter_t *)>
82
68
void test_single_thread () {
83
69
counter_t counter (0 );
84
- Thread thread (&counter, F, osPriorityNormal, STACK_SIZE);
70
+ Thread thread;
71
+ thread.start (callback (F, &counter));
85
72
thread.join ();
86
73
TEST_ASSERT_EQUAL (counter, 1 );
87
74
}
@@ -92,7 +79,8 @@ void test_parallel_threads() {
92
79
Thread *threads[N];
93
80
94
81
for (int i = 0 ; i < N; i++) {
95
- threads[i] = new Thread (&counter, F, osPriorityNormal, STACK_SIZE);
82
+ threads[i] = new Thread (osPriorityNormal, PARALLEL_STACK_SIZE);
83
+ threads[i]->start (callback (F, &counter));
96
84
}
97
85
98
86
for (int i = 0 ; i < N; i++) {
@@ -108,16 +96,17 @@ void test_serial_threads() {
108
96
counter_t counter (0 );
109
97
110
98
for (int i = 0 ; i < N; i++) {
111
- Thread thread (&counter, F, osPriorityNormal, STACK_SIZE);
99
+ Thread thread;
100
+ thread.start (callback (F, &counter));
112
101
thread.join ();
113
102
}
114
103
115
104
TEST_ASSERT_EQUAL (counter, N);
116
105
}
117
106
118
107
void test_self_terminate () {
119
- Thread *thread = new Thread (osPriorityNormal, STACK_SIZE );
120
- thread->start (thread, self_terminate );
108
+ Thread *thread = new Thread ();
109
+ thread->start (callback (self_terminate, thread) );
121
110
thread->join ();
122
111
delete thread;
123
112
}
0 commit comments