]> granicus.if.org Git - libevent/commitdiff
Add event_base_get_running_event() to get the event* whose cb we are in
authorNick Mathewson <nickm@torproject.org>
Sun, 25 Mar 2012 22:54:40 +0000 (18:54 -0400)
committerNick Mathewson <nickm@torproject.org>
Sun, 25 Mar 2012 22:54:40 +0000 (18:54 -0400)
event.c
include/event2/event.h
test/regress.c

diff --git a/event.c b/event.c
index 432d0060e7bc86ecf775e28a2ee5a14dd27bfa59..bb4c4c88a2c8c934422de76b33169d436b09b547 100644 (file)
--- a/event.c
+++ b/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)
 {
index d209c8156915ea429a627891f978a211a9198ea2..9685e0a2025cf7a8900b183e429ced1354b2c620 100644 (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.
index fe6862fc7e14dca57e3444b16be2dcd744b014a3..49c40efd5af630f132b12e824f8f69d89f44b12d 100644 (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