2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-03 08:05:21 +00:00

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

(cherry picked from commit ef49780d30)
This commit is contained in:
Ondřej Surý
2019-04-17 15:22:27 +02:00
parent bb258967c3
commit e203d4d65a
3 changed files with 14 additions and 10 deletions

View File

@@ -423,11 +423,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;
}
@@ -575,7 +575,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;
@@ -3327,7 +3327,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);
/*
@@ -3457,7 +3457,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;
@@ -3516,7 +3516,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

View 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) */

View File

@@ -425,8 +425,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;
@@ -659,6 +659,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));
}