Commit d72f436b authored by Ondřej Surý's avatar Ondřej Surý

Replace atomic operations in bin/named/client.c with isc_refcount reference counting

(cherry picked from commit ef49780d)
parent a3a6947a
Pipeline #13943 passed with stages
in 17 minutes and 22 seconds
...@@ -428,12 +428,10 @@ tcpconn_detach(ns_client_t *client) { ...@@ -428,12 +428,10 @@ tcpconn_detach(ns_client_t *client) {
static void static void
mark_tcp_active(ns_client_t *client, bool active) { mark_tcp_active(ns_client_t *client, bool active) {
if (active && !client->tcpactive) { if (active && !client->tcpactive) {
isc_atomic_xadd(&client->interface->ntcpactive, 1); isc_refcount_increment0(&client->interface->ntcpactive, NULL);
client->tcpactive = active; client->tcpactive = active;
} else if (!active && client->tcpactive) { } else if (!active && client->tcpactive) {
uint32_t old = isc_refcount_decrement(&client->interface->ntcpactive, NULL);
isc_atomic_xadd(&client->interface->ntcpactive, -1);
INSIST(old > 0);
client->tcpactive = active; client->tcpactive = active;
} }
} }
...@@ -580,7 +578,7 @@ exit_check(ns_client_t *client) { ...@@ -580,7 +578,7 @@ exit_check(ns_client_t *client) {
if (client->mortal && TCP_CLIENT(client) && if (client->mortal && TCP_CLIENT(client) &&
client->newstate != NS_CLIENTSTATE_FREED && client->newstate != NS_CLIENTSTATE_FREED &&
(client->sctx->options & NS_SERVER_CLIENTTEST) == 0 && (client->sctx->options & NS_SERVER_CLIENTTEST) == 0 &&
isc_atomic_xadd(&client->interface->ntcpaccepting, 0) == 0) isc_refcount_current(&client->interface->ntcpaccepting) == 0)
{ {
/* Nobody else is accepting */ /* Nobody else is accepting */
client->mortal = false; client->mortal = false;
...@@ -3306,7 +3304,6 @@ client_newconn(isc_task_t *task, isc_event_t *event) { ...@@ -3306,7 +3304,6 @@ client_newconn(isc_task_t *task, isc_event_t *event) {
ns_client_t *client = event->ev_arg; ns_client_t *client = event->ev_arg;
isc_socket_newconnev_t *nevent = (isc_socket_newconnev_t *)event; isc_socket_newconnev_t *nevent = (isc_socket_newconnev_t *)event;
dns_aclenv_t *env = ns_interfacemgr_getaclenv(client->interface->mgr); dns_aclenv_t *env = ns_interfacemgr_getaclenv(client->interface->mgr);
uint32_t old;
REQUIRE(event->ev_type == ISC_SOCKEVENT_NEWCONN); REQUIRE(event->ev_type == ISC_SOCKEVENT_NEWCONN);
REQUIRE(NS_CLIENT_VALID(client)); REQUIRE(NS_CLIENT_VALID(client));
...@@ -3326,8 +3323,7 @@ client_newconn(isc_task_t *task, isc_event_t *event) { ...@@ -3326,8 +3323,7 @@ client_newconn(isc_task_t *task, isc_event_t *event) {
INSIST(client->naccepts == 1); INSIST(client->naccepts == 1);
client->naccepts--; client->naccepts--;
old = isc_atomic_xadd(&client->interface->ntcpaccepting, -1); isc_refcount_decrement(&client->interface->ntcpaccepting, NULL);
INSIST(old > 0);
/* /*
* We must take ownership of the new socket before the exit * We must take ownership of the new socket before the exit
...@@ -3457,8 +3453,8 @@ client_accept(ns_client_t *client) { ...@@ -3457,8 +3453,8 @@ client_accept(ns_client_t *client) {
* quota is tcp-clients plus the number of listening * quota is tcp-clients plus the number of listening
* interfaces plus 1.) * interfaces plus 1.)
*/ */
exit = (isc_atomic_xadd(&client->interface->ntcpactive, 0) > exit = (isc_refcount_current(&client->interface->ntcpactive) >
(client->tcpactive ? 1 : 0)); (client->tcpactive ? 1U : 0U));
if (exit) { if (exit) {
client->newstate = NS_CLIENTSTATE_INACTIVE; client->newstate = NS_CLIENTSTATE_INACTIVE;
(void)exit_check(client); (void)exit_check(client);
...@@ -3516,7 +3512,7 @@ client_accept(ns_client_t *client) { ...@@ -3516,7 +3512,7 @@ client_accept(ns_client_t *client) {
* listening for connections itself to prevent the interface * listening for connections itself to prevent the interface
* going dead. * going dead.
*/ */
isc_atomic_xadd(&client->interface->ntcpaccepting, 1); isc_refcount_increment0(&client->interface->ntcpaccepting, NULL);
} }
static void static void
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <isc/magic.h> #include <isc/magic.h>
#include <isc/mem.h> #include <isc/mem.h>
#include <isc/socket.h> #include <isc/socket.h>
#include <isc/refcount.h>
#include <dns/geoip.h> #include <dns/geoip.h>
#include <dns/result.h> #include <dns/result.h>
...@@ -76,11 +77,11 @@ struct ns_interface { ...@@ -76,11 +77,11 @@ struct ns_interface {
/*%< UDP dispatchers. */ /*%< UDP dispatchers. */
isc_socket_t * tcpsocket; /*%< TCP socket. */ isc_socket_t * tcpsocket; /*%< TCP socket. */
isc_dscp_t dscp; /*%< "listen-on" DSCP value */ isc_dscp_t dscp; /*%< "listen-on" DSCP value */
int32_t ntcpaccepting; /*%< Number of clients isc_refcount_t ntcpaccepting; /*%< Number of clients
ready to accept new ready to accept new
TCP connections on this TCP connections on this
interface */ interface */
int32_t ntcpactive; /*%< Number of clients isc_refcount_t ntcpactive; /*%< Number of clients
servicing TCP queries servicing TCP queries
(whether accepting or (whether accepting or
connected) */ connected) */
......
...@@ -429,8 +429,8 @@ ns_interface_create(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr, ...@@ -429,8 +429,8 @@ ns_interface_create(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr,
* connections will be handled in parallel even though there is * connections will be handled in parallel even though there is
* only one client initially. * only one client initially.
*/ */
ifp->ntcpaccepting = 0; isc_refcount_init(&ifp->ntcpaccepting, 0);
ifp->ntcpactive = 0; isc_refcount_init(&ifp->ntcpactive, 0);
ifp->nudpdispatch = 0; ifp->nudpdispatch = 0;
...@@ -663,6 +663,9 @@ ns_interface_destroy(ns_interface_t *ifp) { ...@@ -663,6 +663,9 @@ ns_interface_destroy(ns_interface_t *ifp) {
ns_interfacemgr_detach(&ifp->mgr); ns_interfacemgr_detach(&ifp->mgr);
isc_refcount_destroy(&ifp->ntcpactive);
isc_refcount_destroy(&ifp->ntcpaccepting);
ifp->magic = 0; ifp->magic = 0;
isc_mem_put(mctx, ifp, sizeof(*ifp)); isc_mem_put(mctx, ifp, sizeof(*ifp));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment