]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
complete removal of isc_loop_current()
authorEvan Hunt <each@isc.org>
Tue, 26 Mar 2024 09:13:53 +0000 (02:13 -0700)
committerOndřej Surý <ondrej@isc.org>
Tue, 2 Apr 2024 08:35:56 +0000 (10:35 +0200)
isc_loop() can now take its place.

This also requires changes to the test harness - instead of running the
setup and teardown outside of th main loop, we now schedule the setup
and teardown to run on the loop (via isc_loop_setup() and
isc_loop_teardown()) - this is needed because the new the isc_loop()
call has to be run on the active event loop, but previously the
isc_loop_current() (and the variants like isc_loop_main()) would work
even outside of the loop because it needed just isc_tid() to work, but
not the full loop (which was mainly true for the main thread).

13 files changed:
bin/delv/delv.c
bin/dnssec/dnssec-signzone.c
bin/nsupdate/nsupdate.c
lib/dns/nta.c
lib/isc/include/isc/async.h
lib/isc/include/isc/loop.h
lib/isc/loop.c
tests/include/tests/isc.h
tests/isc/doh_test.c
tests/isc/loop_test.c
tests/isc/netmgr_common.c
tests/isc/tcpdns_test.c
tests/isc/timer_test.c

index 31d44667e93d53eca06d172c3fea519b002cb15a..a767c0cffa4c6eca56e2624e8276bb078e2346a8 100644 (file)
@@ -2186,7 +2186,7 @@ run_server(void *arg) {
                                     NULL, NULL, ISC_NM_PROXY_NONE,
                                     &ifp->tcplistensocket));
        ifp->flags |= NS_INTERFACEFLAG_LISTENING;
-       isc_async_current(loopmgr, sendquery, ifp->tcplistensocket);
+       isc_async_current(sendquery, ifp->tcplistensocket);
 
        return;
 
index afe2eff19b12443b829cc693ecec56acd27b453d..7b8546418057e651475eb5352e1fd2ac211162ef 100644 (file)
@@ -1674,7 +1674,7 @@ assignwork(void *arg) {
        lock_and_dumpnode(dns_fixedname_name(&fname), node);
        dns_db_detachnode(gdb, &node);
 
-       isc_async_current(loopmgr, assignwork, NULL);
+       isc_async_current(assignwork, NULL);
 }
 
 /*%
index f81c1965b27ca77b53434a41a9356a2a95f48f9c..3048df834588a9a947d43c1b50dad26dd930301d 100644 (file)
@@ -2484,7 +2484,7 @@ static void
 done_update(void) {
        ddebug("done_update()");
 
-       isc_async_current(loopmgr, getinput, NULL);
+       isc_async_current(getinput, NULL);
 }
 
 static void
index abff2cba4ffd95cae65a0fe04b1dd7b7cfa1281c..ab04bb736fb0da0cb7ec9dc28d5abf2a112286f3 100644 (file)
@@ -439,7 +439,7 @@ dns_ntatable_covered(dns_ntatable_t *ntatable, isc_stdtime_t now,
                /* NTA is expired */
                dns__nta_ref(nta);
                dns_ntatable_ref(nta->ntatable);
-               isc_async_current(nta->ntatable->loopmgr, delete_expired, nta);
+               isc_async_current(delete_expired, nta);
                goto done;
        }
 
index c3785fa0f7746f2fcbbf78cf663206253d75e125..2b94cd78e0946bbfb72e83dba31994243bb1ef88 100644 (file)
@@ -45,8 +45,7 @@ isc_async_run(isc_loop_t *loop, isc_job_cb cb, void *cbarg);
  *\li  'cbarg' is passed to the 'cb' as the only argument, may be NULL
  */
 
-#define isc_async_current(loopmgr, cb, cbarg) \
-       isc_async_run(isc_loop_current(loopmgr), cb, cbarg)
+#define isc_async_current(cb, cbarg) isc_async_run(isc_loop(), cb, cbarg)
 /*%<
  * Helper macro to run the job on the current loop
  */
index ef34bd2ca4e2252dc28012aeda7f74cba7b29828..e7745323034cf77318de85106de58c0cc5ab237b 100644 (file)
@@ -157,16 +157,6 @@ isc_loop_main(isc_loopmgr_t *loopmgr);
  *\li  'loopmgr' is a valid loop manager.
  */
 
-isc_loop_t *
-isc_loop_current(isc_loopmgr_t *loopmgr);
-/*%<
- * Returns the loop object from which the function has been called,
- * or NULL if not called from a loop.
- *
- * Requires:
- *\li  'loopmgr' is a valid loop manager.
- */
-
 isc_loop_t *
 isc_loop_get(isc_loopmgr_t *loopmgr, uint32_t tid);
 /*%<
index 77cc9c614ef8b369aef26f09957d070910e92666..4aef8f2aadd53e8f202374a683e25411d0a6233c 100644 (file)
@@ -573,13 +573,6 @@ isc_loop_main(isc_loopmgr_t *loopmgr) {
        return (DEFAULT_LOOP(loopmgr));
 }
 
-isc_loop_t *
-isc_loop_current(isc_loopmgr_t *loopmgr) {
-       REQUIRE(VALID_LOOPMGR(loopmgr));
-
-       return (CURRENT_LOOP(loopmgr));
-}
-
 isc_loop_t *
 isc_loop_get(isc_loopmgr_t *loopmgr, uint32_t tid) {
        REQUIRE(VALID_LOOPMGR(loopmgr));
index add574ffb31f6b80d463137a41ba53fd1a6497f6..125b88009e046f296658acb5927e5f4ff439a512 100644 (file)
@@ -124,21 +124,21 @@ teardown_managers(void **state);
        }                 \
        ;
 
-#define ISC_LOOP_TEST_CUSTOM_IMPL(name, setup, teardown)           \
-       void run_test_##name(void **state ISC_ATTR_UNUSED);        \
-       void loop_test_##name(void *arg ISC_ATTR_UNUSED);          \
-       void run_test_##name(void **state ISC_ATTR_UNUSED) {       \
-               isc_job_cb setup_loop = setup;                     \
-               isc_job_cb teardown_loop = teardown;               \
-               if (setup_loop != NULL) {                          \
-                       setup_loop(state);                         \
-               }                                                  \
-               isc_loop_setup(mainloop, loop_test_##name, state); \
-               isc_loopmgr_run(loopmgr);                          \
-               if (teardown_loop != NULL) {                       \
-                       teardown_loop(state);                      \
-               }                                                  \
-       }                                                          \
+#define ISC_LOOP_TEST_CUSTOM_IMPL(name, setup, teardown)                   \
+       void run_test_##name(void **state ISC_ATTR_UNUSED);                \
+       void loop_test_##name(void *arg ISC_ATTR_UNUSED);                  \
+       void run_test_##name(void **state ISC_ATTR_UNUSED) {               \
+               isc_job_cb setup_loop = setup;                             \
+               isc_job_cb teardown_loop = teardown;                       \
+               if (setup_loop != NULL) {                                  \
+                       isc_loop_setup(mainloop, setup_loop, state);       \
+               }                                                          \
+               if (teardown_loop != NULL) {                               \
+                       isc_loop_teardown(mainloop, teardown_loop, state); \
+               }                                                          \
+               isc_loop_setup(mainloop, loop_test_##name, state);         \
+               isc_loopmgr_run(loopmgr);                                  \
+       }                                                                  \
        void loop_test_##name(void *arg ISC_ATTR_UNUSED)
 
 #define ISC_LOOP_TEST_IMPL(name) ISC_LOOP_TEST_CUSTOM_IMPL(name, NULL, NULL)
index 1da62f1d605a8914959712260ed0f21d621fb42a..072816cf242edcbb7511fd0355d307a0aadc1124 100644 (file)
@@ -751,7 +751,7 @@ doh_receive_send_reply_cb(isc_nmhandle_t *handle, isc_result_t eresult,
                        assert_true(eresult == ISC_R_SUCCESS);
                }
 
-               isc_async_current(loopmgr, doh_connect_thread, connect_nm);
+               isc_async_current(doh_connect_thread, connect_nm);
        }
        if (sends <= 0) {
                isc_loopmgr_shutdown(loopmgr);
index 539e273c2820787b9571ab00130f20906e88bf2d..f7e1d28e8b344eef1c304d63fecb2e3d10dcb9b0 100644 (file)
@@ -67,9 +67,9 @@ ISC_RUN_TEST_IMPL(isc_loopmgr) {
 
 static void
 runjob(void *arg ISC_ATTR_UNUSED) {
-       isc_async_current(loopmgr, count, loopmgr);
+       isc_async_current(count, loopmgr);
        if (isc_tid() == 0) {
-               isc_async_current(loopmgr, shutdown_loopmgr, loopmgr);
+               isc_async_current(shutdown_loopmgr, loopmgr);
        }
 }
 
index 0f16219321a2e12a354ccd0cdf7bb6cc99528640..a65c1d5ebcf2d9f4b1698d924836dc736a9970ce 100644 (file)
@@ -388,7 +388,7 @@ connect_connect_cb(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
        if (have_expected_cconnects(atomic_fetch_add(&cconnects, 1) + 1)) {
                do_cconnects_shutdown(loopmgr);
        } else if (do_send) {
-               isc_async_current(loopmgr, stream_recv_send_connect,
+               isc_async_current(stream_recv_send_connect,
                                  (cbarg == NULL
                                           ? get_stream_connect_function()
                                           : (stream_connect_function)cbarg));
@@ -1477,7 +1477,7 @@ udp__connect_cb(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
                {
                        do_cconnects_shutdown(loopmgr);
                } else if (do_send) {
-                       isc_async_current(loopmgr, udp_enqueue_connect, cbarg);
+                       isc_async_current(udp_enqueue_connect, cbarg);
                }
 
                isc_refcount_increment0(&active_creads);
@@ -1819,8 +1819,7 @@ udp_shutdown_connect_connect_cb(isc_nmhandle_t *handle, isc_result_t eresult,
         */
        if (atomic_fetch_add(&cconnects, 1) == 0) {
                assert_int_equal(eresult, ISC_R_SUCCESS);
-               isc_async_current(loopmgr, udp_shutdown_connect_async_cb,
-                                 netmgr);
+               isc_async_current(udp_shutdown_connect_async_cb, netmgr);
        } else {
                assert_int_equal(eresult, ISC_R_SHUTTINGDOWN);
        }
@@ -1853,7 +1852,7 @@ udp_shutdown_connect(void **arg ISC_ATTR_UNUSED) {
         * isc_nm_udpconnect() is synchronous, so we need to launch this on the
         * async loop.
         */
-       isc_async_current(loopmgr, udp_shutdown_connect_async_cb, netmgr);
+       isc_async_current(udp_shutdown_connect_async_cb, netmgr);
 }
 
 int
index fd7f23414c59f226e88a36045f0b194b667c619b..915b4ae3a4ded409d932e27946f86f66c82e0bbe 100644 (file)
@@ -101,21 +101,21 @@ ISC_LOOP_TEST_IMPL(tcpdns_timeout_recovery) {
        connect_readcb = timeout_retry_cb;
        isc_nm_settimeouts(connect_nm, T_SOFT, T_SOFT, T_SOFT, T_SOFT);
 
-       isc_async_current(loopmgr, stream_recv_send_connect, tcpdns_connect);
+       isc_async_current(stream_recv_send_connect, tcpdns_connect);
 }
 
 ISC_LOOP_TEST_IMPL(tcpdns_recv_one) {
        start_listening(ISC_NM_LISTEN_ONE, listen_accept_cb, listen_read_cb);
 
-       isc_async_current(loopmgr, stream_recv_send_connect, tcpdns_connect);
+       isc_async_current(stream_recv_send_connect, tcpdns_connect);
 }
 
 ISC_LOOP_TEST_IMPL(tcpdns_recv_two) {
        start_listening(ISC_NM_LISTEN_ONE, listen_accept_cb, listen_read_cb);
 
-       isc_async_current(loopmgr, stream_recv_send_connect, tcpdns_connect);
+       isc_async_current(stream_recv_send_connect, tcpdns_connect);
 
-       isc_async_current(loopmgr, stream_recv_send_connect, tcpdns_connect);
+       isc_async_current(stream_recv_send_connect, tcpdns_connect);
 }
 
 ISC_LOOP_TEST_IMPL(tcpdns_recv_send) {
index 3c8efd1dedc8e0b055014a8db0da5ae2c0b6587f..66fbbc7d7acf92d5ec7b4cedf02f42bbcd9512ed 100644 (file)
@@ -39,7 +39,7 @@
 #include <tests/isc.h>
 
 /* Set to true (or use -v option) for verbose output */
-static bool verbose = false;
+static bool verbose = true;
 
 #define FUDGE_SECONDS    0         /* in absence of clock_getres() */
 #define FUDGE_NANOSECONDS 500000000 /* in absence of clock_getres() */
@@ -345,6 +345,7 @@ tick_event(void *arg) {
         */
        if (tick == 0) {
                isc_timer_destroy(&tickertimer);
+               isc_loopmgr_shutdown(loopmgr);
        }
 }
 
@@ -361,7 +362,6 @@ once_event(void *arg) {
         */
        atomic_store(&startflag, true);
 
-       isc_loopmgr_shutdown(loopmgr);
        isc_timer_destroy(&oncetimer);
 }