Skip to content

Commit 306cc1a

Browse files
authored
Merge pull request #3490 from ARMmbed/fix_deprecated_thread_ctors
Fix deprecated Thread ctor usage in RTOS tests
2 parents 24cd573 + ed41ebe commit 306cc1a

File tree

7 files changed

+40
-25
lines changed

7 files changed

+40
-25
lines changed

TESTS/mbedmicro-rtos-mbed/isr/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void queue_isr() {
4040
myled = !myled;
4141
}
4242

43-
void queue_thread(void const *argument) {
43+
void queue_thread() {
4444
while (true) {
4545
queue.put((uint32_t*)QUEUE_PUT_THREAD_VALUE);
4646
Thread::wait(THREAD_DELAY);
@@ -50,7 +50,8 @@ void queue_thread(void const *argument) {
5050
int main (void) {
5151
GREENTEA_SETUP(20, "default_auto");
5252

53-
Thread thread(queue_thread, NULL, osPriorityNormal, STACK_SIZE);
53+
Thread thread(osPriorityNormal, STACK_SIZE);
54+
thread.start(queue_thread);
5455
Ticker ticker;
5556
ticker.attach(queue_isr, 1.0);
5657
int isr_puts_counter = 0;

TESTS/mbedmicro-rtos-mbed/mail/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ typedef struct {
3838

3939
Mail<mail_t, QUEUE_SIZE> mail_box;
4040

41-
void send_thread (void const *argument) {
41+
void send_thread () {
4242
static uint32_t i = 10;
4343
while (true) {
4444
i++; // fake data update
@@ -54,7 +54,8 @@ void send_thread (void const *argument) {
5454
int main (void) {
5555
GREENTEA_SETUP(20, "default_auto");
5656

57-
Thread thread(send_thread, NULL, osPriorityNormal, STACK_SIZE);
57+
Thread thread(osPriorityNormal, STACK_SIZE);
58+
thread.start(send_thread);
5859
bool result = true;
5960
int result_counter = 0;
6061

TESTS/mbedmicro-rtos-mbed/mutex/main.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ bool manipulate_protected_zone(const int thread_delay) {
7777
return result;
7878
}
7979

80-
void test_thread(void const *args) {
81-
const int thread_delay = int(args);
80+
void test_thread(int const *thread_delay) {
8281
while (true) {
83-
manipulate_protected_zone(thread_delay);
82+
manipulate_protected_zone(*thread_delay);
8483
}
8584
}
8685

@@ -90,8 +89,11 @@ int main() {
9089
const int t1_delay = THREAD_DELAY * 1;
9190
const int t2_delay = THREAD_DELAY * 2;
9291
const int t3_delay = THREAD_DELAY * 3;
93-
Thread t2(test_thread, (void *)t2_delay, osPriorityNormal, STACK_SIZE);
94-
Thread t3(test_thread, (void *)t3_delay, osPriorityNormal, STACK_SIZE);
92+
Thread t2(osPriorityNormal, STACK_SIZE);
93+
Thread t3(osPriorityNormal, STACK_SIZE);
94+
95+
t2.start(callback(test_thread, &t2_delay));
96+
t3.start(callback(test_thread, &t3_delay));
9597

9698
while (true) {
9799
// Thread 1 action

TESTS/mbedmicro-rtos-mbed/queue/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ MemoryPool<message_t, QUEUE_SIZE> mpool;
4040
Queue<message_t, QUEUE_SIZE> queue;
4141

4242
/* Send Thread */
43-
void send_thread (void const *argument) {
43+
void send_thread () {
4444
static uint32_t i = 10;
4545
while (true) {
4646
i++; // Fake data update
@@ -56,7 +56,8 @@ void send_thread (void const *argument) {
5656
int main (void) {
5757
GREENTEA_SETUP(20, "default_auto");
5858

59-
Thread thread(send_thread, NULL, osPriorityNormal, STACK_SIZE);
59+
Thread thread(osPriorityNormal, STACK_SIZE);
60+
thread.start(send_thread);
6061
bool result = true;
6162
int result_counter = 0;
6263

TESTS/mbedmicro-rtos-mbed/semaphore/main.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ volatile int change_counter = 0;
5656
volatile int sem_counter = 0;
5757
volatile bool sem_defect = false;
5858

59-
void test_thread(void const *delay) {
60-
const int thread_delay = int(delay);
59+
void test_thread(int const *delay) {
60+
const int thread_delay = *delay;
6161
while (true) {
6262
two_slots.wait();
6363
sem_counter++;
@@ -81,9 +81,13 @@ int main (void) {
8181
const int t1_delay = THREAD_DELAY * 1;
8282
const int t2_delay = THREAD_DELAY * 2;
8383
const int t3_delay = THREAD_DELAY * 3;
84-
Thread t1(test_thread, (void *)t1_delay, osPriorityNormal, STACK_SIZE);
85-
Thread t2(test_thread, (void *)t2_delay, osPriorityNormal, STACK_SIZE);
86-
Thread t3(test_thread, (void *)t3_delay, osPriorityNormal, STACK_SIZE);
84+
Thread t1(osPriorityNormal, STACK_SIZE);
85+
Thread t2(osPriorityNormal, STACK_SIZE);
86+
Thread t3(osPriorityNormal, STACK_SIZE);
87+
88+
t1.start(callback(test_thread, &t1_delay));
89+
t2.start(callback(test_thread, &t2_delay));
90+
t3.start(callback(test_thread, &t3_delay));
8791

8892
while (true) {
8993
if (change_counter >= SEM_CHANGES or sem_defect == true) {

TESTS/mbedmicro-rtos-mbed/signals/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const int SIGNAL_HANDLE_DELEY = 25;
3232
DigitalOut led(LED1);
3333
int signal_counter = 0;
3434

35-
void led_thread(void const *argument) {
35+
void led_thread() {
3636
while (true) {
3737
// Signal flags that are reported as event are automatically cleared.
3838
Thread::signal_wait(SIGNAL_SET_VALUE);
@@ -44,7 +44,8 @@ void led_thread(void const *argument) {
4444
int main (void) {
4545
GREENTEA_SETUP(20, "default_auto");
4646

47-
Thread thread(led_thread, NULL, osPriorityNormal, STACK_SIZE);
47+
Thread thread(osPriorityNormal, STACK_SIZE);
48+
thread.start(led_thread);
4849
bool result = false;
4950

5051
printf("Handling %d signals...\r\n", SIGNALS_TO_EMIT);

TESTS/mbedmicro-rtos-mbed/threads/main.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ void increment_with_wait(counter_t* counter) {
3939
}
4040

4141
void increment_with_child(counter_t* counter) {
42-
Thread child(counter, increment);
42+
Thread child;
43+
child.start(callback(increment, counter));
4344
child.join();
4445
}
4546

@@ -48,7 +49,8 @@ void increment_with_murder(counter_t* counter) {
4849
// take ownership of the counter mutex so it prevent the child to
4950
// modify counter.
5051
LockGuard lock(counter->internal_mutex());
51-
Thread child(counter, increment);
52+
Thread child;
53+
child.start(callback(increment, counter));
5254
child.terminate();
5355
}
5456

@@ -65,7 +67,8 @@ void self_terminate(Thread *self) {
6567
template <void (*F)(counter_t *)>
6668
void test_single_thread() {
6769
counter_t counter(0);
68-
Thread thread(&counter, F);
70+
Thread thread;
71+
thread.start(callback(F, &counter));
6972
thread.join();
7073
TEST_ASSERT_EQUAL(counter, 1);
7174
}
@@ -76,7 +79,8 @@ void test_parallel_threads() {
7679
Thread *threads[N];
7780

7881
for (int i = 0; i < N; i++) {
79-
threads[i] = new Thread(&counter, F, osPriorityNormal, PARALLEL_STACK_SIZE);
82+
threads[i] = new Thread(osPriorityNormal, PARALLEL_STACK_SIZE);
83+
threads[i]->start(callback(F, &counter));
8084
}
8185

8286
for (int i = 0; i < N; i++) {
@@ -92,16 +96,17 @@ void test_serial_threads() {
9296
counter_t counter(0);
9397

9498
for (int i = 0; i < N; i++) {
95-
Thread thread(&counter, F);
99+
Thread thread;
100+
thread.start(callback(F, &counter));
96101
thread.join();
97102
}
98103

99104
TEST_ASSERT_EQUAL(counter, N);
100105
}
101106

102107
void test_self_terminate() {
103-
Thread *thread = new Thread(osPriorityNormal);
104-
thread->start(thread, self_terminate);
108+
Thread *thread = new Thread();
109+
thread->start(callback(self_terminate, thread));
105110
thread->join();
106111
delete thread;
107112
}

0 commit comments

Comments
 (0)