struct zt_load_params *loadparams;
/* Locked by lock. */
bool flush;
- uint32_t references;
+ isc_refcount_t references;
unsigned int loads_pending;
dns_rbt_t *table;
};
zt->mctx = NULL;
isc_mem_attach(mctx, &zt->mctx);
- zt->references = 1;
+ isc_refcount_init(&zt->references, 1);
zt->flush = false;
zt->rdclass = rdclass;
zt->magic = ZTMAGIC;
REQUIRE(VALID_ZT(zt));
REQUIRE(ztp != NULL && *ztp == NULL);
- RWLOCK(&zt->rwlock, isc_rwlocktype_write);
-
- INSIST(zt->references > 0);
- zt->references++;
- INSIST(zt->references != 0);
-
- RWUNLOCK(&zt->rwlock, isc_rwlocktype_write);
-
+ isc_refcount_increment(&zt->references);
+
*ztp = zt;
}
REQUIRE(ztp != NULL && VALID_ZT(*ztp));
zt = *ztp;
-
- RWLOCK(&zt->rwlock, isc_rwlocktype_write);
-
- INSIST(zt->references > 0);
- zt->references--;
- if (zt->references == 0)
- destroy = true;
- if (need_flush)
- zt->flush = true;
-
- RWUNLOCK(&zt->rwlock, isc_rwlocktype_write);
-
- if (destroy)
+ if (isc_refcount_decrement(&zt->references) == 1) {
zt_destroy(zt);
+ }
*ztp = NULL;
}
isc_result_t result;
struct dns_zt *zt = (dns_zt_t*) zt_;
REQUIRE(zone != NULL);
- INSIST(zt->references > 0);
- zt->references++;
+ isc_refcount_increment(&zt->references);
zt->loads_pending++;
result = dns_zone_asyncload(zone, zt->loadparams->newonly, *zt->loadparams->dl, zt);
if (result != ISC_R_SUCCESS) {
- zt->references--;
+ isc_refcount_decrement(&zt->references);
zt->loads_pending--;
- INSIST(zt->references > 0);
}
return (ISC_R_SUCCESS);
}
RWLOCK(&zt->rwlock, isc_rwlocktype_write);
INSIST(zt->loads_pending != 0);
- INSIST(zt->references != 0);
- zt->references--;
- if (zt->references == 0)
+ if (isc_refcount_decrement(&zt->references) == 1)
destroy = true;
zt->loads_pending--;
if (zt->loads_pending == 0) {