tevent: fix the nesting logic
authorStefan Metzmacher <metze@samba.org>
Thu, 19 Mar 2009 13:31:43 +0000 (14:31 +0100)
committerKarolin Seeger <kseeger@samba.org>
Wed, 9 Sep 2009 10:27:13 +0000 (12:27 +0200)
Only tevent_loop_once and tevent_loop_until() should care
about the nesting level.

This fixes the samba3 printing code where we use tevent_loop_wait()
and don't allow nested events.

We still call the nesting hook for all levels, we need to decide
if we really want this...

metze
(cherry picked from commit 36e7045340bbc7d6567008bdd87c4cdf717835bd)

tevent/tevent.c

index 43f174de04575bba3423965cbe2bf37f53920cae..3ce6e3e4777685d86232f86896a3152072e328e4 100644 (file)
@@ -468,6 +468,8 @@ int _tevent_loop_once(struct tevent_context *ev, const char *location)
                        errno = ELOOP;
                        return -1;
                }
+       }
+       if (ev->nesting.level > 0) {
                if (ev->nesting.hook_fn) {
                        int ret2;
                        ret2 = ev->nesting.hook_fn(ev,
@@ -485,7 +487,7 @@ int _tevent_loop_once(struct tevent_context *ev, const char *location)
 
        ret = ev->ops->loop_once(ev, location);
 
-       if (ev->nesting.level > 1) {
+       if (ev->nesting.level > 0) {
                if (ev->nesting.hook_fn) {
                        int ret2;
                        ret2 = ev->nesting.hook_fn(ev,
@@ -525,6 +527,8 @@ int _tevent_loop_until(struct tevent_context *ev,
                        errno = ELOOP;
                        return -1;
                }
+       }
+       if (ev->nesting.level > 0) {
                if (ev->nesting.hook_fn) {
                        int ret2;
                        ret2 = ev->nesting.hook_fn(ev,
@@ -547,7 +551,7 @@ int _tevent_loop_until(struct tevent_context *ev,
                }
        }
 
-       if (ev->nesting.level > 1) {
+       if (ev->nesting.level > 0) {
                if (ev->nesting.hook_fn) {
                        int ret2;
                        ret2 = ev->nesting.hook_fn(ev,
@@ -601,9 +605,5 @@ int tevent_common_loop_wait(struct tevent_context *ev,
 */
 int _tevent_loop_wait(struct tevent_context *ev, const char *location)
 {
-       int ret;
-       ev->nesting.level++;
-       ret = ev->ops->loop_wait(ev, location);
-       ev->nesting.level--;
-       return ret;
+       return ev->ops->loop_wait(ev, location);
 }