]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
lib/dns/nta.c: use isc_refcount_t
authorOndřej Surý <ondrej@sury.org>
Mon, 20 May 2019 14:41:24 +0000 (16:41 +0200)
committerWitold Kręcicki <wpk@isc.org>
Tue, 9 Jul 2019 14:09:36 +0000 (16:09 +0200)
lib/dns/include/dns/nta.h
lib/dns/nta.c

index cce47b0a44c0109d803d74e1fbaecedba4b2b51f..3bd5d9f9fc42c6d697189c7165943a36c6debc03 100644 (file)
@@ -50,8 +50,9 @@ struct dns_ntatable {
        isc_taskmgr_t           *taskmgr;
        isc_timermgr_t          *timermgr;
        isc_task_t              *task;
+       /* Protected by atomics */
+       isc_refcount_t          references;
        /* Locked by rwlock. */
-       uint32_t                references;
        dns_rbt_t               *table;
 };
 
index 444684c2e950a437e3605a2f727d9126c30d6211..c495c3cff44f4a4760cea00f63f3b2addd36d867 100644 (file)
@@ -133,7 +133,7 @@ dns_ntatable_create(dns_view_t *view,
        ntatable->taskmgr = taskmgr;
 
        ntatable->view = view;
-       ntatable->references = 1;
+       isc_refcount_init(&ntatable->references, 1);
 
        ntatable->magic = NTATABLE_MAGIC;
        *ntatablep = ntatable;
@@ -157,20 +157,13 @@ dns_ntatable_attach(dns_ntatable_t *source, dns_ntatable_t **targetp) {
        REQUIRE(VALID_NTATABLE(source));
        REQUIRE(targetp != NULL && *targetp == NULL);
 
-       RWLOCK(&source->rwlock, isc_rwlocktype_write);
-
-       INSIST(source->references > 0);
-       source->references++;
-       INSIST(source->references != 0);
-
-       RWUNLOCK(&source->rwlock, isc_rwlocktype_write);
+       isc_refcount_increment(&source->references);
 
        *targetp = source;
 }
 
 void
 dns_ntatable_detach(dns_ntatable_t **ntatablep) {
-       bool destroy = false;
        dns_ntatable_t *ntatable;
 
        REQUIRE(ntatablep != NULL && VALID_NTATABLE(*ntatablep));
@@ -178,16 +171,10 @@ dns_ntatable_detach(dns_ntatable_t **ntatablep) {
        ntatable = *ntatablep;
        *ntatablep = NULL;
 
-       RWLOCK(&ntatable->rwlock, isc_rwlocktype_write);
-       INSIST(ntatable->references > 0);
-       ntatable->references--;
-       if (ntatable->references == 0)
-               destroy = true;
-       RWUNLOCK(&ntatable->rwlock, isc_rwlocktype_write);
-
-       if (destroy) {
+       if (isc_refcount_decrement(&ntatable->references) == 1) {
                dns_rbt_destroy(&ntatable->table);
                isc_rwlock_destroy(&ntatable->rwlock);
+               isc_refcount_destroy(&ntatable->references);
                if (ntatable->task != NULL)
                        isc_task_detach(&ntatable->task);
                ntatable->timermgr = NULL;