mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +00:00
dns/zt.c: use isc_refcount_t for reference counting
This commit is contained in:
40
lib/dns/zt.c
40
lib/dns/zt.c
@@ -45,9 +45,9 @@ struct dns_zt {
|
|||||||
dns_zt_allloaded_t loaddone;
|
dns_zt_allloaded_t loaddone;
|
||||||
void * loaddone_arg;
|
void * loaddone_arg;
|
||||||
struct zt_load_params *loadparams;
|
struct zt_load_params *loadparams;
|
||||||
|
isc_refcount_t references;
|
||||||
/* Locked by lock. */
|
/* Locked by lock. */
|
||||||
bool flush;
|
bool flush;
|
||||||
uint32_t references;
|
|
||||||
unsigned int loads_pending;
|
unsigned int loads_pending;
|
||||||
dns_rbt_t *table;
|
dns_rbt_t *table;
|
||||||
};
|
};
|
||||||
@@ -93,7 +93,7 @@ dns_zt_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, dns_zt_t **ztp) {
|
|||||||
|
|
||||||
zt->mctx = NULL;
|
zt->mctx = NULL;
|
||||||
isc_mem_attach(mctx, &zt->mctx);
|
isc_mem_attach(mctx, &zt->mctx);
|
||||||
zt->references = 1;
|
isc_refcount_init(&zt->references, 1);
|
||||||
zt->flush = false;
|
zt->flush = false;
|
||||||
zt->rdclass = rdclass;
|
zt->rdclass = rdclass;
|
||||||
zt->magic = ZTMAGIC;
|
zt->magic = ZTMAGIC;
|
||||||
@@ -209,13 +209,7 @@ dns_zt_attach(dns_zt_t *zt, dns_zt_t **ztp) {
|
|||||||
REQUIRE(VALID_ZT(zt));
|
REQUIRE(VALID_ZT(zt));
|
||||||
REQUIRE(ztp != NULL && *ztp == NULL);
|
REQUIRE(ztp != NULL && *ztp == NULL);
|
||||||
|
|
||||||
RWLOCK(&zt->rwlock, isc_rwlocktype_write);
|
isc_refcount_increment(&zt->references);
|
||||||
|
|
||||||
INSIST(zt->references > 0);
|
|
||||||
zt->references++;
|
|
||||||
INSIST(zt->references != 0);
|
|
||||||
|
|
||||||
RWUNLOCK(&zt->rwlock, isc_rwlocktype_write);
|
|
||||||
|
|
||||||
*ztp = zt;
|
*ztp = zt;
|
||||||
}
|
}
|
||||||
@@ -238,26 +232,17 @@ zt_destroy(dns_zt_t *zt) {
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
zt_flushanddetach(dns_zt_t **ztp, bool need_flush) {
|
zt_flushanddetach(dns_zt_t **ztp, bool need_flush) {
|
||||||
bool destroy = false;
|
|
||||||
dns_zt_t *zt;
|
dns_zt_t *zt;
|
||||||
|
|
||||||
REQUIRE(ztp != NULL && VALID_ZT(*ztp));
|
REQUIRE(ztp != NULL && VALID_ZT(*ztp));
|
||||||
|
|
||||||
zt = *ztp;
|
zt = *ztp;
|
||||||
|
if (need_flush) {
|
||||||
RWLOCK(&zt->rwlock, isc_rwlocktype_write);
|
|
||||||
|
|
||||||
INSIST(zt->references > 0);
|
|
||||||
zt->references--;
|
|
||||||
if (zt->references == 0)
|
|
||||||
destroy = true;
|
|
||||||
if (need_flush)
|
|
||||||
zt->flush = true;
|
zt->flush = true;
|
||||||
|
}
|
||||||
RWUNLOCK(&zt->rwlock, isc_rwlocktype_write);
|
if (isc_refcount_decrement(&zt->references) == 1) {
|
||||||
|
|
||||||
if (destroy)
|
|
||||||
zt_destroy(zt);
|
zt_destroy(zt);
|
||||||
|
}
|
||||||
|
|
||||||
*ztp = NULL;
|
*ztp = NULL;
|
||||||
}
|
}
|
||||||
@@ -340,15 +325,13 @@ asyncload(dns_zone_t *zone, void *zt_) {
|
|||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
struct dns_zt *zt = (dns_zt_t*) zt_;
|
struct dns_zt *zt = (dns_zt_t*) zt_;
|
||||||
REQUIRE(zone != NULL);
|
REQUIRE(zone != NULL);
|
||||||
INSIST(zt->references > 0);
|
INSIST(isc_refcount_increment(&zt->references) > 0);
|
||||||
zt->references++;
|
|
||||||
zt->loads_pending++;
|
zt->loads_pending++;
|
||||||
|
|
||||||
result = dns_zone_asyncload(zone, zt->loadparams->newonly, *zt->loadparams->dl, zt);
|
result = dns_zone_asyncload(zone, zt->loadparams->newonly, *zt->loadparams->dl, zt);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
zt->references--;
|
INSIST(isc_refcount_decrement(&zt->references) > 1);
|
||||||
zt->loads_pending--;
|
zt->loads_pending--;
|
||||||
INSIST(zt->references > 0);
|
|
||||||
}
|
}
|
||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
@@ -548,10 +531,9 @@ doneloading(dns_zt_t *zt, dns_zone_t *zone, isc_task_t *task) {
|
|||||||
|
|
||||||
RWLOCK(&zt->rwlock, isc_rwlocktype_write);
|
RWLOCK(&zt->rwlock, isc_rwlocktype_write);
|
||||||
INSIST(zt->loads_pending != 0);
|
INSIST(zt->loads_pending != 0);
|
||||||
INSIST(zt->references != 0);
|
if (isc_refcount_decrement(&zt->references) == 1) {
|
||||||
zt->references--;
|
|
||||||
if (zt->references == 0)
|
|
||||||
destroy = true;
|
destroy = true;
|
||||||
|
}
|
||||||
zt->loads_pending--;
|
zt->loads_pending--;
|
||||||
if (zt->loads_pending == 0) {
|
if (zt->loads_pending == 0) {
|
||||||
alldone = zt->loaddone;
|
alldone = zt->loaddone;
|
||||||
|
Reference in New Issue
Block a user