Skip to content

Commit e44775c

Browse files
committed
Rework am_ao_dump_event_queues() and am_ao_dump_event_queues()
1 parent 22d3305 commit e44775c

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

libs/ao/ao.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* Active Object (AO) API implementation.
2929
*/
3030

31+
#include <limits.h>
3132
#include <stdbool.h>
3233
#include <stddef.h>
3334
#include <stdint.h>
@@ -306,10 +307,18 @@ void am_ao_init_subscribe_list(struct am_ao_subscribe_list *sub, int nsub) {
306307
}
307308

308309
void am_ao_dump_event_queues(
309-
int num, void (*log)(const char *name, int i, int len, int cap, int event)
310+
int num,
311+
void (*log)(
312+
const char *name, int i, int len, int cap, const struct am_event *event
313+
)
310314
) {
315+
AM_ASSERT(num != 0);
311316
AM_ASSERT(log);
312317

318+
if (num < 0) {
319+
num = INT_MAX;
320+
}
321+
313322
struct am_ao_state *me = &g_am_ao_state;
314323
for (int i = 0; i < AM_COUNTOF(me->ao); i++) {
315324
struct am_ao *ao = me->ao[i];
@@ -318,21 +327,18 @@ void am_ao_dump_event_queues(
318327
}
319328
struct am_queue *q = &ao->event_queue;
320329
int cap = am_queue_capacity(q);
321-
me->crit_enter();
322330
int len = am_queue_length(q);
323331
int tnum = AM_MIN(num, len);
324332
if (0 == tnum) {
325-
me->crit_exit();
326333
log(ao->name, 0, len, cap, /*event=*/AM_EVT_INVALID);
327334
continue;
328335
}
329336
for (int j = 0; j < tnum; j++) {
330337
struct am_event **e = (struct am_event **)am_queue_pop_front(q);
331338
AM_ASSERT(e);
332339
AM_ASSERT(*e);
333-
log(ao->name, j, len, cap, (*e)->id);
340+
log(ao->name, j, len, cap, *e);
334341
}
335-
me->crit_exit();
336342
}
337343
}
338344

libs/ao/ao.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,14 @@ bool am_ao_run_all(bool loop);
285285
/**
286286
* Log the content of the first num events in each event queue of every AO.
287287
*
288-
* @param num the number of events to log
288+
* @param num the number of events to log. Use -1 to log all events.
289289
* @param log the logging callback
290290
*/
291291
void am_ao_dump_event_queues(
292-
int num, void (*log)(const char *name, int i, int len, int cap, int event)
292+
int num,
293+
void (*log)(
294+
const char *name, int i, int len, int cap, const struct am_event *event
295+
)
293296
);
294297

295298
/**

0 commit comments

Comments
 (0)