Skip to content

Commit 78107e8

Browse files
committed
Add struct am_ao_state::subscribe_list_set
1 parent e07709c commit 78107e8

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

libs/ao/ao.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ bool am_ao_publish_exclude_x(
6464
AM_ASSERT(AM_EVENT_HAS_PUBSUB_ID(event));
6565
AM_ASSERT(margin >= 0);
6666
struct am_ao_state *me = &am_ao_state_;
67+
AM_ASSERT(me->subscribe_list_set);
6768
AM_ASSERT(me->sub);
6869

6970
if (!am_event_is_static(event)) {
@@ -177,6 +178,7 @@ void am_ao_subscribe(const struct am_ao *ao, int event) {
177178
AM_ASSERT(AM_AO_PRIO_IS_VALID(ao));
178179
AM_ASSERT(event >= AM_EVT_USER);
179180
struct am_ao_state *me = &am_ao_state_;
181+
AM_ASSERT(me->subscribe_list_set);
180182
AM_ASSERT(event < me->nsub);
181183
AM_ASSERT(me->aos[ao->prio] == ao);
182184
AM_ASSERT(me->sub);
@@ -195,6 +197,7 @@ void am_ao_unsubscribe(const struct am_ao *ao, int event) {
195197
AM_ASSERT(AM_AO_PRIO_IS_VALID(ao));
196198
AM_ASSERT(event >= AM_EVT_USER);
197199
struct am_ao_state *me = &am_ao_state_;
200+
AM_ASSERT(me->subscribe_list_set);
198201
AM_ASSERT(event < me->nsub);
199202
AM_ASSERT(me->aos[ao->prio] == ao);
200203
AM_ASSERT(me->sub);
@@ -216,6 +219,7 @@ void am_ao_unsubscribe_all(const struct am_ao *ao) {
216219
AM_ASSERT(AM_AO_PRIO_IS_VALID(ao));
217220

218221
struct am_ao_state *me = &am_ao_state_;
222+
AM_ASSERT(me->subscribe_list_set);
219223
if (!me->sub) {
220224
return;
221225
}
@@ -295,6 +299,7 @@ void am_ao_init_subscribe_list(struct am_ao_subscribe_list *sub, int nsub) {
295299
me->sub = sub;
296300
me->nsub = nsub;
297301
memset(sub, 0, sizeof(*sub) * (size_t)nsub);
302+
me->subscribe_list_set = true;
298303
}
299304

300305
void am_ao_log_event_queues(

libs/ao/cooperative/port.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ void am_ao_stop(struct am_ao *ao) {
158158
struct am_ao_state *me = &am_ao_state_;
159159
AM_ASSERT(me->aos_cnt);
160160

161-
am_ao_unsubscribe_all(ao);
161+
if (me->subscribe_list_set) {
162+
am_ao_unsubscribe_all(ao);
163+
}
162164

163165
me->crit_enter();
164166

libs/ao/preemptive/port.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ void am_ao_stop(struct am_ao *ao) {
137137
struct am_ao_state *me = &am_ao_state_;
138138
AM_ASSERT(me->aos_cnt);
139139

140-
am_ao_unsubscribe_all(ao);
140+
if (me->subscribe_list_set) {
141+
am_ao_unsubscribe_all(ao);
142+
}
141143

142144
me->crit_enter();
143145

libs/ao/state.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ struct am_ao_state {
7878
unsigned hsm_init_pend : 1;
7979
/** mark startup sequence complete */
8080
unsigned startup_complete : 1;
81+
/** safety net to catch missing am_ao_init_subscribe_list() call */
82+
unsigned subscribe_list_set : 1;
8183
};
8284

8385
extern struct am_ao_state am_ao_state_;

0 commit comments

Comments
 (0)