Skip to content

Commit 257d561

Browse files
committed
Rework am_ao_run_all() in ao/cooperative/port.c
1 parent 73c2c90 commit 257d561

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

libs/ao/ao.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,11 @@ void am_ao_init_subscribe_list(struct am_ao_subscribe_list *sub, int nsub);
273273
/**
274274
* Run all active objects.
275275
*
276-
* @retval true processed at least one event
277-
* @retval false processed no events
276+
* Non blocking.
277+
* Return after dispatching zero or one event.
278+
*
279+
* @retval true dispatched one event
280+
* @retval false dispatched no events
278281
*/
279282
bool am_ao_run_all(void);
280283

libs/ao/cooperative/port.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ static struct am_bit_u64 am_ready_aos_ = {0};
4040

4141
bool am_ao_run_all(void) {
4242
struct am_ao_state *me = &am_ao_state_;
43-
me->crit_enter();
44-
45-
while (!am_bit_u64_is_empty(&am_ready_aos_)) {
43+
bool dispatched = false;
44+
do {
45+
me->crit_enter();
46+
if (am_bit_u64_is_empty(&am_ready_aos_)) {
47+
me->crit_exit();
48+
break;
49+
}
4650
int msb = am_bit_u64_msb(&am_ready_aos_);
47-
4851
me->crit_exit();
4952

5053
struct am_ao *ao = me->ao[msb];
@@ -66,9 +69,10 @@ bool am_ao_run_all(void) {
6669
AM_ATOMIC_STORE_N(&ao->last_event, AM_EVT_INVALID);
6770
am_event_free(&e);
6871

69-
return true;
70-
}
71-
return false;
72+
dispatched = true;
73+
} while (!dispatched);
74+
75+
return dispatched;
7276
}
7377

7478
void am_ao_start(

0 commit comments

Comments
 (0)