Skip to content

Commit 9634177

Browse files
committed
Allow configuration set to NULL in am_ao_state_ctor()
1 parent 69d07eb commit 9634177

File tree

11 files changed

+18
-61
lines changed

11 files changed

+18
-61
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [0-based versioning](https://0ver.org/).
2020
- Fix AM_GET_MACRO_2_() documentation.
2121
- Relocate compiler independent macros to `common/macros.h`.
2222
- Allow configuration set to NULL in `am_event_state_ctor()`.
23+
- Allow configuration set to NULL in `am_ao_state_ctor()`.
2324

2425
### Added
2526

apps/examples/async/main.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,7 @@ static void input_task(void *param) {
307307
}
308308

309309
int main(void) {
310-
struct am_ao_state_cfg cfg = {
311-
.on_idle = am_pal_on_idle,
312-
.crit_enter = am_pal_crit_enter,
313-
.crit_exit = am_pal_crit_exit
314-
};
315-
am_ao_state_ctor(&cfg);
310+
am_ao_state_ctor(/*cfg=*/NULL);
316311

317312
am_event_add_pool(
318313
m_event_pool,

apps/examples/dpp/main.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,7 @@ static void ticker_task(void *param) {
120120
}
121121

122122
int main(void) {
123-
struct am_ao_state_cfg cfg_ao = {
124-
.on_idle = am_pal_on_idle,
125-
.crit_enter = am_pal_crit_enter,
126-
.crit_exit = am_pal_crit_exit
127-
};
128-
am_ao_state_ctor(&cfg_ao);
123+
am_ao_state_ctor(/*cfg=*/NULL);
129124

130125
am_event_add_pool(
131126
m_event_pool,

apps/examples/fork/main.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,7 @@ int main(int argc, const char *argv[]) {
221221
return EXIT_FAILURE;
222222
}
223223

224-
struct am_ao_state_cfg cfg = {
225-
.on_idle = am_pal_on_idle,
226-
.crit_enter = am_pal_crit_enter,
227-
.crit_exit = am_pal_crit_exit
228-
};
229-
am_ao_state_ctor(&cfg);
224+
am_ao_state_ctor(/*cfg=*/NULL);
230225

231226
am_ao_init_subscribe_list(m_pubsub_list, AM_COUNTOF(m_pubsub_list));
232227

apps/examples/ringbuf/main.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,7 @@ static void test_ringbuf_threading(void) {
6767

6868
am_ringbuf_ctor(&g_ringbuf, buf, AM_COUNTOF(buf));
6969

70-
struct am_ao_state_cfg cfg_ao = {
71-
.on_idle = am_pal_on_idle,
72-
.crit_enter = am_pal_crit_enter,
73-
.crit_exit = am_pal_crit_exit
74-
};
75-
am_ao_state_ctor(&cfg_ao);
70+
am_ao_state_ctor(/*cfg=*/NULL);
7671

7772
ringbuf_reader_ctor();
7873
ringbuf_writer_ctor();

apps/examples/smokers/main.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,7 @@ static void ticker_task(void *param) {
336336
AM_ALIGNOF_DEFINE(events_t);
337337

338338
int main(void) {
339-
struct am_ao_state_cfg cfg = {
340-
.on_idle = am_pal_on_idle,
341-
.crit_enter = am_pal_crit_enter,
342-
.crit_exit = am_pal_crit_exit
343-
};
344-
am_ao_state_ctor(&cfg);
339+
am_ao_state_ctor(/*cfg=*/NULL);
345340

346341
am_event_add_pool(
347342
m_event_pool,

apps/examples/workers/main.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,7 @@ static void ticker_task(void *param) {
250250
AM_ALIGNOF_DEFINE(events_t);
251251

252252
int main(void) {
253-
struct am_ao_state_cfg cfg = {
254-
.on_idle = am_pal_on_idle,
255-
.crit_enter = am_pal_crit_enter,
256-
.crit_exit = am_pal_crit_exit
257-
};
258-
am_ao_state_ctor(&cfg);
253+
am_ao_state_ctor(/*cfg=*/NULL);
259254

260255
am_event_add_pool(
261256
m_event_pool,

libs/ao/ao.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,6 @@ static void am_ao_debug_stub(const struct am_ao *ao, const struct am_event *e) {
261261
}
262262

263263
void am_ao_state_ctor(const struct am_ao_state_cfg *cfg) {
264-
AM_ASSERT(cfg);
265-
AM_ASSERT(cfg->crit_enter);
266-
AM_ASSERT(cfg->crit_exit);
267-
268264
struct am_ao_state *me = &am_ao_state_;
269265
memset(me, 0, sizeof(*me));
270266

@@ -274,27 +270,27 @@ void am_ao_state_ctor(const struct am_ao_state_cfg *cfg) {
274270

275271
AM_ATOMIC_STORE_N(&me->startup_complete, false);
276272

277-
me->debug = cfg->debug;
273+
me->debug = cfg ? cfg->debug : NULL;
278274
if (!me->debug) {
279275
me->debug = am_ao_debug_stub;
280276
}
281-
me->crit_enter = cfg->crit_enter;
282-
me->crit_exit = cfg->crit_exit;
283-
me->on_idle = cfg->on_idle;
277+
me->crit_enter = cfg ? cfg->crit_enter : am_pal_crit_enter;
278+
me->crit_exit = cfg ? cfg->crit_exit : am_pal_crit_exit;
279+
me->on_idle = cfg ? cfg->on_idle : am_pal_on_idle;
284280

285281
me->running_ao_prio = AM_AO_PRIO_INVALID;
286282

287283
struct am_event_state_cfg cfg_event = {
288-
.crit_enter = cfg->crit_enter,
289-
.crit_exit = cfg->crit_exit,
284+
.crit_enter = me->crit_enter,
285+
.crit_exit = me->crit_exit,
290286
};
291287
am_event_state_ctor(&cfg_event);
292288

293289
struct am_timer_state_cfg cfg_timer = {
294290
.post_unsafe = (am_timer_post_unsafe_fn)am_ao_post_fifo_unsafe,
295291
.publish = (am_timer_publish_fn)am_ao_publish,
296-
.crit_enter = cfg->crit_enter,
297-
.crit_exit = cfg->crit_exit,
292+
.crit_enter = me->crit_enter,
293+
.crit_exit = me->crit_exit,
298294
};
299295
am_timer_state_ctor(&cfg_timer);
300296
}

libs/ao/ao.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ void am_ao_stop(struct am_ao *ao);
458458
*
459459
* @param cfg active object library configuration
460460
* The active object library makes an internal copy of
461-
* the configuration.
461+
* the configuration. Can be NULL.
462462
*/
463463
void am_ao_state_ctor(const struct am_ao_state_cfg *cfg);
464464

libs/ao/tests/minimal.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,7 @@ static int loopback_test_init(
116116
}
117117

118118
int main(void) {
119-
struct am_ao_state_cfg cfg_ao = {
120-
.on_idle = am_pal_on_idle,
121-
.crit_enter = am_pal_crit_enter,
122-
.crit_exit = am_pal_crit_exit
123-
};
124-
am_ao_state_ctor(&cfg_ao);
119+
am_ao_state_ctor(/*cfg=*/NULL);
125120

126121
am_ao_ctor(&m_loopback.ao, AM_HSM_STATE_CTOR(loopback_init));
127122
am_ao_ctor(&m_loopback_test.ao, AM_HSM_STATE_CTOR(loopback_test_init));

0 commit comments

Comments
 (0)