Skip to content

Commit 45de008

Browse files
committed
Incorporated the review comment
1 parent 176c599 commit 45de008

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

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

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ using utest::v1::Case;
3636

3737
#define MAX_FLAG_POS 30
3838
#define PROHIBITED_FLAG_POS 31
39-
static bool is_ticker_used = false; /* This flag protects avoid calling ThisThread::sleep_for as it is not safe to call in IRQ mode. */
4039

4140
/* flags */
4241
#define FLAG01 0x1FFF /* 00000000000000000001111111111111 */
@@ -45,14 +44,13 @@ static bool is_ticker_used = false; /* This flag protects avoid calling ThisThre
4544
#define PROHIBITED_FLAG 0x80000000 /* 10000000000000000000000000000000 */
4645
#define NO_FLAGS 0x0
4746

48-
template<uint32_t flags, uint32_t wait_ms>
49-
void send_thread(EventFlags *ef)
47+
void send_thread(EventFlags *ef, uint32_t flags, uint32_t wait_ms)
5048
{
5149
for (uint32_t i = 0; i <= MAX_FLAG_POS; i++) {
5250
const uint32_t flag = flags & (1 << i);
5351
if (flag) {
5452
ef->set(flag);
55-
if (!is_ticker_used) {
53+
if (wait_ms != 0) {
5654
ThisThread::sleep_for(wait_ms);
5755
}
5856
}
@@ -220,9 +218,9 @@ void test_multi_thread_all(void)
220218
Thread thread1(osPriorityNormal, THREAD_STACK_SIZE);
221219
Thread thread2(osPriorityNormal, THREAD_STACK_SIZE);
222220
Thread thread3(osPriorityNormal, THREAD_STACK_SIZE);
223-
thread1.start(callback(send_thread<FLAG01, 1>, &ef));
224-
thread2.start(callback(send_thread<FLAG02, 2>, &ef));
225-
thread3.start(callback(send_thread<FLAG03, 3>, &ef));
221+
thread1.start([&] { send_thread(&ef, FLAG01, 1); });
222+
thread2.start([&] { send_thread(&ef, FLAG02, 2); });
223+
thread3.start([&] { send_thread(&ef, FLAG03, 3); });
226224

227225
uint32_t ret = ef.wait_all(FLAG01 | FLAG02 | FLAG03);
228226
TEST_ASSERT_EQUAL(FLAG01 | FLAG02 | FLAG03, ret);
@@ -241,9 +239,9 @@ void test_multi_thread_any(void)
241239
Thread thread1(osPriorityNormal, THREAD_STACK_SIZE);
242240
Thread thread2(osPriorityNormal, THREAD_STACK_SIZE);
243241
Thread thread3(osPriorityNormal, THREAD_STACK_SIZE);
244-
thread1.start(callback(send_thread<FLAG01, 1>, &ef));
245-
thread2.start(callback(send_thread<FLAG02, 1>, &ef));
246-
thread3.start(callback(send_thread<FLAG03, 1>, &ef));
242+
thread1.start([&] { send_thread(&ef, FLAG01, 1); });
243+
thread2.start([&] { send_thread(&ef, FLAG02, 1); });
244+
thread3.start([&] { send_thread(&ef, FLAG03, 1); });
247245

248246
for (int i = 0; i <= MAX_FLAG_POS; i++) {
249247
uint32_t flag = 1 << i;
@@ -296,9 +294,9 @@ void test_multi_thread_any_no_clear(void)
296294
Thread thread1(osPriorityNormal, THREAD_STACK_SIZE);
297295
Thread thread2(osPriorityNormal, THREAD_STACK_SIZE);
298296
Thread thread3(osPriorityNormal, THREAD_STACK_SIZE);
299-
thread1.start(callback(send_thread<FLAG01, 1>, &ef));
300-
thread2.start(callback(send_thread<FLAG02, 1>, &ef));
301-
thread3.start(callback(send_thread<FLAG03, 1>, &ef));
297+
thread1.start([&] { send_thread(&ef, FLAG01, 1); });
298+
thread2.start([&] { send_thread(&ef, FLAG02, 1); });
299+
thread3.start([&] { send_thread(&ef, FLAG03, 1); });
302300

303301
for (int i = 0; i <= MAX_FLAG_POS; i++) {
304302
uint32_t flag = 1 << i;
@@ -364,13 +362,11 @@ void test_multi_eventflags_all(void)
364362
{
365363
EventFlags ef;
366364
Ticker t1, t2, t3;
367-
is_ticker_used = true;
368-
t1.attach_us(callback(send_thread<FLAG01, 0>, &ef), 3000);
369-
t2.attach_us(callback(send_thread<FLAG02, 0>, &ef), 4000);
370-
t3.attach_us(callback(send_thread<FLAG03, 0>, &ef), 5000);
365+
t1.attach_us([&] { send_thread(&ef, FLAG01, 0); }, 3000);
366+
t2.attach_us([&] { send_thread(&ef, FLAG02, 0); }, 4000);
367+
t3.attach_us([&] { send_thread(&ef, FLAG03, 0); }, 5000);
371368
uint32_t ret = ef.wait_all(FLAG01 | FLAG02 | FLAG03, 20, false);
372369
TEST_ASSERT_EQUAL(FLAG01 | FLAG02 | FLAG03, ret);
373-
is_ticker_used = false;
374370
}
375371

376372
/** Test if multi-event flag set cause wait_any to return
@@ -384,10 +380,9 @@ void test_multi_eventflags_any(void)
384380
EventFlags ef;
385381
uint32_t ret;
386382
Ticker t1, t2, t3;
387-
is_ticker_used = true;
388-
t1.attach_us(callback(send_thread<FLAG01, 0>, &ef), 3000);
389-
t2.attach_us(callback(send_thread<FLAG02, 0>, &ef), 4000);
390-
t3.attach_us(callback(send_thread<FLAG03, 0>, &ef), 5000);
383+
t1.attach_us([&] { send_thread(&ef, FLAG01, 0); }, 3000);
384+
t2.attach_us([&] { send_thread(&ef, FLAG02, 0); }, 4000);
385+
t3.attach_us([&] { send_thread(&ef, FLAG03, 0); }, 5000);
391386

392387
for (int i = 0; i <= MAX_FLAG_POS; i++) {
393388
uint32_t flag = 1 << i;
@@ -396,7 +391,6 @@ void test_multi_eventflags_any(void)
396391
}
397392
ret = ef.get();
398393
TEST_ASSERT_EQUAL(NO_FLAGS, ret);
399-
is_ticker_used = false;
400394
}
401395

402396
/** Test if multi-event flag set cause wait_any(without clear) to return
@@ -410,10 +404,9 @@ void test_multi_eventflags_any_no_clear(void)
410404
EventFlags ef;
411405
uint32_t ret;
412406
Ticker t1, t2, t3;
413-
is_ticker_used = true;
414-
t1.attach_us(callback(send_thread<FLAG01, 0>, &ef), 3000);
415-
t2.attach_us(callback(send_thread<FLAG02, 0>, &ef), 4000);
416-
t3.attach_us(callback(send_thread<FLAG03, 0>, &ef), 5000);
407+
t1.attach_us([&] { send_thread(&ef, FLAG01, 0); }, 3000);
408+
t2.attach_us([&] { send_thread(&ef, FLAG02, 0); }, 4000);
409+
t3.attach_us([&] { send_thread(&ef, FLAG03, 0); }, 5000);
417410

418411
for (int i = 0; i <= MAX_FLAG_POS; i++) {
419412
uint32_t flag = 1 << i;
@@ -424,7 +417,6 @@ void test_multi_eventflags_any_no_clear(void)
424417
}
425418
ret = ef.get();
426419
TEST_ASSERT_EQUAL(NO_FLAGS, ret);
427-
is_ticker_used = false;
428420
}
429421

430422
utest::v1::status_t test_setup(const size_t number_of_cases)

text.txt

-204 KB
Binary file not shown.

0 commit comments

Comments
 (0)