]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add asserts to make sure running ioloop is always current_ioloop
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 8 Aug 2017 19:11:48 +0000 (22:11 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Wed, 9 Aug 2017 12:07:55 +0000 (15:07 +0300)
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.

src/lib/ioloop.c

index 98e42c8fb0969367f34652af55a54b5fc7b237b5..6e63fde510497f332867c644590f086a9403849c 100644 (file)
@@ -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)