From: Timo Sirainen Date: Tue, 8 Aug 2017 19:11:48 +0000 (+0300) Subject: lib: Add asserts to make sure running ioloop is always current_ioloop X-Git-Tag: 2.3.0.rc1~1188 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=65b82c99b1db81a56a1e6c9e92fe8eec49fb36b3;p=thirdparty%2Fdovecot%2Fcore.git lib: Add asserts to make sure running ioloop is always current_ioloop We could also switch current_ioloop to the running ioloop temporarily while calling callbacks, but this behavior is probably clearer. All of the existing code should already work this way. Add the asserts after IO or timeout callback is called, so if the assert triggers, we can find out which callback caused the change. The initial assert in io_loop_handler_run() is enough to verify that the initial ioloop is correct. --- diff --git a/src/lib/ioloop.c b/src/lib/ioloop.c index 98e42c8fb0..6e63fde510 100644 --- a/src/lib/ioloop.c +++ b/src/lib/ioloop.c @@ -527,6 +527,7 @@ static void io_loop_handle_timeouts_real(struct ioloop *ioloop) ioloop_timeval.tv_sec)); ioloop->time_moved_callback(ioloop_time, ioloop_timeval.tv_sec); + i_assert(ioloop == current_ioloop); /* the callback may have slept, so check the time again. */ if (gettimeofday(&ioloop_timeval, NULL) < 0) i_fatal("gettimeofday(): %m"); @@ -538,6 +539,7 @@ static void io_loop_handle_timeouts_real(struct ioloop *ioloop) /* time moved forwards */ ioloop->time_moved_callback(ioloop->next_max_time, ioloop_timeval.tv_sec); + i_assert(ioloop == current_ioloop); } ioloop_add_wait_time(ioloop); } @@ -572,6 +574,7 @@ static void io_loop_handle_timeouts_real(struct ioloop *ioloop) } if (ioloop->cur_ctx != NULL) io_loop_context_deactivate(ioloop->cur_ctx); + i_assert(ioloop == current_ioloop); } } @@ -604,6 +607,7 @@ void io_loop_call_io(struct io *io) } if (ioloop->cur_ctx != NULL) io_loop_context_deactivate(ioloop->cur_ctx); + i_assert(ioloop == current_ioloop); } void io_loop_run(struct ioloop *ioloop) @@ -644,10 +648,14 @@ static void io_loop_call_pending(struct ioloop *ioloop) void io_loop_handler_run(struct ioloop *ioloop) { + i_assert(ioloop == current_ioloop); + io_loop_timeouts_start_new(ioloop); ioloop->wait_started = ioloop_timeval; io_loop_handler_run_internal(ioloop); io_loop_call_pending(ioloop); + + i_assert(ioloop == current_ioloop); } void io_loop_stop(struct ioloop *ioloop)