From 21eaa048582b19d3fe7a2c9f9b3455256dbae77b Mon Sep 17 00:00:00 2001 From: Andreas Gustafsson Date: Thu, 15 Jun 2000 16:11:50 +0000 Subject: [PATCH] added dns_zonemgr_attach(); also changed comments for other attach() functions to consistently say that the new reference attaches to the object, not vice versa --- lib/dns/include/dns/zone.h | 21 ++++++++++++++++----- lib/dns/zone.c | 17 +++++++++++++++-- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/lib/dns/include/dns/zone.h b/lib/dns/include/dns/zone.h index 5abbc1ad7d..0f6c2b5a49 100644 --- a/lib/dns/include/dns/zone.h +++ b/lib/dns/include/dns/zone.h @@ -51,7 +51,7 @@ ISC_LANG_BEGINDECLS isc_result_t dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx); /* - * Creates a new empty zone and attach to it. + * Creates a new empty zone and attach '*zonep' to it. * * Requires: * 'zonep' to point to a NULL pointer. @@ -178,7 +178,7 @@ dns_zone_load(dns_zone_t *zone); void dns_zone_attach(dns_zone_t *source, dns_zone_t **target); /* - * Attach 'zone' to 'target' incrementing its external + * Attach '*target' to 'source' incrementing its external * reference count. * * Require: @@ -200,7 +200,7 @@ dns_zone_detach(dns_zone_t **zonep); void dns_zone_iattach(dns_zone_t *source, dns_zone_t **target); /* - * Attach 'zone' to 'target' incrementing its internal + * Attach '*target' to 'source' incrementing its internal * reference count. This is intended for use by operations * such as zone transfers that need to prevent the zone * object from being freed but not from shutting down. @@ -260,7 +260,7 @@ dns_zone_cleardbargs(dns_zone_t *zone); isc_result_t dns_zone_getdb(dns_zone_t *zone, dns_db_t **dbp); /* - * Attach the database to '*dbp' if it exists otherwise + * Attach '*dbp' to the database to if it exists otherwise * return DNS_R_NOTLOADED. * * Require: @@ -715,7 +715,7 @@ dns_zone_settask(dns_zone_t *zone, isc_task_t *task); void dns_zone_gettask(dns_zone_t *zone, isc_task_t **target); /* - * Attach the zone's task to '*target'. + * Attach '*target' to the zone's task. * * Requires: * 'zone' to be valid initialised zone. @@ -918,6 +918,17 @@ dns_zonemgr_shutdown(dns_zonemgr_t *zmgr); * 'zmgr' to be a valid zone manager. */ +void +dns_zonemgr_attach(dns_zonemgr_t *source, dns_zonemgr_t **target); +/* + * Attach '*target' to 'source' incrementing its external + * reference count. + * + * Require: + * 'zone' to be a valid zone. + * 'target' to be non NULL and '*target' to be NULL. + */ + void dns_zonemgr_detach(dns_zonemgr_t **zmgrp); /* diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 04628764f7..d0ac141277 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: zone.c,v 1.146 2000/06/15 02:45:47 marka Exp $ */ +/* $Id: zone.c,v 1.147 2000/06/15 16:11:49 gson Exp $ */ #include @@ -184,7 +184,7 @@ struct dns_zone { struct dns_zonemgr { unsigned int magic; isc_mem_t * mctx; - int refs; + int refs; /* Locked by rwlock */ isc_taskmgr_t * taskmgr; isc_timermgr_t * timermgr; isc_socketmgr_t * socketmgr; @@ -4097,6 +4097,19 @@ dns_zonemgr_releasezone(dns_zonemgr_t *zmgr, dns_zone_t *zone) { ENSURE(zone->zmgr == NULL); } +void +dns_zonemgr_attach(dns_zonemgr_t *source, dns_zonemgr_t **target) { + REQUIRE(DNS_ZONEMGR_VALID(source)); + REQUIRE(target != NULL && *target == NULL); + + RWLOCK(&source->rwlock, isc_rwlocktype_write); + REQUIRE(source->refs > 0); + source->refs++; + INSIST(source->refs > 0); + RWUNLOCK(&source->rwlock, isc_rwlocktype_write); + *target = source; +} + void dns_zonemgr_detach(dns_zonemgr_t **zmgrp) { dns_zonemgr_t *zmgr;