]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Replace atomic operations in bin/named/client.c with isc_refcount reference counting
authorOndřej Surý <ondrej@sury.org>
Wed, 17 Apr 2019 13:22:27 +0000 (15:22 +0200)
committerOndřej Surý <ondrej@sury.org>
Fri, 26 Apr 2019 20:14:26 +0000 (22:14 +0200)
(cherry picked from commit ef49780d30d3ddc5735cfc32561b678a634fa72f)
(cherry picked from commit e203d4d65a3bbba4303b9f185bd38314c0a3f77c)

lib/ns/client.c
lib/ns/include/ns/interfacemgr.h
lib/ns/interfacemgr.c

index 6e58b7e3501f5929ed396d44668e3b4f7b555f24..c07e57cad14a598cd2e14742e7225a214f530d22 100644 (file)
@@ -421,11 +421,11 @@ tcpconn_detach(ns_client_t *client) {
 static void
 mark_tcp_active(ns_client_t *client, bool active) {
        if (active && !client->tcpactive) {
-               atomic_fetch_add(&client->interface->ntcpactive, 1);
+               isc_refcount_increment0(&client->interface->ntcpactive);
                client->tcpactive = active;
        } else if (!active && client->tcpactive) {
                uint32_t old =
-                       atomic_fetch_sub(&client->interface->ntcpactive, 1);
+                       isc_refcount_decrement(&client->interface->ntcpactive);
                INSIST(old > 0);
                client->tcpactive = active;
        }
@@ -573,7 +573,7 @@ exit_check(ns_client_t *client) {
                if (client->mortal && TCP_CLIENT(client) &&
                    client->newstate != NS_CLIENTSTATE_FREED &&
                    (client->sctx->options & NS_SERVER_CLIENTTEST) == 0 &&
-                   atomic_load(&client->interface->ntcpaccepting) == 0)
+                   isc_refcount_current(&client->interface->ntcpaccepting) == 0)
                {
                        /* Nobody else is accepting */
                        client->mortal = false;
@@ -3325,7 +3325,7 @@ client_newconn(isc_task_t *task, isc_event_t *event) {
        INSIST(client->naccepts == 1);
        client->naccepts--;
 
-       old = atomic_fetch_sub(&client->interface->ntcpaccepting, 1);
+       old = isc_refcount_decrement(&client->interface->ntcpaccepting);
        INSIST(old > 0);
 
        /*
@@ -3455,7 +3455,7 @@ client_accept(ns_client_t *client) {
                 * quota is tcp-clients plus the number of listening
                 * interfaces plus 1.)
                 */
-               exit = (atomic_load(&client->interface->ntcpactive) >
+               exit = (isc_refcount_current(&client->interface->ntcpactive) >
                        (client->tcpactive ? 1U : 0U));
                if (exit) {
                        client->newstate = NS_CLIENTSTATE_INACTIVE;
@@ -3514,7 +3514,7 @@ client_accept(ns_client_t *client) {
         * listening for connections itself to prevent the interface
         * going dead.
         */
-       atomic_fetch_add(&client->interface->ntcpaccepting, 1);
+       isc_refcount_increment0(&client->interface->ntcpaccepting);
 }
 
 static void
index 7baafa95c0985bab2aae60471b1e3edd61cbc076..6bbb0e67f3455eb8cdfce151d23535ca2ce877f1 100644 (file)
@@ -45,6 +45,7 @@
 #include <isc/magic.h>
 #include <isc/mem.h>
 #include <isc/socket.h>
+#include <isc/refcount.h>
 
 #include <dns/geoip.h>
 #include <dns/result.h>
@@ -76,11 +77,11 @@ struct ns_interface {
                                                /*%< UDP dispatchers. */
        isc_socket_t *          tcpsocket;      /*%< TCP socket. */
        isc_dscp_t              dscp;           /*%< "listen-on" DSCP value */
-       atomic_uint_fast32_t    ntcpaccepting;  /*%< Number of clients
+       isc_refcount_t          ntcpaccepting;  /*%< Number of clients
                                                     ready to accept new
                                                     TCP connections on this
                                                     interface */
-       atomic_uint_fast32_t    ntcpactive;     /*%< Number of clients
+       isc_refcount_t          ntcpactive;     /*%< Number of clients
                                                     servicing TCP queries
                                                     (whether accepting or
                                                     connected) */
index ea44c5dc08a67644b1d57423943de79740b8798b..275a7a3d29b524f5dea119ad2ef831b5581e05c7 100644 (file)
@@ -423,8 +423,8 @@ ns_interface_create(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr,
         * connections will be handled in parallel even though there is
         * only one client initially.
         */
-       atomic_init(&ifp->ntcpaccepting, 0);
-       atomic_init(&ifp->ntcpactive, 0);
+       isc_refcount_init(&ifp->ntcpaccepting, 0);
+       isc_refcount_init(&ifp->ntcpactive, 0);
 
        ifp->nudpdispatch = 0;
 
@@ -657,6 +657,9 @@ ns_interface_destroy(ns_interface_t *ifp) {
 
        ns_interfacemgr_detach(&ifp->mgr);
 
+       isc_refcount_destroy(&ifp->ntcpactive);
+       isc_refcount_destroy(&ifp->ntcpaccepting);
+
        ifp->magic = 0;
        isc_mem_put(mctx, ifp, sizeof(*ifp));
 }