@@ -42,39 +42,33 @@ bool am_ao_run_all(void) {
4242 struct am_ao_state * me = & am_ao_state_ ;
4343 me -> crit_enter ();
4444
45- while (am_bit_u64_is_empty (& am_ready_aos_ )) {
46- me -> crit_exit ();
47- if (me -> on_idle ) {
48- me -> on_idle ();
49- } else {
50- int task_id = am_pal_task_own_id ();
51- am_pal_task_wait (task_id );
52- }
53- me -> crit_enter ();
54- }
55- int msb = am_bit_u64_msb (& am_ready_aos_ );
56-
57- me -> crit_exit ();
45+ while (!am_bit_u64_is_empty (& am_ready_aos_ )) {
46+ int msb = am_bit_u64_msb (& am_ready_aos_ );
5847
59- struct am_ao * ao = me -> ao [msb ];
60- AM_ASSERT (ao );
48+ me -> crit_exit ();
6149
62- const struct am_event * e = am_event_pop_front (& ao -> event_queue );
63- if (!e ) {
64- me -> crit_enter ();
65- if (am_queue_is_empty (& ao -> event_queue )) {
66- am_bit_u64_clear (& am_ready_aos_ , ao -> prio );
50+ struct am_ao * ao = me -> ao [msb ];
51+ AM_ASSERT (ao );
52+ AM_ASSERT (ao -> prio == msb );
53+
54+ const struct am_event * e = am_event_pop_front (& ao -> event_queue );
55+ if (!e ) {
56+ me -> crit_enter ();
57+ if (am_queue_is_empty (& ao -> event_queue )) {
58+ am_bit_u64_clear (& am_ready_aos_ , ao -> prio );
59+ }
60+ me -> crit_exit ();
61+ continue ;
6762 }
68- me -> crit_exit ();
69- return false;
70- }
71- me -> debug (ao , e );
72- AM_ATOMIC_STORE_N (& ao -> last_event , e -> id );
73- am_hsm_dispatch (& ao -> hsm , e );
74- AM_ATOMIC_STORE_N (& ao -> last_event , AM_EVT_INVALID );
75- am_event_free (& e );
63+ me -> debug (ao , e );
64+ AM_ATOMIC_STORE_N (& ao -> last_event , e -> id );
65+ am_hsm_dispatch (& ao -> hsm , e );
66+ AM_ATOMIC_STORE_N (& ao -> last_event , AM_EVT_INVALID );
67+ am_event_free (& e );
7668
77- return true;
69+ return true;
70+ }
71+ return false;
7872}
7973
8074void am_ao_start (
0 commit comments