From: Evan Hunt Date: Tue, 26 Mar 2024 09:13:53 +0000 (-0700) Subject: complete removal of isc_loop_current() X-Git-Tag: v9.19.23~6^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63659e2e3a4e0a4cc84f551d08edb8e64a4b8526;p=thirdparty%2Fbind9.git complete removal of isc_loop_current() 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). --- diff --git a/bin/delv/delv.c b/bin/delv/delv.c index 31d44667e93..a767c0cffa4 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -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; diff --git a/bin/dnssec/dnssec-signzone.c b/bin/dnssec/dnssec-signzone.c index afe2eff19b1..7b854641805 100644 --- a/bin/dnssec/dnssec-signzone.c +++ b/bin/dnssec/dnssec-signzone.c @@ -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); } /*% diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index f81c1965b27..3048df83458 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -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 diff --git a/lib/dns/nta.c b/lib/dns/nta.c index abff2cba4ff..ab04bb736fb 100644 --- a/lib/dns/nta.c +++ b/lib/dns/nta.c @@ -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; } diff --git a/lib/isc/include/isc/async.h b/lib/isc/include/isc/async.h index c3785fa0f77..2b94cd78e09 100644 --- a/lib/isc/include/isc/async.h +++ b/lib/isc/include/isc/async.h @@ -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 */ diff --git a/lib/isc/include/isc/loop.h b/lib/isc/include/isc/loop.h index ef34bd2ca4e..e7745323034 100644 --- a/lib/isc/include/isc/loop.h +++ b/lib/isc/include/isc/loop.h @@ -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); /*%< diff --git a/lib/isc/loop.c b/lib/isc/loop.c index 77cc9c614ef..4aef8f2aadd 100644 --- a/lib/isc/loop.c +++ b/lib/isc/loop.c @@ -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)); diff --git a/tests/include/tests/isc.h b/tests/include/tests/isc.h index add574ffb31..125b88009e0 100644 --- a/tests/include/tests/isc.h +++ b/tests/include/tests/isc.h @@ -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) diff --git a/tests/isc/doh_test.c b/tests/isc/doh_test.c index 1da62f1d605..072816cf242 100644 --- a/tests/isc/doh_test.c +++ b/tests/isc/doh_test.c @@ -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); diff --git a/tests/isc/loop_test.c b/tests/isc/loop_test.c index 539e273c282..f7e1d28e8b3 100644 --- a/tests/isc/loop_test.c +++ b/tests/isc/loop_test.c @@ -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); } } diff --git a/tests/isc/netmgr_common.c b/tests/isc/netmgr_common.c index 0f16219321a..a65c1d5ebcf 100644 --- a/tests/isc/netmgr_common.c +++ b/tests/isc/netmgr_common.c @@ -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 diff --git a/tests/isc/tcpdns_test.c b/tests/isc/tcpdns_test.c index fd7f23414c5..915b4ae3a4d 100644 --- a/tests/isc/tcpdns_test.c +++ b/tests/isc/tcpdns_test.c @@ -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) { diff --git a/tests/isc/timer_test.c b/tests/isc/timer_test.c index 3c8efd1dedc..66fbbc7d7ac 100644 --- a/tests/isc/timer_test.c +++ b/tests/isc/timer_test.c @@ -39,7 +39,7 @@ #include /* 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); }