]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Improve isc_refcount with initializer and implicit destroy
authorOndřej Surý <ondrej@isc.org>
Fri, 22 Sep 2023 11:57:26 +0000 (13:57 +0200)
committerOndřej Surý <ondrej@isc.org>
Sun, 24 Sep 2023 08:08:56 +0000 (10:08 +0200)
Add ISC_REFCOUNT_INITIALIZER(x) macro and implicitly call
isc_refcount_destroy() in the ISC_REFCOUNT_IMPL() macros
to reduce code duplicities.

17 files changed:
bin/named/controlconf.c
lib/dns/adb.c
lib/dns/catz.c
lib/dns/dispatch.c
lib/dns/keytable.c
lib/dns/nametree.c
lib/dns/nta.c
lib/dns/request.c
lib/dns/resolver.c
lib/dns/rpz.c
lib/dns/tsig.c
lib/dns/xfrin.c
lib/dns/zone.c
lib/isc/include/isc/refcount.h
lib/isc/netmgr/netmgr.c
lib/isc/ratelimiter.c
lib/ns/client.c

index a84af436fe83993ee0568750d5a83d804b11cada..eff48e0af75afb4a2653d57ee28359637b50f762 100644 (file)
@@ -173,8 +173,6 @@ free_listener(controllistener_t *listener) {
        INSIST(listener->exiting);
        INSIST(ISC_LIST_EMPTY(listener->connections));
 
-       isc_refcount_destroy(&listener->references);
-
        REQUIRE(listener->sock == NULL);
 
        free_controlkeylist(&listener->keys, listener->mctx);
index beab25b57d8664f474e8fec8ff34cb0e0d7fdd17..c47b2219aae417b2c42e3cee362ab8380de1dd57 100644 (file)
@@ -1179,7 +1179,6 @@ destroy_adbentry(dns_adbentry_t *entry) {
        }
 
        isc_mutex_destroy(&entry->lock);
-       isc_refcount_destroy(&entry->references);
        isc_mem_put(adb->mctx, entry, sizeof(*entry));
 
        dec_adbstats(adb, dns_adbstats_entriescnt);
@@ -1963,7 +1962,6 @@ destroy(dns_adb_t *adb) {
        isc_mem_detach(&adb->hmctx);
 
        isc_mutex_destroy(&adb->lock);
-       isc_refcount_destroy(&adb->references);
 
        isc_stats_detach(&adb->stats);
        dns_resolver_detach(&adb->res);
index 26be1ec9e170f39d884120a84efc04a531648729..92149db4685d6bf8cf64871c4e05d05df16bedb6 100644 (file)
@@ -1020,7 +1020,6 @@ dns__catz_zone_destroy(dns_catz_zone_t *catz) {
        dns_catz_options_free(&catz->zoneoptions, mctx);
 
        dns_catz_zones_detach(&catz->catzs);
-       isc_refcount_destroy(&catz->references);
 
        isc_mem_put(mctx, catz, sizeof(*catz));
 }
@@ -1032,7 +1031,6 @@ dns__catz_zones_destroy(dns_catz_zones_t *catzs) {
 
        catzs->magic = 0;
        isc_mutex_destroy(&catzs->lock);
-       isc_refcount_destroy(&catzs->references);
 
        isc_mem_putanddetach(&catzs->mctx, catzs, sizeof(*catzs));
 }
index 0b82990a1a2dc47c6d84d69e3bb90b4dd08fc937..9871c15c34a39304d755ccd8c254c24c70945dfd 100644 (file)
@@ -414,8 +414,6 @@ dispentry_destroy(dns_dispentry_t *resp) {
        INSIST(disp->requests > 0);
        disp->requests--;
 
-       isc_refcount_destroy(&resp->references);
-
        resp->magic = 0;
 
        INSIST(!ISC_LINK_LINKED(resp, plink));
@@ -1363,7 +1361,6 @@ dispatch_destroy(dns_dispatch_t *disp) {
        dns_dispatchmgr_t *mgr = disp->mgr;
        uint32_t tid = isc_tid();
 
-       isc_refcount_destroy(&disp->references);
        disp->magic = 0;
 
        if (disp->socktype == isc_socktype_tcp) {
index 99ffe5623ac868379cce3c91bc2c32c15441c92e..10614431b3de8bdeded4a639c20379b8e77b6411 100644 (file)
@@ -104,7 +104,6 @@ static void
 destroy_keynode(dns_keynode_t *knode) {
        dns_rdata_t *rdata = NULL;
 
-       isc_refcount_destroy(&knode->references);
        isc_rwlock_destroy(&knode->rwlock);
        if (knode->dslist != NULL) {
                for (rdata = ISC_LIST_HEAD(knode->dslist->rdata); rdata != NULL;
@@ -163,7 +162,6 @@ destroy_keytable(dns_keytable_t *keytable) {
        dns_qpread_destroy(keytable->table, &qpr);
 
        dns_qpmulti_destroy(&keytable->table);
-       isc_refcount_destroy(&keytable->references);
 
        isc_mem_putanddetach(&keytable->mctx, keytable, sizeof(*keytable));
 }
index ec297ca6f26704a7e05a71a4d6bd3e026f9e8b0e..08140371c09bed725fdefd88864bebd2fbb739b8 100644 (file)
@@ -66,7 +66,6 @@ static dns_qpmethods_t qpmethods = {
 
 static void
 destroy_ntnode(dns_ntnode_t *node) {
-       isc_refcount_destroy(&node->references);
        if (node->bits != NULL) {
                isc_mem_cput(node->mctx, node->bits, node->bits[0],
                             sizeof(char));
@@ -120,7 +119,6 @@ destroy_nametree(dns_nametree_t *nametree) {
        /* dns_qpread_destroy(nametree->table, &qpr); */
 
        dns_qpmulti_destroy(&nametree->table);
-       isc_refcount_destroy(&nametree->references);
 
        isc_mem_putanddetach(&nametree->mctx, nametree, sizeof(*nametree));
 }
index 35ee03e8de198b6f6aa12cdf89be2b44862b5593..6df1a9f5ab6b7edc9435a64df75cae3b59ec1e02 100644 (file)
@@ -93,7 +93,6 @@ dns__nta_destroy(dns__nta_t *nta) {
        REQUIRE(nta->timer == NULL);
 
        nta->magic = 0;
-       isc_refcount_destroy(&nta->references);
        if (dns_rdataset_isassociated(&nta->rdataset)) {
                dns_rdataset_disassociate(&nta->rdataset);
        }
@@ -140,7 +139,6 @@ dns_ntatable_create(dns_view_t *view, isc_loopmgr_t *loopmgr,
 
 static void
 dns__ntatable_destroy(dns_ntatable_t *ntatable) {
-       isc_refcount_destroy(&ntatable->references);
        ntatable->magic = 0;
        isc_rwlock_destroy(&ntatable->rwlock);
        dns_qpmulti_destroy(&ntatable->table);
index 46affed3f1e69eb4d1479ce6eb3a15bb6c716a69..dc8aaaec648c58e4632db674d02eb4aad411015f 100644 (file)
@@ -227,8 +227,6 @@ requestmgr_destroy(dns_requestmgr_t *requestmgr) {
 
        INSIST(atomic_load(&requestmgr->shuttingdown));
 
-       isc_refcount_destroy(&requestmgr->references);
-
        size_t nloops = isc_loopmgr_nloops(requestmgr->loopmgr);
        for (size_t i = 0; i < nloops; i++) {
                INSIST(ISC_LIST_EMPTY(requestmgr->requests[i]));
@@ -973,8 +971,6 @@ req_destroy(dns_request_t *request) {
 
        req_log(ISC_LOG_DEBUG(3), "%s: request %p", __func__, request);
 
-       isc_refcount_destroy(&request->references);
-
        /*
         * These should have been cleaned up before the
         * completion event was sent.
index f65b7e4a9267857c0478ed43f6a1e049439e770b..700c531eabd1da71d41ad12c7ebed2bad9abe14e 100644 (file)
@@ -998,8 +998,6 @@ resquery_destroy(resquery_t *query) {
                dns_dispatch_detach(&query->dispatch);
        }
 
-       isc_refcount_destroy(&query->references);
-
        LOCK(&fctx->lock);
        atomic_fetch_sub_release(&fctx->nqueries, 1);
        UNLOCK(&fctx->lock);
@@ -4309,8 +4307,6 @@ fctx_destroy(fetchctx_t *fctx) {
 
        FCTXTRACE("destroy");
 
-       isc_refcount_destroy(&fctx->references);
-
        fctx->magic = 0;
 
        res = fctx->res;
@@ -9850,7 +9846,6 @@ static void
 dns_resolver__destroy(dns_resolver_t *res) {
        alternate_t *a = NULL;
 
-       isc_refcount_destroy(&res->references);
        REQUIRE(!atomic_load_acquire(&res->priming));
        REQUIRE(res->primefetch == NULL);
 
index ee4ed0613a9fa75b2cafa3efbe97f577fe18cb4e..46dc8ef3a73e660f48673c30db80a30f2a8d750d 100644 (file)
@@ -2088,8 +2088,6 @@ static void
 dns__rpz_zones_destroy(dns_rpz_zones_t *rpzs) {
        REQUIRE(rpzs->shuttingdown);
 
-       isc_refcount_destroy(&rpzs->references);
-
        for (dns_rpz_num_t rpz_num = 0; rpz_num < DNS_RPZ_MAX_ZONES; ++rpz_num)
        {
                if (rpzs->zones[rpz_num] == NULL) {
index 8b03b2dba68b284fd556c2d62d568898862a9ad4..b65c0b7baf44b73e93a899763a20c09363254746 100644 (file)
@@ -332,7 +332,6 @@ destroyring(dns_tsigkeyring_t *ring) {
 
        ring->magic = 0;
 
-       isc_refcount_destroy(&ring->references);
        isc_rwlock_destroy(&ring->lock);
        isc_mem_putanddetach(&ring->mctx, ring, sizeof(dns_tsigkeyring_t));
 }
index 22a89916176a6c8160b6e318d5b043933bd290ff..3a3da99cfb3720bfe9d39ddf6ad8fc881a22f537 100644 (file)
@@ -1859,7 +1859,6 @@ xfrin_destroy(dns_xfrin_t *xfr) {
 
        /* Safe-guards */
        REQUIRE(atomic_load(&xfr->shuttingdown));
-       isc_refcount_destroy(&xfr->references);
 
        INSIST(xfr->shutdown_result != ISC_R_UNSET);
 
index bf49b693b436669560ac9b9bcdd48f868afe80db..82b4157585edd60a2ff0a55c225d7e5f6880c791 100644 (file)
@@ -5601,8 +5601,6 @@ closeversion:
 
 static void
 zone_destroy(dns_zone_t *zone) {
-       isc_refcount_destroy(&zone->references);
-
        /*
         * Stop things being restarted after we cancel them below.
         */
index 823123307245acfc1c448c01500f6bd9314ffa35..8524b04410614d77e9a96e0bb063f963ce38d644 100644 (file)
@@ -34,6 +34,8 @@ ISC_LANG_BEGINDECLS
 
 typedef atomic_uint_fast32_t isc_refcount_t;
 
+#define ISC_REFCOUNT_INITIALIZER(a) (a)
+
 /** \def isc_refcount_init(ref, n)
  *  \brief Initialize the reference counter.
  *  \param[in] ref pointer to reference counter.
@@ -145,6 +147,7 @@ typedef atomic_uint_fast32_t isc_refcount_t;
                uint_fast32_t refs =                                          \
                        isc_refcount_decrement(&ptr->references) - 1;         \
                if (refs == 0) {                                              \
+                       isc_refcount_destroy(&ptr->references);               \
                        destroy(ptr);                                         \
                }                                                             \
                fprintf(stderr,                                               \
@@ -170,6 +173,7 @@ typedef atomic_uint_fast32_t isc_refcount_t;
                uint_fast32_t refs =                                          \
                        isc_refcount_decrement(&ptr->references) - 1;         \
                if (refs == 0) {                                              \
+                       isc_refcount_destroy(&ptr->references);               \
                        destroy(ptr);                                         \
                }                                                             \
                fprintf(stderr,                                               \
@@ -193,6 +197,7 @@ typedef atomic_uint_fast32_t isc_refcount_t;
        void name##_unref(name##_t *ptr) {                           \
                REQUIRE(ptr != NULL);                                \
                if (isc_refcount_decrement(&ptr->references) == 1) { \
+                       isc_refcount_destroy(&ptr->references);      \
                        destroy(ptr);                                \
                }                                                    \
        }                                                            \
index de491924749789f9b2216133847ed5e24a89ae9d..df9b687c7c1886f3fb35a4592b8e90bf4a3c5180 100644 (file)
@@ -880,8 +880,6 @@ isc_nmhandle_is_stream(isc_nmhandle_t *handle) {
 
 static void
 nmhandle_free(isc_nmsocket_t *sock, isc_nmhandle_t *handle) {
-       isc_refcount_destroy(&handle->references);
-
        handle->magic = 0;
 
        if (handle->dofree != NULL) {
index a7c59152117fcac3fa178f917cefa3f1bcd77ec0..9d59ffc43d1086dc244b2437e5e69dd0f38e2a56 100644 (file)
@@ -313,8 +313,6 @@ isc_ratelimiter_shutdown(isc_ratelimiter_t *restrict rl) {
 
 static void
 ratelimiter_destroy(isc_ratelimiter_t *restrict rl) {
-       isc_refcount_destroy(&rl->references);
-
        LOCK(&rl->lock);
        REQUIRE(rl->state == isc_ratelimiter_shuttingdown);
        UNLOCK(&rl->lock);
index 58d5c4862489c94dda0f9b03b54d2eb72cc41c01..967b915b2230e69087ebf5997c1ff22cef5933bc 100644 (file)
@@ -2383,8 +2383,6 @@ clientmgr_destroy_cb(void *arg) {
 
        manager->magic = 0;
 
-       isc_refcount_destroy(&manager->references);
-
        isc_loop_detach(&manager->loop);
 
        dns_aclenv_detach(&manager->aclenv);