2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-04 08:35:31 +00:00

Make client reference counts work the same way as all

other reference counts: replace ns_client_wait() and
ns_client_unwait() by ns_client_attach() and ns_client_detach(),
respectively
This commit is contained in:
Andreas Gustafsson
2000-02-11 20:56:19 +00:00
parent b599cfd793
commit ae0bc2f30e
4 changed files with 35 additions and 29 deletions

View File

@@ -273,8 +273,8 @@ exit_check(ns_client_t *client) {
* *
* - The resolver will not shut down until the view refcount is zero * - The resolver will not shut down until the view refcount is zero
* - The view refcount does not go to zero until all clients detach * - The view refcount does not go to zero until all clients detach
* - The client does not detach from the view until nwaiting is zero * - The client does not detach from the view until references is zero
* - nwaiting does not go to zero until the resolver has shut down * - references does not go to zero until the resolver has shut down
* *
*/ */
if (client->newstate == NS_CLIENTSTATE_FREED && client->view != NULL) if (client->newstate == NS_CLIENTSTATE_FREED && client->view != NULL)
@@ -295,7 +295,7 @@ exit_check(ns_client_t *client) {
isc_socket_cancel(socket, client->task, isc_socket_cancel(socket, client->task,
ISC_SOCKCANCEL_SEND); ISC_SOCKCANCEL_SEND);
} }
if (! (client->nsends == 0 && client->nwaiting == 0)) { if (! (client->nsends == 0 && client->references == 0)) {
/* /*
* Still waiting for I/O cancel completion. * Still waiting for I/O cancel completion.
* or lingering references. * or lingering references.
@@ -1045,7 +1045,7 @@ client_create(ns_clientmgr_t *manager, ns_client_t **clientp)
client->naccepts = 0; client->naccepts = 0;
client->nreads = 0; client->nreads = 0;
client->nsends = 0; client->nsends = 0;
client->nwaiting = 0; client->references = 0;
client->attributes = 0; client->attributes = 0;
client->view = NULL; client->view = NULL;
client->lockview = NULL; client->lockview = NULL;
@@ -1236,8 +1236,20 @@ client_accept(ns_client_t *client) {
} }
void void
ns_client_wait(ns_client_t *client) { ns_client_attach(ns_client_t *source, ns_client_t **targetp) {
client->nwaiting++; REQUIRE(NS_CLIENT_VALID(source));
REQUIRE(targetp != NULL && *targetp == NULL);
source->references++;
*targetp = source;
}
void
ns_client_detach(ns_client_t **clientp) {
ns_client_t *client = *clientp;
client->references--;
INSIST(client->references >= 0);
*clientp = NULL;
(void) exit_check(client);
} }
isc_boolean_t isc_boolean_t
@@ -1245,13 +1257,6 @@ ns_client_shuttingdown(ns_client_t *client) {
return (client->newstate == NS_CLIENTSTATE_FREED); return (client->newstate == NS_CLIENTSTATE_FREED);
} }
void
ns_client_unwait(ns_client_t *client) {
client->nwaiting--;
INSIST(client->nwaiting >= 0);
(void) exit_check(client);
}
isc_result_t isc_result_t
ns_client_replace(ns_client_t *client) { ns_client_replace(ns_client_t *client) {
isc_result_t result; isc_result_t result;

View File

@@ -88,7 +88,7 @@ struct ns_client {
int naccepts; int naccepts;
int nreads; int nreads;
int nsends; int nsends;
int nwaiting; int references;
unsigned int attributes; unsigned int attributes;
isc_task_t * task; isc_task_t * task;
dns_view_t * view; dns_view_t * view;
@@ -167,16 +167,15 @@ ns_client_shuttingdown(ns_client_t *client);
*/ */
void void
ns_client_wait(ns_client_t *client); ns_client_attach(ns_client_t *source, ns_client_t **target);
/* /*
* Increment reference count. The client object will * Attach '*targetp' to 'source'.
* not be destroyed while the reference count is nonzero.
*/ */
void void
ns_client_unwait(ns_client_t *client); ns_client_detach(ns_client_t **clientp);
/* /*
* Decrement reference count. * Detach '*clientp' from its client.
*/ */
isc_result_t isc_result_t

View File

@@ -1679,7 +1679,7 @@ query_resume(isc_task_t *task, isc_event_t *event) {
isc_event_free(&event); isc_event_free(&event);
ns_client_next(client, ISC_R_CANCELED); ns_client_next(client, ISC_R_CANCELED);
/* This may destroy the client. */ /* This may destroy the client. */
ns_client_unwait(client); ns_client_detach(&client);
} else { } else {
RWLOCK(&ns_g_server->conflock, isc_rwlocktype_read); RWLOCK(&ns_g_server->conflock, isc_rwlocktype_read);
dns_zonemgr_lockconf(ns_g_server->zonemgr, isc_rwlocktype_read); dns_zonemgr_lockconf(ns_g_server->zonemgr, isc_rwlocktype_read);
@@ -2597,7 +2597,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
if (eresult != ISC_R_SUCCESS && !PARTIALANSWER(client)) { if (eresult != ISC_R_SUCCESS && !PARTIALANSWER(client)) {
ns_client_error(client, eresult); ns_client_error(client, eresult);
ns_client_unwait(client); ns_client_detach(&client);
} else if (!RECURSING(client)) { } else if (!RECURSING(client)) {
/* /*
* We are done. Make a final tweak to the AA bit if the * We are done. Make a final tweak to the AA bit if the
@@ -2609,7 +2609,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
client->message->flags |= DNS_MESSAGEFLAG_AA; client->message->flags |= DNS_MESSAGEFLAG_AA;
ns_client_send(client); ns_client_send(client);
ns_client_unwait(client); ns_client_detach(&client);
} }
CTRACE("query_find: done"); CTRACE("query_find: done");
} }
@@ -2672,7 +2672,8 @@ ns_query_start(ns_client_t *client) {
dns_message_t *message = client->message; dns_message_t *message = client->message;
dns_rdataset_t *rdataset; dns_rdataset_t *rdataset;
isc_boolean_t set_ra = ISC_TRUE; isc_boolean_t set_ra = ISC_TRUE;
ns_client_t *qclient;
CTRACE("ns_query_start"); CTRACE("ns_query_start");
/* /*
@@ -2802,6 +2803,7 @@ ns_query_start(ns_client_t *client) {
*/ */
message->flags |= DNS_MESSAGEFLAG_AD; message->flags |= DNS_MESSAGEFLAG_AD;
ns_client_wait(client); qclient = NULL;
query_find(client, NULL); ns_client_attach(client, &qclient);
query_find(qclient, NULL);
} }

View File

@@ -15,7 +15,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
/* $Id: xfrout.c,v 1.42 2000/02/09 22:58:45 gson Exp $ */ /* $Id: xfrout.c,v 1.43 2000/02/11 20:56:18 gson Exp $ */
#include <config.h> #include <config.h>
@@ -1052,8 +1052,8 @@ xfrout_ctx_create(isc_mem_t *mctx, ns_client_t *client, unsigned int id,
if (xfr == NULL) if (xfr == NULL)
return (DNS_R_NOMEMORY); return (DNS_R_NOMEMORY);
xfr->mctx = mctx; xfr->mctx = mctx;
xfr->client = client; xfr->client = NULL;
ns_client_wait(client); ns_client_attach(client, &xfr->client);
xfr->id = id; xfr->id = id;
xfr->qname = qname; xfr->qname = qname;
xfr->qtype = qtype; xfr->qtype = qtype;
@@ -1397,7 +1397,7 @@ xfrout_ctx_destroy(xfrout_ctx_t **xfrp) {
if (xfr->db != NULL) if (xfr->db != NULL)
dns_db_detach(&xfr->db); dns_db_detach(&xfr->db);
ns_client_unwait(xfr->client); ns_client_detach(&xfr->client);
isc_mem_put(xfr->mctx, xfr, sizeof(*xfr)); isc_mem_put(xfr->mctx, xfr, sizeof(*xfr));