]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
lib/ns/client: use refcount_t for reference counting
authorWitold Kręcicki <wpk@isc.org>
Fri, 17 May 2019 11:33:30 +0000 (13:33 +0200)
committerWitold Kręcicki <wpk@isc.org>
Tue, 9 Jul 2019 14:09:36 +0000 (16:09 +0200)
lib/ns/client.c
lib/ns/include/ns/client.h

index c07e57cad14a598cd2e14742e7225a214f530d22..dd054422e5682d7f25bb7a339cbfd233b0a08864 100644 (file)
@@ -489,7 +489,7 @@ exit_check(ns_client_t *client) {
                }
 
                if (! (client->nsends == 0 && client->nrecvs == 0 &&
-                      client->references == 0))
+                      isc_refcount_current(&client->references) == 0))
                {
                        /*
                         * Still waiting for I/O cancel completion.
@@ -3175,7 +3175,7 @@ client_create(ns_clientmgr_t *manager, ns_client_t **clientp) {
        client->nrecvs = 0;
        client->nupdates = 0;
        client->nctls = 0;
-       client->references = 0;
+       isc_refcount_init(&client->references, 0);
        client->attributes = 0;
        client->view = NULL;
        client->dispatch = NULL;
@@ -3546,26 +3546,28 @@ client_udprecv(ns_client_t *client) {
 
 void
 ns_client_attach(ns_client_t *source, ns_client_t **targetp) {
+       uint32_t oldrefs;
        REQUIRE(NS_CLIENT_VALID(source));
        REQUIRE(targetp != NULL && *targetp == NULL);
 
-       source->references++;
+       oldrefs = isc_refcount_increment(&source->references);
        ns_client_log(source, NS_LOGCATEGORY_CLIENT,
                      NS_LOGMODULE_CLIENT, ISC_LOG_DEBUG(10),
-                     "ns_client_attach: ref = %d", source->references);
+                     "ns_client_attach: ref = %d", oldrefs+1);
        *targetp = source;
 }
 
 void
 ns_client_detach(ns_client_t **clientp) {
+       int32_t oldrefs;
        ns_client_t *client = *clientp;
+       oldrefs = isc_refcount_decrement(&client->references);
+       INSIST(oldrefs > 0);
 
-       client->references--;
-       INSIST(client->references >= 0);
        *clientp = NULL;
        ns_client_log(client, NS_LOGCATEGORY_CLIENT,
                      NS_LOGMODULE_CLIENT, ISC_LOG_DEBUG(10),
-                     "ns_client_detach: ref = %d", client->references);
+                     "ns_client_detach: ref = %d", oldrefs-1);
        (void)exit_check(client);
 }
 
@@ -3924,7 +3926,7 @@ ns__clientmgr_getclient(ns_clientmgr_t *manager, ns_interface_t *ifp,
        INSIST(client->recursionquota == NULL);
 
        client->dscp = ifp->dscp;
-       client->references++;
+       isc_refcount_increment(&client->references);
 
        if (tcp) {
                client->attributes |= NS_CLIENTATTR_TCP;
index 110d25e95366277096e8a9fc3019b93bc68a662c..02531f21180092d98bf2e9cbd89d9d093f38ea38 100644 (file)
@@ -101,7 +101,7 @@ struct ns_client {
        int                     nrecvs;
        int                     nupdates;
        int                     nctls;
-       int                     references;
+       isc_refcount_t          references;
        bool                    tcpactive;
        bool                    needshutdown;   /*
                                                 * Used by clienttest to get