|
|
4b42a5 |
From ef49780d30d3ddc5735cfc32561b678a634fa72f Mon Sep 17 00:00:00 2001
|
|
|
4b42a5 |
From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= <ondrej@sury.org>
|
|
|
4b42a5 |
Date: Wed, 17 Apr 2019 15:22:27 +0200
|
|
|
4b42a5 |
Subject: [PATCH] Replace atomic operations in bin/named/client.c with
|
|
|
4b42a5 |
isc_refcount reference counting
|
|
|
4b42a5 |
|
|
|
4b42a5 |
---
|
|
|
4b42a5 |
bin/named/client.c | 18 +++++++-----------
|
|
|
4b42a5 |
bin/named/include/named/interfacemgr.h | 5 +++--
|
|
|
4b42a5 |
bin/named/interfacemgr.c | 7 +++++--
|
|
|
4b42a5 |
3 files changed, 15 insertions(+), 15 deletions(-)
|
|
|
4b42a5 |
|
|
|
4b42a5 |
diff --git a/bin/named/client.c b/bin/named/client.c
|
|
|
4b42a5 |
index 845326abc0..29fecadca8 100644
|
|
|
4b42a5 |
--- a/bin/named/client.c
|
|
|
4b42a5 |
+++ b/bin/named/client.c
|
|
|
4b42a5 |
@@ -402,12 +402,10 @@ tcpconn_detach(ns_client_t *client) {
|
|
|
4b42a5 |
static void
|
|
|
4b42a5 |
mark_tcp_active(ns_client_t *client, bool active) {
|
|
|
4b42a5 |
if (active && !client->tcpactive) {
|
|
|
4b42a5 |
- isc_atomic_xadd(&client->interface->ntcpactive, 1);
|
|
|
4b42a5 |
+ isc_refcount_increment0(&client->interface->ntcpactive, NULL);
|
|
|
4b42a5 |
client->tcpactive = active;
|
|
|
4b42a5 |
} else if (!active && client->tcpactive) {
|
|
|
4b42a5 |
- uint32_t old =
|
|
|
4b42a5 |
- isc_atomic_xadd(&client->interface->ntcpactive, -1);
|
|
|
4b42a5 |
- INSIST(old > 0);
|
|
|
4b42a5 |
+ isc_refcount_decrement(&client->interface->ntcpactive, NULL);
|
|
|
4b42a5 |
client->tcpactive = active;
|
|
|
4b42a5 |
}
|
|
|
4b42a5 |
}
|
|
|
4b42a5 |
@@ -554,7 +552,7 @@ exit_check(ns_client_t *client) {
|
|
|
4b42a5 |
if (client->mortal && TCP_CLIENT(client) &&
|
|
|
4b42a5 |
client->newstate != NS_CLIENTSTATE_FREED &&
|
|
|
4b42a5 |
!ns_g_clienttest &&
|
|
|
4b42a5 |
- isc_atomic_xadd(&client->interface->ntcpaccepting, 0) == 0)
|
|
|
4b42a5 |
+ isc_refcount_current(&client->interface->ntcpaccepting) == 0)
|
|
|
4b42a5 |
{
|
|
|
4b42a5 |
/* Nobody else is accepting */
|
|
|
4b42a5 |
client->mortal = false;
|
|
|
4b42a5 |
@@ -3328,7 +3326,6 @@ client_newconn(isc_task_t *task, isc_event_t *event) {
|
|
|
4b42a5 |
isc_result_t result;
|
|
|
4b42a5 |
ns_client_t *client = event->ev_arg;
|
|
|
4b42a5 |
isc_socket_newconnev_t *nevent = (isc_socket_newconnev_t *)event;
|
|
|
4b42a5 |
- uint32_t old;
|
|
|
4b42a5 |
|
|
|
4b42a5 |
REQUIRE(event->ev_type == ISC_SOCKEVENT_NEWCONN);
|
|
|
4b42a5 |
REQUIRE(NS_CLIENT_VALID(client));
|
|
|
4b42a5 |
@@ -3348,8 +3345,7 @@ client_newconn(isc_task_t *task, isc_event_t *event) {
|
|
|
4b42a5 |
INSIST(client->naccepts == 1);
|
|
|
4b42a5 |
client->naccepts--;
|
|
|
4b42a5 |
|
|
|
4b42a5 |
- old = isc_atomic_xadd(&client->interface->ntcpaccepting, -1);
|
|
|
4b42a5 |
- INSIST(old > 0);
|
|
|
4b42a5 |
+ isc_refcount_decrement(&client->interface->ntcpaccepting, NULL);
|
|
|
4b42a5 |
|
|
|
4b42a5 |
/*
|
|
|
4b42a5 |
* We must take ownership of the new socket before the exit
|
|
|
4b42a5 |
@@ -3480,8 +3476,8 @@ client_accept(ns_client_t *client) {
|
|
|
4b42a5 |
* quota is tcp-clients plus the number of listening
|
|
|
4b42a5 |
* interfaces plus 1.)
|
|
|
4b42a5 |
*/
|
|
|
4b42a5 |
- exit = (isc_atomic_xadd(&client->interface->ntcpactive, 0) >
|
|
|
4b42a5 |
- (client->tcpactive ? 1 : 0));
|
|
|
4b42a5 |
+ exit = (isc_refcount_current(&client->interface->ntcpactive) >
|
|
|
4b42a5 |
+ (client->tcpactive ? 1U : 0U));
|
|
|
4b42a5 |
if (exit) {
|
|
|
4b42a5 |
client->newstate = NS_CLIENTSTATE_INACTIVE;
|
|
|
4b42a5 |
(void)exit_check(client);
|
|
|
4b42a5 |
@@ -3539,7 +3535,7 @@ client_accept(ns_client_t *client) {
|
|
|
4b42a5 |
* listening for connections itself to prevent the interface
|
|
|
4b42a5 |
* going dead.
|
|
|
4b42a5 |
*/
|
|
|
4b42a5 |
- isc_atomic_xadd(&client->interface->ntcpaccepting, 1);
|
|
|
4b42a5 |
+ isc_refcount_increment0(&client->interface->ntcpaccepting, NULL);
|
|
|
4b42a5 |
}
|
|
|
4b42a5 |
|
|
|
4b42a5 |
static void
|
|
|
4b42a5 |
diff --git a/bin/named/include/named/interfacemgr.h b/bin/named/include/named/interfacemgr.h
|
|
|
4b42a5 |
index 3535ef22a8..6e10f210fd 100644
|
|
|
4b42a5 |
--- a/bin/named/include/named/interfacemgr.h
|
|
|
4b42a5 |
+++ b/bin/named/include/named/interfacemgr.h
|
|
|
4b42a5 |
@@ -45,6 +45,7 @@
|
|
|
4b42a5 |
#include <isc/magic.h>
|
|
|
4b42a5 |
#include <isc/mem.h>
|
|
|
4b42a5 |
#include <isc/socket.h>
|
|
|
4b42a5 |
+#include <isc/refcount.h>
|
|
|
4b42a5 |
|
|
|
4b42a5 |
#include <dns/result.h>
|
|
|
4b42a5 |
|
|
|
4b42a5 |
@@ -75,11 +76,11 @@ struct ns_interface {
|
|
|
4b42a5 |
/*%< UDP dispatchers. */
|
|
|
4b42a5 |
isc_socket_t * tcpsocket; /*%< TCP socket. */
|
|
|
4b42a5 |
isc_dscp_t dscp; /*%< "listen-on" DSCP value */
|
|
|
4b42a5 |
- int32_t ntcpaccepting; /*%< Number of clients
|
|
|
4b42a5 |
+ isc_refcount_t ntcpaccepting; /*%< Number of clients
|
|
|
4b42a5 |
ready to accept new
|
|
|
4b42a5 |
TCP connections on this
|
|
|
4b42a5 |
interface */
|
|
|
4b42a5 |
- int32_t ntcpactive; /*%< Number of clients
|
|
|
4b42a5 |
+ isc_refcount_t ntcpactive; /*%< Number of clients
|
|
|
4b42a5 |
servicing TCP queries
|
|
|
4b42a5 |
(whether accepting or
|
|
|
4b42a5 |
connected) */
|
|
|
4b42a5 |
diff --git a/bin/named/interfacemgr.c b/bin/named/interfacemgr.c
|
|
|
4b42a5 |
index d9f6df5802..135533be6b 100644
|
|
|
4b42a5 |
--- a/bin/named/interfacemgr.c
|
|
|
4b42a5 |
+++ b/bin/named/interfacemgr.c
|
|
|
4b42a5 |
@@ -386,8 +386,8 @@ ns_interface_create(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr,
|
|
|
4b42a5 |
* connections will be handled in parallel even though there is
|
|
|
4b42a5 |
* only one client initially.
|
|
|
4b42a5 |
*/
|
|
|
4b42a5 |
- ifp->ntcpaccepting = 0;
|
|
|
4b42a5 |
- ifp->ntcpactive = 0;
|
|
|
4b42a5 |
+ isc_refcount_init(&ifp->ntcpaccepting, 0);
|
|
|
4b42a5 |
+ isc_refcount_init(&ifp->ntcpactive, 0);
|
|
|
4b42a5 |
|
|
|
4b42a5 |
ifp->nudpdispatch = 0;
|
|
|
4b42a5 |
|
|
|
4b42a5 |
@@ -618,6 +618,9 @@ ns_interface_destroy(ns_interface_t *ifp) {
|
|
|
4b42a5 |
|
|
|
4b42a5 |
ns_interfacemgr_detach(&ifp->mgr);
|
|
|
4b42a5 |
|
|
|
4b42a5 |
+ isc_refcount_destroy(&ifp->ntcpactive);
|
|
|
4b42a5 |
+ isc_refcount_destroy(&ifp->ntcpaccepting);
|
|
|
4b42a5 |
+
|
|
|
4b42a5 |
ifp->magic = 0;
|
|
|
4b42a5 |
isc_mem_put(mctx, ifp, sizeof(*ifp));
|
|
|
4b42a5 |
}
|
|
|
4b42a5 |
--
|
|
|
4b42a5 |
2.18.1
|
|
|
4b42a5 |
|