int
event_base_foreach_event_(struct event_base *base,
- int (*fn)(struct event_base *, struct event *, void *), void *arg)
+ event_base_foreach_event_cb fn, void *arg)
{
int r, i;
unsigned u;
/* Helper for event_base_dump_events: called on each event in the event base;
* dumps only the inserted events. */
static int
-dump_inserted_event_fn(struct event_base *base, struct event *e, void *arg)
+dump_inserted_event_fn(const struct event_base *base, const struct event *e, void *arg)
{
FILE *output = arg;
const char *gloss = (e->ev_events & EV_SIGNAL) ?
/* Helper for event_base_dump_events: called on each event in the event base;
* dumps only the active events. */
static int
-dump_active_event_fn(struct event_base *base, struct event *e, void *arg)
+dump_active_event_fn(const struct event_base *base, const struct event *e, void *arg)
{
FILE *output = arg;
const char *gloss = (e->ev_events & EV_SIGNAL) ?
return 0;
}
+void
+event_base_foreach_event(struct event_base *base,
+ event_base_foreach_event_cb fn, void *arg)
+{
+ if ((!fn) || (!base)) {
+ return;
+ }
+ EVBASE_ACQUIRE_LOCK(base, th_base_lock);
+ event_base_foreach_event_(base, fn, arg);
+ EVBASE_RELEASE_LOCK(base, th_base_lock);
+}
+
+
void
event_base_dump_events(struct event_base *base, FILE *output)
{
+ EVBASE_ACQUIRE_LOCK(base, th_base_lock);
fprintf(output, "Inserted events:\n");
event_base_foreach_event_(base, dump_inserted_event_fn, output);
fprintf(output, "Active events:\n");
event_base_foreach_event_(base, dump_active_event_fn, output);
+ EVBASE_RELEASE_LOCK(base, th_base_lock);
}
void
/* Helper type for evmap_foreach_event_: Bundles a function to call on every
* event, and the user-provided void* to use as its third argument. */
struct evmap_foreach_event_helper {
- int (*fn)(struct event_base *, struct event *, void *);
+ int (*fn)(const struct event_base *, const struct event *, void *);
void *arg;
};
int
evmap_foreach_event_(struct event_base *base,
- int (*fn)(struct event_base *, struct event *, void *), void *arg)
+ int (*fn)(const struct event_base *, const struct event *, void *), void *arg)
{
struct evmap_foreach_event_helper h;
int r;
*/
void event_base_dump_events(struct event_base *, FILE *);
+
+/**
+ * callback for iterating events in an event base via event_base_foreach_event
+ */
+typedef int (*event_base_foreach_event_cb)(const struct event_base *, const struct event *, void *);
+
+/**
+ Iterate all current events in a given event loop. The method is an
+ alternative to event_base_dump_events, but provides a native interface
+ towards the events.
+
+ Modification of events during iteration is an invalid operation
+ and may lead to unexpected behaviour
+
+ @param base An event_base on which to scan the events.
+ @param fn A callback function to receive the events.
+*/
+void event_base_foreach_event(struct event_base *base, event_base_foreach_event_cb fn, void *arg);
+
+
+
/** Sets 'tv' to the current time (as returned by gettimeofday()),
looking at the cached value in 'base' if possible, and calling
gettimeofday() or clock_gettime() as appropriate if there is no