|
38 | 38 |
|
39 | 39 | static struct am_bit_u64 am_ready_aos_ = {0}; |
40 | 40 |
|
41 | | -bool am_ao_run_all(bool loop) { |
| 41 | +bool am_ao_run_all(void) { |
42 | 42 | struct am_ao_state *me = &am_ao_state_; |
43 | | - bool processed = false; |
44 | | - int task_id = am_pal_task_own_id(); |
45 | | - do { |
46 | | - me->crit_enter(); |
| 43 | + me->crit_enter(); |
47 | 44 |
|
48 | | - while (am_bit_u64_is_empty(&am_ready_aos_)) { |
49 | | - me->crit_exit(); |
50 | | - if (me->on_idle) { |
51 | | - me->on_idle(); |
52 | | - } else { |
53 | | - am_pal_task_wait(task_id); |
54 | | - } |
55 | | - me->crit_enter(); |
| 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); |
56 | 52 | } |
57 | | - int msb = am_bit_u64_msb(&am_ready_aos_); |
| 53 | + me->crit_enter(); |
| 54 | + } |
| 55 | + int msb = am_bit_u64_msb(&am_ready_aos_); |
58 | 56 |
|
59 | | - me->crit_exit(); |
| 57 | + me->crit_exit(); |
60 | 58 |
|
61 | | - struct am_ao *ao = me->ao[msb]; |
62 | | - AM_ASSERT(ao); |
63 | | - |
64 | | - const struct am_event *e = am_event_pop_front(&ao->event_queue); |
65 | | - if (!e) { |
66 | | - me->crit_enter(); |
67 | | - if (am_queue_is_empty(&ao->event_queue)) { |
68 | | - am_bit_u64_clear(&am_ready_aos_, ao->prio); |
69 | | - } |
70 | | - me->crit_exit(); |
71 | | - continue; |
| 59 | + struct am_ao *ao = me->ao[msb]; |
| 60 | + AM_ASSERT(ao); |
| 61 | + |
| 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); |
72 | 67 | } |
73 | | - me->debug(ao, e); |
74 | | - AM_ATOMIC_STORE_N(&ao->last_event, e->id); |
75 | | - am_hsm_dispatch(&ao->hsm, e); |
76 | | - AM_ATOMIC_STORE_N(&ao->last_event, AM_EVT_INVALID); |
77 | | - am_event_free(&e); |
78 | | - processed = true; |
79 | | - } while (loop && AM_UNLIKELY(!AM_ATOMIC_LOAD_N(&me->ao_state_dtor_called))); |
80 | | - |
81 | | - return processed; |
| 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); |
| 76 | + |
| 77 | + return true; |
82 | 78 | } |
83 | 79 |
|
84 | 80 | void am_ao_start( |
|
0 commit comments