void event_base_assert_ok_nolock_(struct event_base *base);
-/* Callback type for event_base_foreach_event. */
-//typedef int (*event_base_foreach_event_cb)(struct event_base *base, struct event *, void *);
-
/* Helper function: Call 'fn' exactly once every inserted or active event in
* the event_base 'base'.
*
*
* Requires that 'base' be locked.
*/
-int event_base_foreach_event_(struct event_base *base,
+int event_base_foreach_event_nolock_(struct event_base *base,
event_base_foreach_event_cb cb, void *arg);
#ifdef __cplusplus
}
int
-event_base_foreach_event_(struct event_base *base,
+event_base_foreach_event_nolock_(struct event_base *base,
event_base_foreach_event_cb fn, void *arg)
{
int r, i;
return 0;
}
-void
-event_base_foreach_event(struct event_base *base,
+int
+event_base_foreach_event(struct event_base *base,
event_base_foreach_event_cb fn, void *arg)
{
+ int r;
if ((!fn) || (!base)) {
return;
}
EVBASE_ACQUIRE_LOCK(base, th_base_lock);
- event_base_foreach_event_(base, fn, arg);
+ r = event_base_foreach_event_nolock_(base, fn, arg);
EVBASE_RELEASE_LOCK(base, th_base_lock);
+ return r;
}
{
EVBASE_ACQUIRE_LOCK(base, th_base_lock);
fprintf(output, "Inserted events:\n");
- event_base_foreach_event_(base, dump_inserted_event_fn, output);
+ event_base_foreach_event_nolock_(base, dump_inserted_event_fn, output);
fprintf(output, "Active events:\n");
- event_base_foreach_event_(base, dump_active_event_fn, output);
+ event_base_foreach_event_nolock_(base, dump_active_event_fn, output);
EVBASE_RELEASE_LOCK(base, th_base_lock);
}
/* 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)(const struct event_base *, const struct event *, void *);
+ event_base_foreach_event_cb fn;
void *arg;
};
int
evmap_foreach_event_(struct event_base *base,
- int (*fn)(const struct event_base *, const struct event *, void *), void *arg)
+ event_base_foreach_event_cb fn, void *arg)
{
struct evmap_foreach_event_helper h;
int r;
/**
- * callback for iterating events in an event base via event_base_foreach_event
+ * 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.
+ Iterate over all added or active events events in an event loop, and invoke
+ a given callback on each one.
- Modification of events during iteration is an invalid operation
- and may lead to unexpected behaviour
+ The callback must not call any function that modifies the event base, or
+ modifies any event in the event base. Doing so is unsupported and
+ will lead to undefined behavior.
+
+ The callback function must return 0 to continue iteration, or some other
+ integer to stop iterating.
@param base An event_base on which to scan the events.
@param fn A callback function to receive the events.
+ @param arg An argument passed to the callback function.
+ @return 0 if we iterated over every event, or the value returned by the
+ callback function if the loop exited early.
*/
-void event_base_foreach_event(struct event_base *base, event_base_foreach_event_cb fn, void *arg);
-
+int 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()),