Skip to content

Commit 1ef213e

Browse files
committed
Clean up Thread deprecation warnings
Static Thread methods and signal methods have been deprecated. Remove all references in the main code, and most of the tests. Some tests of the deprecated APIs themselves remain.
1 parent 8dcc949 commit 1ef213e

File tree

60 files changed

+159
-145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+159
-145
lines changed

TESTS/mbed_drivers/lp_ticker/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void test_multi_ticker(void)
7979
ticker[i].attach_us(callback(increment_multi_counter), MULTI_TICKER_TIME_MS * 1000);
8080
}
8181

82-
Thread::wait(MULTI_TICKER_TIME_MS + extra_wait);
82+
ThisThread::sleep_for(MULTI_TICKER_TIME_MS + extra_wait);
8383
TEST_ASSERT_EQUAL(TICKER_COUNT, multi_counter);
8484

8585
for (int i = 0; i < TICKER_COUNT; i++) {
@@ -95,7 +95,7 @@ void test_multi_ticker(void)
9595
ticker[i].attach_us(callback(increment_multi_counter), (MULTI_TICKER_TIME_MS + i) * 1000);
9696
}
9797

98-
Thread::wait(MULTI_TICKER_TIME_MS + TICKER_COUNT + extra_wait);
98+
ThisThread::sleep_for(MULTI_TICKER_TIME_MS + TICKER_COUNT + extra_wait);
9999
TEST_ASSERT_EQUAL(TICKER_COUNT, multi_counter);
100100

101101
for (int i = 0; i < TICKER_COUNT; i++) {

TESTS/mbed_drivers/mem_trace/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ static void test_case_multithread_malloc_free()
391391
threads[i].start(callback(malloc_free, &threads_continue));
392392
}
393393

394-
Thread::wait(wait_time_us);
394+
ThisThread::sleep_for(wait_time_us);
395395
threads_continue = false;
396396

397397
for (int i = 0; i < NUM_TEST_THREADS; i++) {

TESTS/mbed_drivers/race_test/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ class TestClass {
3939
public:
4040
TestClass()
4141
{
42-
Thread::wait(500);
42+
ThisThread::sleep_for(500);
4343
instance_count++;
4444
}
4545

4646
void do_something()
4747
{
48-
Thread::wait(100);
48+
ThisThread::sleep_for(100);
4949
}
5050

5151
~TestClass()
@@ -83,7 +83,7 @@ void test_case_func_race()
8383
// Start start first thread
8484
t1.start(cb);
8585
// Start second thread while the first is inside the constructor
86-
Thread::wait(250);
86+
ThisThread::sleep_for(250);
8787
t2.start(cb);
8888

8989
// Wait for the threads to finish
@@ -105,7 +105,7 @@ void test_case_class_race()
105105
// Start start first thread
106106
t1.start(cb);
107107
// Start second thread while the first is inside the constructor
108-
Thread::wait(250);
108+
ThisThread::sleep_for(250);
109109
t2.start(cb);
110110

111111
// Wait for the threads to finish

TESTS/mbed_drivers/ticker/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ void test_multi_ticker(void)
195195
ticker[i].attach_us(callback(increment_multi_counter), MULTI_TICKER_TIME_MS * 1000);
196196
}
197197

198-
Thread::wait(MULTI_TICKER_TIME_MS + extra_wait);
198+
ThisThread::sleep_for(MULTI_TICKER_TIME_MS + extra_wait);
199199
TEST_ASSERT_EQUAL(TICKER_COUNT, multi_counter);
200200

201201
for (int i = 0; i < TICKER_COUNT; i++) {
@@ -211,7 +211,7 @@ void test_multi_ticker(void)
211211
ticker[i].attach_us(callback(increment_multi_counter), (MULTI_TICKER_TIME_MS + i) * 1000);
212212
}
213213

214-
Thread::wait(MULTI_TICKER_TIME_MS + TICKER_COUNT + extra_wait);
214+
ThisThread::sleep_for(MULTI_TICKER_TIME_MS + TICKER_COUNT + extra_wait);
215215
TEST_ASSERT_EQUAL(TICKER_COUNT, multi_counter);
216216

217217
for (int i = 0; i < TICKER_COUNT; i++) {

TESTS/mbed_drivers/timeout/timeout_tests.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void test_multiple(void)
177177
for (size_t i = 0; i < NUM_TIMEOUTS; i++) {
178178
timeouts[i].attach_callback(mbed::callback(cnt_callback, &callback_count), TEST_DELAY_US);
179179
}
180-
Thread::wait(TEST_DELAY_MS + 2);
180+
ThisThread::sleep_for(TEST_DELAY_MS + 2);
181181
TEST_ASSERT_EQUAL(NUM_TIMEOUTS, callback_count);
182182
}
183183

TESTS/mbed_hal/sleep_manager_racecondition/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void sleep_manager_locking_thread_test()
3535
{
3636
for (uint32_t i = 0; i < 100; i++) {
3737
sleep_manager_lock_deep_sleep();
38-
Thread::wait(25);
38+
ThisThread::sleep_for(25);
3939
sleep_manager_unlock_deep_sleep();
4040
}
4141
}
@@ -48,7 +48,7 @@ void sleep_manager_multithread_test()
4848
Thread t2(osPriorityNormal, TEST_STACK_SIZE);
4949

5050
t1.start(callback(cb));
51-
Thread::wait(25);
51+
ThisThread::sleep_for(25);
5252
t2.start(callback(cb));
5353

5454
// Wait for the threads to finish

TESTS/mbed_platform/stats_cpu/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void get_cpu_usage()
5656
uint8_t usage = 100 - ((diff * 100) / (SAMPLE_TIME * 1000));
5757
prev_idle_time = stats.idle_time;
5858
TEST_ASSERT_NOT_EQUAL(0, usage);
59-
Thread::wait(SAMPLE_TIME);
59+
ThisThread::sleep_for(SAMPLE_TIME);
6060
}
6161
}
6262

@@ -65,7 +65,7 @@ void test_cpu_info(void)
6565
mbed_stats_cpu_t stats;
6666
// Additional read to make sure timer is initialized
6767
mbed_stats_cpu_get(&stats);
68-
Thread::wait(3);
68+
ThisThread::sleep_for(3);
6969
mbed_stats_cpu_get(&stats);
7070
TEST_ASSERT_NOT_EQUAL(0, stats.uptime);
7171
TEST_ASSERT_NOT_EQUAL(0, stats.idle_time);
@@ -83,7 +83,7 @@ void test_cpu_load(void)
8383

8484
// Steadily increase the system load
8585
for (int count = 1; ; count++) {
86-
Thread::wait(LOOP_TIME);
86+
ThisThread::sleep_for(LOOP_TIME);
8787
if (wait_time <= 0) {
8888
break;
8989
}

TESTS/mbed_platform/stats_thread/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void increment_with_delay()
4646
{
4747
while (1) {
4848
counter++;
49-
Thread::wait(500);
49+
ThisThread::sleep_for(500);
5050
}
5151
}
5252

@@ -111,7 +111,7 @@ void test_case_multi_threads_blocked()
111111
uint32_t ret = ef.set(FLAG_SIGNAL_DEC);
112112
TEST_ASSERT_FALSE(ret & osFlagsError);
113113

114-
Thread::wait(100);
114+
ThisThread::sleep_for(100);
115115

116116
count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
117117
TEST_ASSERT_EQUAL(1, (count - old_count));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ static const int test_timeout = 40;
4848
void update_tick_thread(Mutex *mutex)
4949
{
5050
while (true) {
51-
Thread::wait(1);
51+
ThisThread::sleep_for(1);
5252
mutex->lock();
5353
++elapsed_time_ms;
5454
mutex->unlock();
5555
}
5656
}
5757

5858

59-
/** Tests is to measure the accuracy of Thread::wait() over a period of time
59+
/** Tests is to measure the accuracy of ThisThread::sleep_for() over a period of time
6060
6161
Given
6262
a thread updating elapsed_time_ms every milli sec
@@ -109,7 +109,7 @@ void test(void)
109109
}
110110

111111
Case cases[] = {
112-
Case("Test Thread::wait accuracy", test)
112+
Case("Test ThisThread::sleep_for accuracy", test)
113113
};
114114

115115
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void send_thread(EventFlags *ef)
7575
const uint32_t flag = flags & (1 << i);
7676
if (flag) {
7777
ef->set(flag);
78-
Thread::wait(wait_ms);
78+
ThisThread::sleep_for(wait_ms);
7979
}
8080
}
8181
}
@@ -88,7 +88,7 @@ void send_thread_sync(EventFlags *ef)
8888
if (flag) {
8989
sync_sem.wait();
9090
ef->set(flag);
91-
Thread::wait(wait_ms);
91+
ThisThread::sleep_for(wait_ms);
9292
}
9393
}
9494
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void test_heap_allocation_free(void)
226226
check_and_free_heap(head, max_allocation_size);
227227

228228
// Force a task switch so a stack check is performed
229-
Thread::wait(10);
229+
ThisThread::sleep_for(10);
230230

231231
printf("Total size dynamically allocated: %luB\n", max_allocation_size);
232232
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void send_thread(Mail<mail_t, QUEUE_SIZE> *m)
6262
mail->thread_id = thread_id;
6363
mail->data = data++;
6464
m->put(mail);
65-
Thread::wait(wait_ms);
65+
ThisThread::sleep_for(wait_ms);
6666
}
6767
}
6868

@@ -72,7 +72,7 @@ void receive_thread(Mail<mail_t, queue_size> *m)
7272
int result_counter = 0;
7373
uint32_t data = thread_id * DATA_BASE;
7474

75-
Thread::wait(wait_ms);
75+
ThisThread::sleep_for(wait_ms);
7676
for (uint32_t i = 0; i < queue_size; i++) {
7777
osEvent evt = m->get();
7878
if (evt.status == osEventMail) {
@@ -108,7 +108,7 @@ void test_single_thread_order(void)
108108
thread.start(callback(send_thread<THREAD_1_ID, QUEUE_PUT_DELAY_1, QUEUE_SIZE>, &mail_box));
109109

110110
// wait for some mail to be collected
111-
Thread::wait(10);
111+
ThisThread::sleep_for(10);
112112

113113
for (uint32_t i = 0; i < QUEUE_SIZE; i++) {
114114
// mail receive (main thread)
@@ -150,7 +150,7 @@ void test_multi_thread_order(void)
150150
thread3.start(callback(send_thread<THREAD_3_ID, QUEUE_PUT_DELAY_3, 4>, &mail_box));
151151

152152
// wait for some mail to be collected
153-
Thread::wait(10);
153+
ThisThread::sleep_for(10);
154154

155155
for (uint32_t i = 0; i < QUEUE_SIZE; i++) {
156156
// mail receive (main thread)
@@ -211,7 +211,7 @@ void test_multi_thread_multi_mail_order(void)
211211
mail->data = data[id]++;
212212
mail_box[id].put(mail);
213213

214-
Thread::wait(i * 10);
214+
ThisThread::sleep_for(i * 10);
215215
}
216216

217217
thread1.join();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void test_multithread_allocation(void)
9090

9191
// Give the test time to run
9292
while (test_time--) {
93-
Thread::wait(1000);
93+
ThisThread::sleep_for(1000);
9494
}
9595

9696
// Join and delete all threads

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ bool manipulate_protected_zone(const int thread_delay)
6262
change_counter++;
6363
core_util_critical_section_exit();
6464

65-
Thread::wait(thread_delay);
65+
ThisThread::sleep_for(thread_delay);
6666

6767
core_util_critical_section_enter();
6868
changing_counter = false;
@@ -100,7 +100,7 @@ void test_multiple_threads(void)
100100

101101
while (true) {
102102
// Thread 1 action
103-
Thread::wait(t1_delay);
103+
ThisThread::sleep_for(t1_delay);
104104
manipulate_protected_zone(t1_delay);
105105

106106
core_util_critical_section_enter();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ using namespace utest::v1;
3737
template <uint32_t ms>
3838
void thread_put_uint_msg(Queue<uint32_t, 1> *q)
3939
{
40-
Thread::wait(ms);
40+
ThisThread::sleep_for(ms);
4141
osStatus stat = q->put((uint32_t *) TEST_UINT_MSG);
4242
TEST_ASSERT_EQUAL(osOK, stat);
4343
}
4444

4545
template <uint32_t ms, uint32_t val>
4646
void thread_get_uint_msg(Queue<uint32_t, 1> *q)
4747
{
48-
Thread::wait(ms);
48+
ThisThread::sleep_for(ms);
4949
osEvent evt = q->get();
5050
TEST_ASSERT_EQUAL(osEventMessage, evt.status);
5151
TEST_ASSERT_EQUAL(val, evt.value.v);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void test_thread(int const *delay)
5252
if (sem_lock_failed) {
5353
sem_defect = true;
5454
}
55-
Thread::wait(thread_delay);
55+
ThisThread::sleep_for(thread_delay);
5656
sem_counter--;
5757
change_counter++;
5858
two_slots.release();
@@ -123,15 +123,15 @@ void test_single_thread()
123123

124124
res = t.start(callback(single_thread, &data));
125125
TEST_ASSERT_EQUAL(osOK, res);
126-
Thread::wait(SHORT_WAIT);
126+
ThisThread::sleep_for(SHORT_WAIT);
127127

128128
TEST_ASSERT_EQUAL(Thread::WaitingSemaphore, t.get_state());
129129
TEST_ASSERT_EQUAL(0, data.data);
130130

131131
res = sem.release();
132132
TEST_ASSERT_EQUAL(osOK, res);
133133

134-
Thread::wait(SHORT_WAIT);
134+
ThisThread::sleep_for(SHORT_WAIT);
135135

136136
TEST_ASSERT_EQUAL(1, data.data);
137137

@@ -160,7 +160,7 @@ void test_timeout()
160160
timer.start();
161161
res = t.start(callback(timeout_thread, &sem));
162162
TEST_ASSERT_EQUAL(osOK, res);
163-
Thread::wait(SHORT_WAIT);
163+
ThisThread::sleep_for(SHORT_WAIT);
164164

165165
TEST_ASSERT_EQUAL(Thread::WaitingSemaphore, t.get_state());
166166

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void run_wait_clear(Sync *sync)
103103
{
104104
sync->sem_parent.release();
105105
sync->sem_child.wait();
106-
int32_t ret = Thread::signal_clr(signals);
106+
int32_t ret = ThisThread::flags_clear(signals);
107107
TEST_ASSERT_EQUAL(test_val, ret);
108108
}
109109

@@ -114,10 +114,10 @@ void run_double_wait_clear(Sync *sync)
114114

115115
sync->sem_parent.release();
116116
sync->sem_child.wait();
117-
ret = Thread::signal_clr(signals1);
117+
ret = ThisThread::flags_clear(signals1);
118118
TEST_ASSERT_EQUAL(test_val1, ret);
119119

120-
ret = Thread::signal_clr(signals2);
120+
ret = ThisThread::flags_clear(signals2);
121121
TEST_ASSERT_EQUAL(test_val2, ret);
122122
}
123123

@@ -128,7 +128,7 @@ void run_loop_wait_clear(Sync *sync)
128128
int32_t signal = 1 << i;
129129
signals |= signal;
130130
sync->sem_child.wait();
131-
int32_t ret = Thread::signal_clr(NO_SIGNALS);
131+
int32_t ret = ThisThread::flags_clear(NO_SIGNALS);
132132
TEST_ASSERT_EQUAL(signals, ret);
133133
sync->sem_parent.release();
134134
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ void test_thread_wait()
474474
Timer timer;
475475
timer.start();
476476

477-
Thread::wait(150);
477+
ThisThread::sleep_for(150);
478478

479479
TEST_ASSERT_UINT32_WITHIN(50000, 150000, timer.read_us());
480480
}
@@ -528,7 +528,7 @@ void test_deleted()
528528

529529
void test_delay_thread()
530530
{
531-
Thread::wait(50);
531+
ThisThread::sleep_for(50);
532532
}
533533

534534
/** Testing thread states: wait delay

TESTS/netsocket/tcp/tcpsocket_echotest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
119119

120120
tcpsocket_connect_to_echo_srv(sock);
121121
sock.set_blocking(false);
122-
sock.sigio(callback(_sigio_handler, Thread::gettid()));
122+
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
123123

124124
int bytes2send;
125125
int sent;

0 commit comments

Comments
 (0)