From f5fc224af39ca4bfcb421eece6e4597c30071429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 29 Mar 2023 09:02:22 +0200 Subject: [PATCH] Add isc_async_current() macro to run job on current loop Previously, isc_job_run() could have been used to run the job on the current loop and the isc_job_run() would take care of allocating and deallocating the job. After the change in this MR, the isc_job_run() is more complicated to use, so we introduce the isc_async_current() macro to suplement isc_async_run() when we need to run the job on the current loop. --- bin/delv/delv.c | 3 +-- bin/dnssec/dnssec-signzone.c | 2 +- bin/nsupdate/nsupdate.c | 2 +- lib/isc/include/isc/async.h | 6 ++++++ tests/isc/doh_test.c | 3 +-- tests/isc/loop_test.c | 5 ++--- tests/isc/netmgr_common.c | 8 ++++---- tests/isc/tcpdns_test.c | 12 ++++-------- tests/isc/udp_test.c | 6 ++---- 9 files changed, 22 insertions(+), 25 deletions(-) diff --git a/bin/delv/delv.c b/bin/delv/delv.c index e42af92dd7..110d4210d7 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -2169,8 +2169,7 @@ run_server(void *arg) { ns_client_request, ifp, accept_cb, ifp, 10, NULL, NULL, &ifp->tcplistensocket)); ifp->flags |= NS_INTERFACEFLAG_LISTENING; - isc_async_run(isc_loop_current(loopmgr), sendquery, - ifp->tcplistensocket); + isc_async_current(loopmgr, sendquery, ifp->tcplistensocket); return; diff --git a/bin/dnssec/dnssec-signzone.c b/bin/dnssec/dnssec-signzone.c index a8bb578532..1a5b3b40fe 100644 --- a/bin/dnssec/dnssec-signzone.c +++ b/bin/dnssec/dnssec-signzone.c @@ -1667,7 +1667,7 @@ assignwork(void *arg) { lock_and_dumpnode(dns_fixedname_name(&fname), node); dns_db_detachnode(gdb, &node); - isc_async_run(isc_loop_current(loopmgr), assignwork, NULL); + isc_async_current(loopmgr, assignwork, NULL); } /*% diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index 46eb03d423..9c38a6ed68 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -2424,7 +2424,7 @@ static void done_update(void) { ddebug("done_update()"); - isc_async_run(isc_loop_main(loopmgr), getinput, NULL); + isc_async_current(loopmgr, getinput, NULL); } static void diff --git a/lib/isc/include/isc/async.h b/lib/isc/include/isc/async.h index ea36a150dd..c3785fa0f7 100644 --- a/lib/isc/include/isc/async.h +++ b/lib/isc/include/isc/async.h @@ -45,4 +45,10 @@ 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) +/*%< + * Helper macro to run the job on the current loop + */ + ISC_LANG_ENDDECLS diff --git a/tests/isc/doh_test.c b/tests/isc/doh_test.c index 2c770ef0fc..43c0f98191 100644 --- a/tests/isc/doh_test.c +++ b/tests/isc/doh_test.c @@ -702,8 +702,7 @@ doh_receive_send_reply_cb(isc_nmhandle_t *handle, isc_result_t eresult, assert_true(eresult == ISC_R_SUCCESS); } - isc_async_run(isc_loop_current(loopmgr), doh_connect_thread, - connect_nm); + isc_async_current(loopmgr, 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 d863309c51..cf13a4a586 100644 --- a/tests/isc/loop_test.c +++ b/tests/isc/loop_test.c @@ -66,11 +66,10 @@ ISC_RUN_TEST_IMPL(isc_loopmgr) { static void runjob(void *arg __attribute__((__unused__))) { - isc_async_run(isc_loop_current(loopmgr), count, loopmgr); + isc_async_current(loopmgr, count, loopmgr); if (isc_tid() == 0) { - isc_async_run(isc_loop_current(loopmgr), shutdown_loopmgr, - loopmgr); + isc_async_current(loopmgr, shutdown_loopmgr, loopmgr); } } diff --git a/tests/isc/netmgr_common.c b/tests/isc/netmgr_common.c index ad44777918..62bd912a1f 100644 --- a/tests/isc/netmgr_common.c +++ b/tests/isc/netmgr_common.c @@ -368,10 +368,10 @@ 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_run(isc_loop_current(loopmgr), - stream_recv_send_connect, - (cbarg == NULL ? get_stream_connect_function() - : (stream_connect_function)cbarg)); + isc_async_current(loopmgr, stream_recv_send_connect, + (cbarg == NULL + ? get_stream_connect_function() + : (stream_connect_function)cbarg)); } isc_refcount_increment0(&active_creads); diff --git a/tests/isc/tcpdns_test.c b/tests/isc/tcpdns_test.c index dabd0e84e4..4747f4ad20 100644 --- a/tests/isc/tcpdns_test.c +++ b/tests/isc/tcpdns_test.c @@ -100,25 +100,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_run(isc_loop_current(loopmgr), stream_recv_send_connect, - tcpdns_connect); + isc_async_current(loopmgr, 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_run(isc_loop_current(loopmgr), stream_recv_send_connect, - tcpdns_connect); + isc_async_current(loopmgr, 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_run(isc_loop_current(loopmgr), stream_recv_send_connect, - tcpdns_connect); + isc_async_current(loopmgr, stream_recv_send_connect, tcpdns_connect); - isc_async_run(isc_loop_current(loopmgr), stream_recv_send_connect, - tcpdns_connect); + isc_async_current(loopmgr, stream_recv_send_connect, tcpdns_connect); } ISC_LOOP_TEST_IMPL(tcpdns_recv_send) { diff --git a/tests/isc/udp_test.c b/tests/isc/udp_test.c index 54d4489a8a..17221a1fb9 100644 --- a/tests/isc/udp_test.c +++ b/tests/isc/udp_test.c @@ -540,8 +540,7 @@ ISC_TEARDOWN_TEST_IMPL(udp_shutdown_connect) { ISC_LOOP_TEST_IMPL(udp_shutdown_connect) { isc_loopmgr_shutdown(loopmgr); isc_refcount_increment0(&active_cconnects); - isc_async_run(isc_loop_current(loopmgr), udp_connect_udpconnect, - netmgr); + isc_async_current(loopmgr, udp_connect_udpconnect, netmgr); } static void @@ -865,8 +864,7 @@ udp__connect_cb(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) { { do_cconnects_shutdown(loopmgr); } else if (do_send) { - isc_async_run(isc_loop_current(loopmgr), udp__connect, - cbarg); + isc_async_current(loopmgr, udp__connect, cbarg); } isc_refcount_increment0(&active_creads);