view->frozen = false;
view->task = NULL;
isc_refcount_init(&view->references, 1);
- view->weakrefs = 0;
+ isc_refcount_init(&view->weakrefs, 0);
view->attributes = (DNS_VIEWATTR_RESSHUTDOWN|DNS_VIEWATTR_ADBSHUTDOWN|
DNS_VIEWATTR_REQSHUTDOWN);
view->statickeys = NULL;
view->matchrecursiveonly = false;
result = dns_tsigkeyring_create(view->mctx, &view->dynamickeys);
if (result != ISC_R_SUCCESS)
- goto cleanup_references;
+ goto cleanup_weakrefs;
view->peers = NULL;
view->order = NULL;
view->delonly = NULL;
dns_tsigkeyring_detach(&view->dynamickeys);
}
- cleanup_references:
- INSIST(isc_refcount_decrement(&view->references) > 0);
+ cleanup_weakrefs:
+ isc_refcount_destroy(&view->weakrefs);
+
+ isc_refcount_decrement(&view->references);
isc_refcount_destroy(&view->references);
if (view->fwdtable != NULL) {
dns_dlzdb_t *dlzdb;
REQUIRE(!ISC_LINK_LINKED(view, link));
- REQUIRE(isc_refcount_current(&view->references) == 0);
- REQUIRE(view->weakrefs == 0);
REQUIRE(RESSHUTDOWN(view));
REQUIRE(ADBSHUTDOWN(view));
REQUIRE(REQSHUTDOWN(view));
+ isc_refcount_destroy(&view->references);
+ isc_refcount_destroy(&view->weakrefs);
+
if (view->order != NULL)
dns_order_detach(&view->order);
if (view->peers != NULL)
dns_badcache_destroy(&view->failcache);
isc_mutex_destroy(&view->new_zone_lock);
isc_mutex_destroy(&view->lock);
+ isc_refcount_destroy(&view->references);
+ isc_refcount_destroy(&view->weakrefs);
isc_mem_free(view->mctx, view->nta_file);
isc_mem_free(view->mctx, view->name);
if (view->hooktable != NULL && view->hooktable_free != NULL) {
all_done(dns_view_t *view) {
if (isc_refcount_current(&view->references) == 0 &&
- view->weakrefs == 0 &&
+ isc_refcount_current(&view->weakrefs) == 0 &&
RESSHUTDOWN(view) && ADBSHUTDOWN(view) && REQSHUTDOWN(view))
+ {
return (true);
+ }
return (false);
}
REQUIRE(DNS_VIEW_VALID(source));
REQUIRE(targetp != NULL && *targetp == NULL);
- LOCK(&source->lock);
- source->weakrefs++;
- UNLOCK(&source->lock);
+ isc_refcount_increment0(&source->weakrefs);
*targetp = source;
}
void
dns_view_weakdetach(dns_view_t **viewp) {
dns_view_t *view;
- bool done = false;
REQUIRE(viewp != NULL);
view = *viewp;
REQUIRE(DNS_VIEW_VALID(view));
-
- LOCK(&view->lock);
-
- INSIST(view->weakrefs > 0);
- view->weakrefs--;
- done = all_done(view);
-
- UNLOCK(&view->lock);
-
*viewp = NULL;
- if (done)
- destroy(view);
+ if (isc_refcount_decrement(&view->weakrefs) == 1) {
+ bool done = false;
+ LOCK(&view->lock);
+ done = all_done(view);
+ UNLOCK(&view->lock);
+ if (done) {
+ destroy(view);
+ }
+ }
}
static void