#include <dns/types.h>
#include <dns/zt.h>
+/* Define to 1 for detailed reference tracing */
+#undef DNS_ZONE_TRACE
+
typedef enum {
dns_zone_none,
dns_zone_primary,
* tests.)
*/
-void
-dns_zone_attach(dns_zone_t *source, dns_zone_t **target);
-/*%<
- * Attach '*target' to 'source' incrementing its external
- * reference count.
- *
- * Require:
- *\li 'zone' to be a valid zone.
- *\li 'target' to be non NULL and '*target' to be NULL.
- */
-
-void
-dns_zone_detach(dns_zone_t **zonep);
-/*%<
- * Detach from a zone decrementing its external reference count.
- * If this was the last external reference to the zone it will be
- * shut down and eventually freed.
- *
- * Require:
- *\li 'zonep' to point to a valid zone.
- */
-
void
dns_zone_iattach(dns_zone_t *source, dns_zone_t **target);
/*%<
* \li 'true' if the check passes, that is the zone remains consistent,
* 'false' if the zone would have NSEC only DNSKEYs and an NSEC3 chain.
*/
+
+#if DNS_ZONE_TRACE
+#define dns_zone_ref(ptr) dns_zone__ref(ptr, __func__, __FILE__, __LINE__)
+#define dns_zone_unref(ptr) dns_zone__unref(ptr, __func__, __FILE__, __LINE__)
+#define dns_zone_attach(ptr, ptrp) \
+ dns_zone__attach(ptr, ptrp, __func__, __FILE__, __LINE__)
+#define dns_zone_detach(ptrp) \
+ dns_zone__detach(ptrp, __func__, __FILE__, __LINE__)
+ISC_REFCOUNT_TRACE_DECL(dns_zone);
+#else
+ISC_REFCOUNT_DECL(dns_zone);
+#endif
bool locked;
#endif /* ifdef DNS_ZONE_CHECKLOCK */
isc_mem_t *mctx;
- isc_refcount_t erefs;
+ isc_refcount_t references;
isc_rwlock_t dblock;
dns_db_t *db; /* Locked by dblock */
isc_mutex_init(&zone->lock);
ZONEDB_INITLOCK(&zone->dblock);
- isc_refcount_init(&zone->erefs, 1);
+ isc_refcount_init(&zone->references, 1);
isc_refcount_init(&zone->irefs, 0);
dns_name_init(&zone->origin, NULL);
isc_sockaddr_any(&zone->notifysrc4);
return (ISC_R_SUCCESS);
free_refs:
- isc_refcount_decrement0(&zone->erefs);
- isc_refcount_destroy(&zone->erefs);
+ isc_refcount_decrement0(&zone->references);
+ isc_refcount_destroy(&zone->references);
isc_refcount_destroy(&zone->irefs);
ZONEDB_DESTROYLOCK(&zone->dblock);
isc_mutex_destroy(&zone->lock);
REQUIRE(zone->timer == NULL);
REQUIRE(zone->zmgr == NULL);
- isc_refcount_destroy(&zone->erefs);
+ isc_refcount_destroy(&zone->references);
isc_refcount_destroy(&zone->irefs);
/*
isc_refcount_current(&zone->irefs) == 0)
{
/*
- * DNS_ZONEFLG_SHUTDOWN can only be set if erefs == 0.
+ * DNS_ZONEFLG_SHUTDOWN can only be set if references == 0.
*/
- INSIST(isc_refcount_current(&zone->erefs) == 0);
+ INSIST(isc_refcount_current(&zone->references) == 0);
return (true);
}
return (false);
return (answer);
}
-void
-dns_zone_attach(dns_zone_t *source, dns_zone_t **target) {
- REQUIRE(DNS_ZONE_VALID(source));
- REQUIRE(target != NULL && *target == NULL);
- isc_refcount_increment(&source->erefs);
- *target = source;
-}
-
-void
-dns_zone_detach(dns_zone_t **zonep) {
- REQUIRE(zonep != NULL && DNS_ZONE_VALID(*zonep));
-
- dns_zone_t *zone = *zonep;
- *zonep = NULL;
-
- if (isc_refcount_decrement(&zone->erefs) == 1) {
- isc_refcount_destroy(&zone->erefs);
-
- /*
- * Stop things being restarted after we cancel them below.
- */
- DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_EXITING);
- dns_zone_log(zone, ISC_LOG_DEBUG(1),
- "final reference detached");
+static void
+zone_destroy(dns_zone_t *zone) {
+ isc_refcount_destroy(&zone->references);
- if (zone->loop != NULL) {
- /*
- * This zone has a loop; it can clean
- * itself up asynchronously.
- */
- isc_async_run(zone->loop, zone_shutdown, zone);
- return;
- }
+ /*
+ * Stop things being restarted after we cancel them below.
+ */
+ DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_EXITING);
+ dns_zone_log(zone, ISC_LOG_DEBUG(1), "final reference detached");
+ if (zone->loop == NULL) {
/*
* This zone is unmanaged; we're probably running in
* named-checkzone or a unit test. There's no loop, so we
INSIST(zone->view == NULL);
zone_shutdown(zone);
+ } else {
+ /*
+ * This zone has a loop; it can clean
+ * itself up asynchronously.
+ */
+ isc_async_run(zone->loop, zone_shutdown, zone);
}
}
+#if DNS_ZONE_TRACE
+ISC_REFCOUNT_TRACE_IMPL(dns_zone, zone_destroy);
+#else
+ISC_REFCOUNT_IMPL(dns_zone, zone_destroy);
+#endif
+
void
dns_zone_iattach(dns_zone_t *source, dns_zone_t **target) {
REQUIRE(DNS_ZONE_VALID(source));
REQUIRE(LOCKED_ZONE(source));
REQUIRE(target != NULL && *target == NULL);
INSIST(isc_refcount_increment0(&source->irefs) +
- isc_refcount_current(&source->erefs) >
+ isc_refcount_current(&source->references) >
0);
*target = source;
}
*zonep = NULL;
INSIST(isc_refcount_decrement(&zone->irefs) - 1 +
- isc_refcount_current(&zone->erefs) >
+ isc_refcount_current(&zone->references) >
0);
}
dns_view_t *view = NULL, *prev_view = NULL;
REQUIRE(DNS_ZONE_VALID(zone));
- INSIST(isc_refcount_current(&zone->erefs) == 0);
+ INSIST(isc_refcount_current(&zone->references) == 0);
zone_debuglog(zone, __func__, 3, "shutting down");
raw->loop = zone->loop;
/* dns_zone_attach(raw, &zone->raw); */
- isc_refcount_increment(&raw->erefs);
+ isc_refcount_increment(&raw->references);
zone->raw = raw;
/* dns_zone_iattach(zone, &raw->secure); */