Add event_base_get_running_event() to get the event* whose cb we are in

This commit is contained in:
Nick Mathewson 2012-03-25 18:54:40 -04:00
parent 5626092c58
commit c5732fddb0
3 changed files with 19 additions and 0 deletions

11
event.c
View File

@ -1920,6 +1920,17 @@ event_self_cbarg(void)
return &event_self_cbarg_ptr_;
}
struct event *
event_base_get_running_event(struct event_base *base)
{
struct event *ev = NULL;
EVBASE_ACQUIRE_LOCK(base, th_base_lock);
if (EVBASE_IN_THREAD(base))
ev = base->current_event;
EVBASE_RELEASE_LOCK(base, th_base_lock);
return ev;
}
struct event *
event_new(struct event_base *base, evutil_socket_t fd, short events, void (*cb)(evutil_socket_t, short, void *), void *arg)
{

View File

@ -1061,6 +1061,13 @@ void event_active(struct event *ev, int res, short ncalls);
*/
int event_pending(const struct event *ev, short events, struct timeval *tv);
/**
If called from within the callback for an event, returns that event.
The behavior of this function is not defined when called from outside the
callback function for an event.
*/
struct event *event_base_get_running_event(struct event_base *base);
/**
Test if an event structure might be initialized.

View File

@ -1250,6 +1250,7 @@ event_selfarg_cb(evutil_socket_t fd, short event, void *arg)
struct event_base *base = event_get_base(ev);
event_base_assert_ok_(base);
event_base_loopexit(base, NULL);
tt_want(ev == event_base_get_running_event(base));
}
static void