mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-09 04:19:10 -04:00
Add event_base_get_running_event() to get the event* whose cb we are in
This commit is contained in:
parent
5626092c58
commit
c5732fddb0
11
event.c
11
event.c
@ -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)
|
||||
{
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user