dovecot-2.2: lib: Don't call ioloop context deactivate() if acti...

dovecot at dovecot.org dovecot at dovecot.org
Thu Mar 5 21:05:30 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/c98991820dde
changeset: 18291:c98991820dde
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Mar 05 22:19:02 2015 +0200
description:
lib: Don't call ioloop context deactivate() if activate() hasn't been called yet.
This could have happened immediately after the callback was registered.

diffstat:

 src/lib/ioloop-private.h |   1 +
 src/lib/ioloop.c         |  22 ++++++++++++++++------
 2 files changed, 17 insertions(+), 6 deletions(-)

diffs (56 lines):

diff -r 18721584583b -r c98991820dde src/lib/ioloop-private.h
--- a/src/lib/ioloop-private.h	Thu Mar 05 22:18:04 2015 +0200
+++ b/src/lib/ioloop-private.h	Thu Mar 05 22:19:02 2015 +0200
@@ -77,6 +77,7 @@
 	io_callback_t *activate;
 	io_callback_t *deactivate;
 	void *context;
+	bool activated;
 };
 
 struct ioloop_context {
diff -r 18721584583b -r c98991820dde src/lib/ioloop.c
--- a/src/lib/ioloop.c	Thu Mar 05 22:18:04 2015 +0200
+++ b/src/lib/ioloop.c	Thu Mar 05 22:19:02 2015 +0200
@@ -781,25 +781,35 @@
 
 void io_loop_context_activate(struct ioloop_context *ctx)
 {
-	const struct ioloop_context_callback *cb;
+	struct ioloop_context_callback *cb;
 
 	i_assert(ctx->ioloop->cur_ctx == NULL);
 
 	ctx->ioloop->cur_ctx = ctx;
 	io_loop_context_ref(ctx);
-	array_foreach(&ctx->callbacks, cb) {
+	array_foreach_modifiable(&ctx->callbacks, cb) {
+		i_assert(!cb->activated);
 		if (cb->activate != NULL)
 			cb->activate(cb->context);
+		cb->activated = TRUE;
 	}
 }
 
 void io_loop_context_deactivate(struct ioloop_context *ctx)
 {
-	const struct ioloop_context_callback *cb;
+	struct ioloop_context_callback *cb;
 
-	array_foreach(&ctx->callbacks, cb) {
-		if (cb->deactivate != NULL)
-			cb->deactivate(cb->context);
+	i_assert(ctx->ioloop->cur_ctx != NULL);
+
+	array_foreach_modifiable(&ctx->callbacks, cb) {
+		if (!cb->activated) {
+			/* we just added this callback. don't deactivate it
+			   before it gets first activated. */
+		} else {
+			if (cb->deactivate != NULL)
+				cb->deactivate(cb->context);
+			cb->activated = FALSE;
+		}
 	}
 	ctx->ioloop->cur_ctx = NULL;
 	io_loop_context_remove_deleted_callbacks(ctx);


More information about the dovecot-cvs mailing list