ns_zoneload_t *zl = (ns_zoneload_t *) arg;
named_server_t *server = zl->server;
bool reconfig = zl->reconfig;
- unsigned int refs;
/*
* We use the zoneload reference counter to let us
* know when all views are finished.
*/
- isc_refcount_decrement(&zl->refs, &refs);
- if (refs != 0)
- return (ISC_R_SUCCESS);
+ if (isc_refcount_decrement(&zl->refs) == 1) {
- isc_refcount_destroy(&zl->refs);
- isc_mem_put(server->mctx, zl, sizeof (*zl));
+ isc_refcount_destroy(&zl->refs);
+ isc_mem_put(server->mctx, zl, sizeof (*zl));
- /*
- * To maintain compatibility with log parsing tools that might
- * be looking for this string after "rndc reconfig", we keep it
- * as it is
- */
- if (reconfig) {
- isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
- NAMED_LOGMODULE_SERVER, ISC_LOG_INFO,
- "any newly configured zones are now loaded");
- } else {
- isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
- NAMED_LOGMODULE_SERVER, ISC_LOG_NOTICE,
- "all zones loaded");
- }
+ /*
+ * To maintain compatibility with log parsing tools that might
+ * be looking for this string after "rndc reconfig", we keep it
+ * as it is
+ */
+ if (reconfig) {
+ isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
+ NAMED_LOGMODULE_SERVER, ISC_LOG_INFO,
+ "any newly configured zones are now loaded");
+ } else {
+ isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
+ NAMED_LOGMODULE_SERVER, ISC_LOG_NOTICE,
+ "all zones loaded");
+ }
- CHECKFATAL(dns_zonemgr_forcemaint(server->zonemgr),
- "forcing zone maintenance");
+ CHECKFATAL(dns_zonemgr_forcemaint(server->zonemgr),
+ "forcing zone maintenance");
- named_os_started();
- isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
- NAMED_LOGMODULE_SERVER, ISC_LOG_NOTICE, "running");
+ named_os_started();
+ isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
+ NAMED_LOGMODULE_SERVER, ISC_LOG_NOTICE, "running");
+ }
return (ISC_R_SUCCESS);
}
isc_result_t result;
dns_view_t *view;
ns_zoneload_t *zl;
- unsigned int refs = 0;
zl = isc_mem_get(server->mctx, sizeof (*zl));
if (zl == NULL)
* 'dns_view_asyncload' calls view_loaded if there are no
* zones.
*/
- isc_refcount_increment(&zl->refs, NULL);
+ isc_refcount_increment(&zl->refs);
CHECK(dns_view_asyncload(view, view_loaded, zl));
}
cleanup:
- isc_refcount_decrement(&zl->refs, &refs);
- if (refs == 0) {
+ if (isc_refcount_decrement(&zl->refs) == 1) {
isc_refcount_destroy(&zl->refs);
isc_mem_put(server->mctx, zl, sizeof (*zl));
} else if (init) {
REQUIRE(VALID_SAMPLEDB(sampledb));
- isc_refcount_increment(&sampledb->refs, NULL);
+ isc_refcount_increment(&sampledb->refs);
*targetp = source;
}
static void
detach(dns_db_t **dbp) {
sampledb_t *sampledb = (sampledb_t *)(*dbp);
- unsigned int refs;
REQUIRE(VALID_SAMPLEDB(sampledb));
- isc_refcount_decrement(&sampledb->refs, &refs);
- if (refs == 0)
+ if (isc_refcount_decrement(&sampledb->refs) == 1) {
free_sampledb(sampledb);
+ }
*dbp = NULL;
}
dns_acl_attach(dns_acl_t *source, dns_acl_t **target) {
REQUIRE(DNS_ACL_VALID(source));
- isc_refcount_increment(&source->refcount, NULL);
+ isc_refcount_increment(&source->refcount);
*target = source;
}
void
dns_acl_detach(dns_acl_t **aclp) {
dns_acl_t *acl = *aclp;
- unsigned int refs;
REQUIRE(DNS_ACL_VALID(acl));
- isc_refcount_decrement(&acl->refcount, &refs);
- if (refs == 0)
+ if (isc_refcount_decrement(&acl->refcount) == 1) {
destroy(acl);
+ }
+
*aclp = NULL;
}
void
dns_catz_entry_attach(dns_catz_entry_t *entry, dns_catz_entry_t **entryp) {
REQUIRE(entryp != NULL && *entryp == NULL);
- isc_refcount_increment(&entry->refs, NULL);
+ isc_refcount_increment(&entry->refs);
*entryp = entry;
}
dns_catz_entry_detach(dns_catz_zone_t *zone, dns_catz_entry_t **entryp) {
dns_catz_entry_t *entry;
isc_mem_t *mctx;
- unsigned int refs;
REQUIRE(entryp != NULL && *entryp != NULL);
entry = *entryp;
- *entryp = NULL;
mctx = zone->catzs->mctx;
- isc_refcount_decrement(&entry->refs, &refs);
- if (refs == 0) {
+ if (isc_refcount_decrement(&entry->refs) == 1) {
dns_catz_options_free(&entry->opts, mctx);
if (dns_name_dynamic(&entry->name))
dns_name_free(&entry->name, mctx);
isc_refcount_destroy(&entry->refs);
isc_mem_put(mctx, entry, sizeof(dns_catz_entry_t));
}
+
+ *entryp = NULL;
}
bool
dns_catz_catzs_attach(dns_catz_zones_t *catzs, dns_catz_zones_t **catzsp) {
REQUIRE(catzsp != NULL && *catzsp == NULL);
- isc_refcount_increment(&catzs->refs, NULL);
+ isc_refcount_increment(&catzs->refs);
*catzsp = catzs;
}
dns_catz_zone_attach(dns_catz_zone_t *zone, dns_catz_zone_t **zonep) {
REQUIRE(zonep != NULL && *zonep == NULL);
- isc_refcount_increment(&zone->refs, NULL);
+ isc_refcount_increment(&zone->refs);
*zonep = zone;
}
dns_catz_zone_t *zone;
isc_ht_iter_t *iter = NULL;
isc_mem_t *mctx;
- unsigned int refs;
REQUIRE(zonep != NULL && *zonep != NULL);
zone = *zonep;
- *zonep = NULL;
- isc_refcount_decrement(&zone->refs, &refs);
- if (refs == 0) {
+
+ if (isc_refcount_decrement(&zone->refs) == 1) {
+ isc_refcount_destroy(&zone->refs);
if (zone->entries != NULL) {
result = isc_ht_iter_create(zone->entries, &iter);
INSIST(result == ISC_R_SUCCESS);
}
mctx = zone->catzs->mctx;
isc_timer_detach(&zone->updatetimer);
- isc_refcount_destroy(&zone->refs);
if (zone->db_registered == true) {
result = dns_db_updatenotify_unregister(zone->db,
dns_catz_dbupdate_callback,
zone->catzs = NULL;
isc_mem_put(mctx, zone, sizeof(dns_catz_zone_t));
}
+
+ *zonep = NULL;
}
void
dns_catz_zones_t *catzs;
isc_ht_iter_t *iter = NULL;
isc_result_t result;
- unsigned int refs;
dns_catz_zone_t *zone;
REQUIRE(catzs != NULL);
*catzsp = NULL;
- isc_refcount_decrement(&catzs->refs, &refs);
-
- if (refs == 0) {
+ if (isc_refcount_decrement(&catzs->refs) == 1) {
+ isc_refcount_destroy(&catzs->refs);
DESTROYLOCK(&catzs->lock);
if (catzs->zones != NULL) {
result = isc_ht_iter_create(catzs->zones, &iter);
INSIST(isc_ht_count(catzs->zones) == 0);
isc_ht_destroy(&catzs->zones);
}
- isc_refcount_destroy(&catzs->refs);
isc_task_destroy(&catzs->updater);
isc_mem_putanddetach(&catzs->mctx, catzs, sizeof(*catzs));
}
REQUIRE(VALID_DTENV(source));
REQUIRE(destp != NULL && *destp == NULL);
- isc_refcount_increment(&source->refcount, NULL);
+ isc_refcount_increment(&source->refcount);
*destp = source;
}
void
dns_dt_detach(dns_dtenv_t **envp) {
- unsigned int refs;
dns_dtenv_t *env;
REQUIRE(envp != NULL && VALID_DTENV(*envp));
env = *envp;
- *envp = NULL;
- isc_refcount_decrement(&env->refcount, &refs);
- if (refs == 0)
+ if (isc_refcount_decrement(&env->refcount) == 1) {
destroy(env);
+ }
+
+ *envp = NULL;
}
static isc_result_t
REQUIRE(target != NULL && *target == NULL);
REQUIRE(VALID_KEY(source));
- isc_refcount_increment(&source->refs, NULL);
+ isc_refcount_increment(&source->refs);
*target = source;
}
dst_key_free(dst_key_t **keyp) {
isc_mem_t *mctx;
dst_key_t *key;
- unsigned int refs;
REQUIRE(dst_initialized == true);
REQUIRE(keyp != NULL && VALID_KEY(*keyp));
key = *keyp;
mctx = key->mctx;
- isc_refcount_decrement(&key->refs, &refs);
- if (refs != 0)
- return;
-
- isc_refcount_destroy(&key->refs);
- if (key->keydata.generic != NULL) {
- INSIST(key->func->destroy != NULL);
- key->func->destroy(key);
- }
- if (key->engine != NULL)
- isc_mem_free(mctx, key->engine);
- if (key->label != NULL)
- isc_mem_free(mctx, key->label);
- dns_name_free(key->key_name, mctx);
- isc_mem_put(mctx, key->key_name, sizeof(dns_name_t));
- if (key->key_tkeytoken) {
- isc_buffer_free(&key->key_tkeytoken);
+ if (isc_refcount_decrement(&key->refs) == 1) {
+ isc_refcount_destroy(&key->refs);
+ if (key->keydata.generic != NULL) {
+ INSIST(key->func->destroy != NULL);
+ key->func->destroy(key);
+ }
+ if (key->engine != NULL)
+ isc_mem_free(mctx, key->engine);
+ if (key->label != NULL)
+ isc_mem_free(mctx, key->label);
+ dns_name_free(key->key_name, mctx);
+ isc_mem_put(mctx, key->key_name, sizeof(dns_name_t));
+ if (key->key_tkeytoken) {
+ isc_buffer_free(&key->key_tkeytoken);
+ }
+ isc_safe_memwipe(key, sizeof(*key));
+ isc_mem_putanddetach(&mctx, key, sizeof(*key));
}
- isc_safe_memwipe(key, sizeof(*key));
- isc_mem_putanddetach(&mctx, key, sizeof(*key));
*keyp = NULL;
}
* Find the next node at the current depth in DNSSEC order.
*/
-/*
- * Wrapper macros for manipulating the rbtnode reference counter:
- * Since we selectively use isc_refcount_t for the reference counter of
- * a rbtnode, operations on the counter depend on the actual type of it.
- * The following macros provide a common interface to these operations,
- * hiding the back-end. The usage is the same as that of isc_refcount_xxx().
- */
-#define dns_rbtnode_refinit(node, n) \
- do { \
- isc_refcount_init(&(node)->references, (n)); \
- } while (0)
-#define dns_rbtnode_refdestroy(node) \
- do { \
- isc_refcount_destroy(&(node)->references); \
- } while (0)
-#define dns_rbtnode_refcurrent(node) \
- isc_refcount_current(&(node)->references)
-#define dns_rbtnode_refincrement0(node, refs) \
- do { \
- isc_refcount_increment0(&(node)->references, (refs)); \
- } while (0)
-#define dns_rbtnode_refincrement(node, refs) \
- do { \
- isc_refcount_increment(&(node)->references, (refs)); \
- } while (0)
-#define dns_rbtnode_refdecrement(node, refs) \
- do { \
- isc_refcount_decrement(&(node)->references, (refs)); \
- } while (0)
-
void
dns_rbtnode_nodename(dns_rbtnode_t *node, dns_name_t *name);
void
dns_iptable_attach(dns_iptable_t *source, dns_iptable_t **target) {
REQUIRE(DNS_IPTABLE_VALID(source));
- isc_refcount_increment(&source->refcount, NULL);
+ isc_refcount_increment(&source->refcount);
*target = source;
}
void
dns_iptable_detach(dns_iptable_t **tabp) {
dns_iptable_t *tab = *tabp;
- unsigned int refs;
REQUIRE(DNS_IPTABLE_VALID(tab));
- isc_refcount_decrement(&tab->refcount, &refs);
- if (refs == 0)
+
+ if (isc_refcount_decrement(&tab->refcount) == 1) {
destroy_iptable(tab);
+ }
+
*tabp = NULL;
}
REQUIRE(VALID_KEYTABLE(source));
REQUIRE(targetp != NULL && *targetp == NULL);
- isc_refcount_increment(&source->references, NULL);
+ isc_refcount_increment(&source->references);
*targetp = source;
}
void
dns_keytable_detach(dns_keytable_t **keytablep) {
dns_keytable_t *keytable;
- unsigned int refs;
/*
* Detach *keytablep from its keytable.
REQUIRE(keytablep != NULL && VALID_KEYTABLE(*keytablep));
keytable = *keytablep;
- *keytablep = NULL;
- isc_refcount_decrement(&keytable->references, &refs);
- if (refs == 0) {
+ if (isc_refcount_decrement(&keytable->references) == 1) {
INSIST(isc_refcount_current(&keytable->active_nodes) == 0);
isc_refcount_destroy(&keytable->active_nodes);
isc_refcount_destroy(&keytable->references);
isc_mem_putanddetach(&keytable->mctx,
keytable, sizeof(*keytable));
}
+ *keytablep = NULL;
}
/*%
DNS_RBTFIND_NOOPTIONS, NULL, NULL);
if (result == ISC_R_SUCCESS) {
if (node->data != NULL) {
- isc_refcount_increment0(&keytable->active_nodes, NULL);
+ isc_refcount_increment0(&keytable->active_nodes);
dns_keynode_attach(node->data, keynodep);
} else
result = ISC_R_NOTFOUND;
return (ISC_R_NOTFOUND);
dns_keynode_attach(keynode->next, nextnodep);
- isc_refcount_increment(&keytable->active_nodes, NULL);
+ isc_refcount_increment(&keytable->active_nodes);
return (ISC_R_SUCCESS);
}
break;
}
if (knode != NULL) {
- isc_refcount_increment0(&keytable->active_nodes, NULL);
+ isc_refcount_increment0(&keytable->active_nodes);
dns_keynode_attach(knode, keynodep);
} else
result = DNS_R_PARTIALMATCH;
break;
}
if (knode != NULL) {
- isc_refcount_increment(&keytable->active_nodes, NULL);
+ isc_refcount_increment(&keytable->active_nodes);
result = ISC_R_SUCCESS;
dns_keynode_attach(knode, nextnodep);
} else
REQUIRE(VALID_KEYNODE(source));
REQUIRE(target != NULL && *target == NULL);
- isc_refcount_increment(&keytable->active_nodes, NULL);
+ isc_refcount_increment(&keytable->active_nodes);
dns_keynode_attach(source, target);
}
REQUIRE(VALID_KEYTABLE(keytable));
REQUIRE(keynodep != NULL && VALID_KEYNODE(*keynodep));
- isc_refcount_decrement(&keytable->active_nodes, NULL);
+ (void)isc_refcount_decrement(&keytable->active_nodes);
dns_keynode_detach(keytable->mctx, keynodep);
}
result = ISC_R_SUCCESS;
goto cleanup;
}
- isc_refcount_increment0(&keytable->active_nodes, NULL);
+ isc_refcount_increment0(&keytable->active_nodes);
for (;;) {
dns_rbtnodechain_current(&chain, NULL, NULL, &node);
if (node->data != NULL)
break;
}
}
- isc_refcount_decrement(&keytable->active_nodes, NULL);
+ (void)isc_refcount_decrement(&keytable->active_nodes);
cleanup:
dns_rbtnodechain_invalidate(&chain);
void
dns_keynode_attach(dns_keynode_t *source, dns_keynode_t **target) {
REQUIRE(VALID_KEYNODE(source));
- isc_refcount_increment(&source->refcount, NULL);
+ isc_refcount_increment(&source->refcount);
*target = source;
}
void
dns_keynode_detach(isc_mem_t *mctx, dns_keynode_t **keynode) {
- unsigned int refs;
dns_keynode_t *node = *keynode;
REQUIRE(VALID_KEYNODE(node));
- isc_refcount_decrement(&node->refcount, &refs);
- if (refs == 0) {
+ if (isc_refcount_decrement(&node->refcount) == 1) {
if (node->key != NULL)
dst_key_free(&node->key);
isc_refcount_destroy(&node->refcount);
*/
static void
nta_ref(dns_nta_t *nta) {
- isc_refcount_increment(&nta->refcount, NULL);
+ isc_refcount_increment(&nta->refcount);
}
static void
nta_detach(isc_mem_t *mctx, dns_nta_t **ntap) {
- unsigned int refs;
dns_nta_t *nta = *ntap;
REQUIRE(VALID_NTA(nta));
- *ntap = NULL;
- isc_refcount_decrement(&nta->refcount, &refs);
- if (refs == 0) {
+ if (isc_refcount_decrement(&nta->refcount) == 1) {
nta->magic = 0;
if (nta->timer != NULL) {
(void) isc_timer_reset(nta->timer,
}
isc_mem_put(mctx, nta, sizeof(dns_nta_t));
}
+ *ntap = NULL;
}
static void
dns_order_attach(dns_order_t *source, dns_order_t **target) {
REQUIRE(DNS_ORDER_VALID(source));
REQUIRE(target != NULL && *target == NULL);
- isc_refcount_increment(&source->references, NULL);
+ isc_refcount_increment(&source->references);
*target = source;
}
dns_order_detach(dns_order_t **orderp) {
dns_order_t *order;
dns_order_ent_t *ent;
- unsigned int references;
REQUIRE(orderp != NULL);
order = *orderp;
REQUIRE(DNS_ORDER_VALID(order));
- isc_refcount_decrement(&order->references, &references);
- *orderp = NULL;
- if (references != 0)
- return;
- order->magic = 0;
- while ((ent = ISC_LIST_HEAD(order->ents)) != NULL) {
- ISC_LIST_UNLINK(order->ents, ent, link);
- isc_mem_put(order->mctx, ent, sizeof(*ent));
+ if (isc_refcount_decrement(&order->references) == 1) {
+ order->magic = 0;
+ while ((ent = ISC_LIST_HEAD(order->ents)) != NULL) {
+ ISC_LIST_UNLINK(order->ents, ent, link);
+ isc_mem_put(order->mctx, ent, sizeof(*ent));
+ }
+ isc_refcount_destroy(&order->references);
+ isc_mem_putanddetach(&order->mctx, order, sizeof(*order));
}
- isc_refcount_destroy(&order->references);
- isc_mem_putanddetach(&order->mctx, order, sizeof(*order));
+
+ *orderp = NULL;
}
REQUIRE(DNS_VALID_PORTLIST(portlist));
REQUIRE(portlistp != NULL && *portlistp == NULL);
- isc_refcount_increment(&portlist->refcount, NULL);
+ isc_refcount_increment(&portlist->refcount);
*portlistp = portlist;
}
void
dns_portlist_detach(dns_portlist_t **portlistp) {
dns_portlist_t *portlist;
- unsigned int count;
REQUIRE(portlistp != NULL);
portlist = *portlistp;
REQUIRE(DNS_VALID_PORTLIST(portlist));
- *portlistp = NULL;
- isc_refcount_decrement(&portlist->refcount, &count);
- if (count == 0) {
+
+ if (isc_refcount_decrement(&portlist->refcount) == 1) {
portlist->magic = 0;
isc_refcount_destroy(&portlist->refcount);
if (portlist->list != NULL)
isc_mem_putanddetach(&portlist->mctx, portlist,
sizeof(*portlist));
}
+ *portlistp = NULL;
}
#if DNS_RBT_USEMAGIC
node->magic = 0;
#endif
- dns_rbtnode_refdestroy(node);
+ isc_refcount_destroy(&node->references);
freenode(rbt, &node);
LOCKNUM(node) = 0;
WILD(node) = 0;
DIRTY(node) = 0;
- dns_rbtnode_refinit(node, 0);
+ isc_refcount_init(&node->references, 0);
node->find_callback = 0;
node->nsec = DNS_RBT_NSEC_NORMAL;
REQUIRE(VALID_RBTDB(rbtdb));
- isc_refcount_increment(&rbtdb->references, NULL);
+ isc_refcount_increment(&rbtdb->references);
*targetp = source;
}
REQUIRE(rbtdb->future_version == NULL);
if (rbtdb->current_version != NULL) {
- unsigned int refs;
- isc_refcount_decrement(&rbtdb->current_version->references,
- &refs);
- INSIST(refs == 0);
+ INSIST(isc_refcount_decrement(&rbtdb->current_version->references) == 1);
+
UNLINK(rbtdb->open_versions, rbtdb->current_version, link);
isc_rwlock_destroy(&rbtdb->current_version->glue_rwlock);
isc_refcount_destroy(&rbtdb->current_version->references);
static void
detach(dns_db_t **dbp) {
dns_rbtdb_t *rbtdb = (dns_rbtdb_t *)(*dbp);
- unsigned int refs;
REQUIRE(VALID_RBTDB(rbtdb));
- isc_refcount_decrement(&rbtdb->references, &refs);
-
- if (refs == 0)
+ if (isc_refcount_decrement(&rbtdb->references) == 1) {
maybe_free_rbtdb(rbtdb);
+ }
*dbp = NULL;
}
currentversion(dns_db_t *db, dns_dbversion_t **versionp) {
dns_rbtdb_t *rbtdb = (dns_rbtdb_t *)db;
rbtdb_version_t *version;
- unsigned int refs;
REQUIRE(VALID_RBTDB(rbtdb));
+ /* XXXOND: Is the lock needed here? */
RBTDB_LOCK(&rbtdb->lock, isc_rwlocktype_read);
version = rbtdb->current_version;
- isc_refcount_increment(&version->references, &refs);
+ isc_refcount_increment(&version->references);
RBTDB_UNLOCK(&rbtdb->lock, isc_rwlocktype_read);
*versionp = (dns_dbversion_t *)version;
{
dns_rbtdb_t *rbtdb = (dns_rbtdb_t *)db;
rbtdb_version_t *rbtversion = source;
- unsigned int refs;
REQUIRE(VALID_RBTDB(rbtdb));
INSIST(rbtversion != NULL && rbtversion->rbtdb == rbtdb);
- isc_refcount_increment(&rbtversion->references, &refs);
- INSIST(refs > 1);
+ isc_refcount_increment(&rbtversion->references);
*targetp = rbtversion;
}
dns_rbtnode_t *node)
{
rbtdb_changed_t *changed;
- unsigned int refs;
/*
* Caller must be holding the node lock if its reference must be
REQUIRE(version->writer);
if (changed != NULL) {
- dns_rbtnode_refincrement(node, &refs);
- INSIST(refs != 0);
+ isc_refcount_increment(&node->references);
changed->node = node;
changed->dirty = false;
ISC_LIST_INITANDAPPEND(version->changed_list, changed, link);
}
}
-#if 0
-static void
-clean_now_or_later(dns_rbtnode_t *node, dns_rbtdb_t *rbtdb,
- rdatasetheader_t *header, rdatasetheader_t **header_prevp)
-{
- if (dns_rbtnode_refcurrent(node) == 0) {
- isc_mem_t *mctx;
-
- /*
- * header->down can be non-NULL if the refcount has just
- * decremented to 0 but decrement_reference() has not performed
- * clean_cache_node(), in which case we need to purge the stale
- * headers first.
- */
- mctx = rbtdb->common.mctx;
- clean_stale_headers(rbtdb, mctx, header);
- if (*header_prevp != NULL)
- (*header_prevp)->next = header->next;
- else
- node->data = header->next;
- free_rdataset(rbtdb, mctx, header);
- } else {
- header->attributes |= RDATASET_ATTR_STALE |
- RDATASET_ATTR_ANCIENT;
- node->dirty = 1;
- *header_prevp = header;
- }
-}
-
-static rdataset_ttl_t
-check_ttl(dns_rbtnode_t *node, rbtdb_search_t *search,
- rdatasetheader_t *header, rdatasetheader_t **header_prevp,
- nodelock_t *lock, isc_rwlocktype_t *locktype)
-{
- dns_rbtdb_t *rbtdb = search->rbtdb;
-
- if (header->rdh_ttl > search->now)
- return rdataset_ttl_fresh;
-
- /*
- * This rdataset is stale, but perhaps still usable.
- */
- if (KEEPSTALE(rbtdb) &&
- header->rdh_ttl + rbtdb->serve_stale_ttl > search->now) {
- header->attributes |= RDATASET_ATTR_STALE;
- /* Doesn't set dirty because it doesn't need removal. */
- return rdataset_ttl_stale;
- }
-
- /*
- * This rdataset is so stale it is no longer usable, even with
- * KEEPSTALE. If no one else is using the node, we can clean it up
- * right now, otherwise we mark it as ancient, and the node as dirty,
- * so it will get cleaned up later.
- */
- if ((header->rdh_ttl <= search->now - RBTDB_VIRTUAL) &&
- (*locktype == isc_rwlocktype_write ||
- NODE_TRYUPGRADE(lock) == ISC_R_SUCCESS)) {
- /*
- * We update the node's status only when we can get write
- * access; otherwise, we leave others to this work. Periodical
- * cleaning will eventually take the job as the last resort.
- * We won't downgrade the lock, since other rdatasets are
- * probably stale, too.
- */
- *locktype = isc_rwlocktype_write;
- clean_now_or_later(node, rbtdb, header, header_prevp);
- } else
- *header_prevp = header;
-
- return rdataset_ttl_ancient;
-}
-#endif
-
/*
* Caller must be holding the node lock.
*/
static inline void
new_reference(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node) {
- unsigned int lockrefs, noderefs;
- isc_refcount_t *lockref;
-
INSIST(!ISC_LINK_LINKED(node, deadlink));
- dns_rbtnode_refincrement0(node, &noderefs);
- if (noderefs == 1) { /* this is the first reference to the node */
- lockref = &rbtdb->node_locks[node->locknum].references;
- isc_refcount_increment0(lockref, &lockrefs);
- INSIST(lockrefs != 0);
+ if (isc_refcount_increment(&node->references) == 0) {
+ /* this is the first reference to the node */
+ isc_refcount_increment0(&rbtdb->node_locks[node->locknum].references);
}
- INSIST(noderefs != 0);
}
/*%
* Since we're holding a tree write lock, it should be
* impossible for this node to be referenced by others.
*/
- INSIST(dns_rbtnode_refcurrent(node) == 0 &&
+ INSIST(isc_refcount_current(&node->references) == 0 &&
node->data == NULL);
if (node->parent != NULL &&
isc_result_t result;
bool write_locked;
rbtdb_nodelock_t *nodelock;
- unsigned int refs, nrefs;
int bucket = node->locknum;
bool no_reference = true;
/* Handle easy and typical case first. */
if (!node->dirty && KEEP_NODE(node, rbtdb)) {
- dns_rbtnode_refdecrement(node, &nrefs);
- INSIST((int)nrefs >= 0);
- if (nrefs == 0) {
- isc_refcount_decrement(&nodelock->references, &refs);
- INSIST((int)refs >= 0);
+ if (isc_refcount_decrement(&node->references) == 1) {
+ isc_refcount_decrement(&nodelock->references);
+ return (true);
+ } else {
+ return (false);
}
- return ((nrefs == 0) ? true : false);
}
/* Upgrade the lock? */
NODE_WEAKLOCK(&nodelock->lock, isc_rwlocktype_write);
}
- dns_rbtnode_refdecrement(node, &nrefs);
- INSIST((int)nrefs >= 0);
- if (nrefs > 0) {
+ if (isc_refcount_decrement(&node->references) > 1) {
/* Restore the lock? */
if (nlock == isc_rwlocktype_read)
NODE_WEAKDOWNGRADE(&nodelock->lock);
} else
write_locked = true;
- isc_refcount_decrement(&nodelock->references, &refs);
- INSIST((int)refs >= 0);
+ isc_refcount_decrement(&nodelock->references);
if (KEEP_NODE(node, rbtdb))
goto restore_locks;
dns_rbtdb_t *rbtdb = event->ev_arg;
bool again = false;
unsigned int locknum;
- unsigned int refs;
RWLOCK(&rbtdb->tree_lock, isc_rwlocktype_write);
for (locknum = 0; locknum < rbtdb->node_lock_count; locknum++) {
isc_task_send(task, &event);
else {
isc_event_free(&event);
- isc_refcount_decrement(&rbtdb->references, &refs);
- if (refs == 0)
+ if (isc_refcount_decrement(&rbtdb->references) == 1) {
maybe_free_rbtdb(rbtdb);
+ }
}
}
rbtdb_changed_t *changed, *next_changed;
rbtdb_serial_t serial, least_serial;
dns_rbtnode_t *rbtnode;
- unsigned int refs;
rdatasetheader_t *header;
REQUIRE(VALID_RBTDB(rbtdb));
ISC_LIST_INIT(cleanup_list);
ISC_LIST_INIT(resigned_list);
- isc_refcount_decrement(&version->references, &refs);
- if (refs > 0) { /* typical and easy case first */
+ if (isc_refcount_decrement(&version->references) > 1) {
+ /* typical and easy case first */
if (commit) {
RBTDB_LOCK(&rbtdb->lock, isc_rwlocktype_read);
INSIST(!version->writer);
* DB itself and unlink it from the open list.
*/
cur_version = rbtdb->current_version;
- isc_refcount_decrement(&cur_version->references,
- &cur_ref);
- if (cur_ref == 0) {
+ cur_ref = isc_refcount_decrement(&cur_version->references);
+ if (cur_ref == 1) {
if (cur_version->serial == rbtdb->least_serial)
INSIST(EMPTY(cur_version->changed_list));
UNLINK(rbtdb->open_versions,
* isn't being used by anyone, we can clean
* it up.
*/
- if (cur_ref == 0) {
+ if (cur_ref == 1) {
cleanup_version = cur_version;
APPENDLIST(version->changed_list,
cleanup_version->changed_list,
* case where we need to increment the counter from
* zero and need to use isc_refcount_increment0().
*/
- isc_refcount_increment0(&version->references,
- &cur_ref);
- INSIST(cur_ref == 1);
+ INSIST(isc_refcount_increment0(&version->references) == 0);
PREPEND(rbtdb->open_versions,
rbtdb->current_version, link);
resigned_list = version->resigned_list;
sizeof(*changed));
}
if (event != NULL) {
- isc_refcount_increment(&rbtdb->references, NULL);
+ isc_refcount_increment(&rbtdb->references);
isc_task_send(rbtdb->task, &event);
} else
RWUNLOCK(&rbtdb->tree_lock, isc_rwlocktype_write);
*/
*locktype = isc_rwlocktype_write;
- if (dns_rbtnode_refcurrent(node) == 0) {
+ if (isc_refcount_current(&node->references) == 0) {
isc_mem_t *mctx;
/*
attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp) {
dns_rbtdb_t *rbtdb = (dns_rbtdb_t *)db;
dns_rbtnode_t *node = (dns_rbtnode_t *)source;
- unsigned int refs;
REQUIRE(VALID_RBTDB(rbtdb));
REQUIRE(targetp != NULL && *targetp == NULL);
- NODE_STRONGLOCK(&rbtdb->node_locks[node->locknum].lock);
- dns_rbtnode_refincrement(node, &refs);
- INSIST(refs != 0);
- NODE_STRONGUNLOCK(&rbtdb->node_locks[node->locknum].lock);
+ isc_refcount_increment(&node->references);
*targetp = source;
}
NODE_LOCK(&rbtdb->node_locks[rbtnode->locknum].lock,
isc_rwlocktype_read);
- refs = dns_rbtnode_refcurrent(rbtnode);
+ refs = isc_refcount_current(&rbtnode->references);
fprintf(out, "node %p, %" PRIu32 " references, locknum = %u\n",
rbtnode, refs,
rbtnode->locknum);
dns_rbtnode_t *rbtnode = (dns_rbtnode_t *)node;
rbtdb_version_t *rbtversion = version;
rbtdb_rdatasetiter_t *iterator;
- unsigned int refs;
REQUIRE(VALID_RBTDB(rbtdb));
else {
INSIST(rbtversion->rbtdb == rbtdb);
- isc_refcount_increment(&rbtversion->references,
- &refs);
- INSIST(refs > 1);
+ (void)isc_refcount_increment(&rbtversion->references);
}
} else {
if (now == 0)
NODE_STRONGLOCK(&rbtdb->node_locks[rbtnode->locknum].lock);
- dns_rbtnode_refincrement(rbtnode, &refs);
- INSIST(refs != 0);
+ isc_refcount_increment(&rbtnode->references);
iterator->current = NULL;
rbtdb->next_serial = 2;
rbtdb->current_version = allocate_version(mctx, 1, 1, false);
if (rbtdb->current_version == NULL) {
- isc_refcount_decrement(&rbtdb->references, NULL);
+ isc_refcount_decrement(&rbtdb->references);
free_rbtdb(rbtdb, false, NULL);
return (ISC_R_NOMEMORY);
}
isc_mem_put(mctx, rbtdb->current_version,
sizeof(*rbtdb->current_version));
rbtdb->current_version = NULL;
- isc_refcount_decrement(&rbtdb->references, NULL);
+ isc_refcount_decrement(&rbtdb->references);
free_rbtdb(rbtdb, false, NULL);
return (result);
}
* expirenode() currently always returns success.
*/
if (expire_result == ISC_R_SUCCESS && node->down == NULL) {
- unsigned int refs;
-
rbtdbiter->deletions[rbtdbiter->delcnt++] = node;
- NODE_STRONGLOCK(&rbtdb->node_locks[node->locknum].lock);
- dns_rbtnode_refincrement(node, &refs);
- INSIST(refs != 0);
- NODE_STRONGUNLOCK(&rbtdb->node_locks[node->locknum].lock);
+ isc_refcount_increment(&node->references);
}
}
cur = version->glue_table[i];
while (cur != NULL) {
cur_next = cur->next;
- /* dns_rbtnode_refdecrement(cur->node, NULL); */
+ /* isc_refcount_decrement(&cur->node->references); */
cur->node = NULL;
free_gluelist(cur->glue_list, rbtdb);
cur->glue_list = NULL;
* when named is terminated by a keyboard break. This doesn't
* cleanup the node reference and keeps the process dangling.
*/
- /* dns_rbtnode_refincrement0(node, NULL); */
+ /* isc_refcount_increment0(&node->references); */
cur->node = node;
if (ctx.glue_list == NULL) {
* Caller must hold the node (write) lock.
*/
- if (dns_rbtnode_refcurrent(header->node) == 0) {
+ if (isc_refcount_current(&header->node->references) == 0) {
/*
* If no one else is using the node, we can clean it up now.
* We first need to gain a new reference to the node to meet a
dns_rbt_destroy(&zones->rbt);
cleanup_rbt:
- isc_refcount_decrement(&zones->refs, NULL);
+ (void)isc_refcount_decrement(&zones->refs);
isc_refcount_destroy(&zones->refs);
DESTROYLOCK(&zones->maint_lock);
isc_timer_detach(&zone->updatetimer);
cleanup_timer:
- isc_refcount_decrement(&zone->refs, NULL);
+ isc_refcount_decrement(&zone->refs);
isc_refcount_destroy(&zone->refs);
isc_mem_put(zone->rpzs->mctx, zone, sizeof(*zone));
static void
rpz_detach(dns_rpz_zone_t **rpzp, dns_rpz_zones_t *rpzs) {
dns_rpz_zone_t *rpz;
- unsigned int refs;
rpz = *rpzp;
+
+ if (isc_refcount_decrement(&rpz->refs) == 1) {
+ isc_refcount_destroy(&rpz->refs);
+
+ if (dns_name_dynamic(&rpz->origin))
+ dns_name_free(&rpz->origin, rpzs->mctx);
+ if (dns_name_dynamic(&rpz->client_ip))
+ dns_name_free(&rpz->client_ip, rpzs->mctx);
+ if (dns_name_dynamic(&rpz->ip))
+ dns_name_free(&rpz->ip, rpzs->mctx);
+ if (dns_name_dynamic(&rpz->nsdname))
+ dns_name_free(&rpz->nsdname, rpzs->mctx);
+ if (dns_name_dynamic(&rpz->nsip))
+ dns_name_free(&rpz->nsip, rpzs->mctx);
+ if (dns_name_dynamic(&rpz->passthru))
+ dns_name_free(&rpz->passthru, rpzs->mctx);
+ if (dns_name_dynamic(&rpz->drop))
+ dns_name_free(&rpz->drop, rpzs->mctx);
+ if (dns_name_dynamic(&rpz->tcp_only))
+ dns_name_free(&rpz->tcp_only, rpzs->mctx);
+ if (dns_name_dynamic(&rpz->cname))
+ dns_name_free(&rpz->cname, rpzs->mctx);
+ if (rpz->db_registered)
+ dns_db_updatenotify_unregister(rpz->db,
+ dns_rpz_dbupdate_callback, rpz);
+ if (rpz->dbversion != NULL)
+ dns_db_closeversion(rpz->db, &rpz->dbversion,
+ false);
+ if (rpz->db)
+ dns_db_detach(&rpz->db);
+ isc_ht_destroy(&rpz->nodes);
+ isc_timer_detach(&rpz->updatetimer);
+
+ isc_mem_put(rpzs->mctx, rpz, sizeof(*rpz));
+ }
+
*rpzp = NULL;
- isc_refcount_decrement(&rpz->refs, &refs);
- if (refs != 0)
- return;
- isc_refcount_destroy(&rpz->refs);
-
- if (dns_name_dynamic(&rpz->origin))
- dns_name_free(&rpz->origin, rpzs->mctx);
- if (dns_name_dynamic(&rpz->client_ip))
- dns_name_free(&rpz->client_ip, rpzs->mctx);
- if (dns_name_dynamic(&rpz->ip))
- dns_name_free(&rpz->ip, rpzs->mctx);
- if (dns_name_dynamic(&rpz->nsdname))
- dns_name_free(&rpz->nsdname, rpzs->mctx);
- if (dns_name_dynamic(&rpz->nsip))
- dns_name_free(&rpz->nsip, rpzs->mctx);
- if (dns_name_dynamic(&rpz->passthru))
- dns_name_free(&rpz->passthru, rpzs->mctx);
- if (dns_name_dynamic(&rpz->drop))
- dns_name_free(&rpz->drop, rpzs->mctx);
- if (dns_name_dynamic(&rpz->tcp_only))
- dns_name_free(&rpz->tcp_only, rpzs->mctx);
- if (dns_name_dynamic(&rpz->cname))
- dns_name_free(&rpz->cname, rpzs->mctx);
- if (rpz->db_registered)
- dns_db_updatenotify_unregister(rpz->db,
- dns_rpz_dbupdate_callback, rpz);
- if (rpz->dbversion != NULL)
- dns_db_closeversion(rpz->db, &rpz->dbversion,
- false);
- if (rpz->db)
- dns_db_detach(&rpz->db);
- isc_ht_destroy(&rpz->nodes);
- isc_timer_detach(&rpz->updatetimer);
-
- isc_mem_put(rpzs->mctx, rpz, sizeof(*rpz));
}
void
dns_rpz_attach_rpzs(dns_rpz_zones_t *rpzs, dns_rpz_zones_t **rpzsp) {
REQUIRE(rpzsp != NULL && *rpzsp == NULL);
- isc_refcount_increment(&rpzs->refs, NULL);
+ isc_refcount_increment(&rpzs->refs);
*rpzsp = rpzs;
}
dns_rpz_zones_t *rpzs;
dns_rpz_zone_t *rpz;
dns_rpz_num_t rpz_num;
- unsigned int refs;
REQUIRE(rpzsp != NULL);
rpzs = *rpzsp;
REQUIRE(rpzs != NULL);
*rpzsp = NULL;
- isc_refcount_decrement(&rpzs->refs, &refs);
- if (refs != 0) {
- return;
- }
+ if (isc_refcount_decrement(&rpzs->refs) == 1) {
+ isc_refcount_destroy(&rpzs->refs);
- /*
- * Forget the last of view's rpz machinery after the last reference.
- */
- for (rpz_num = 0; rpz_num < DNS_RPZ_MAX_ZONES; ++rpz_num) {
- rpz = rpzs->zones[rpz_num];
- rpzs->zones[rpz_num] = NULL;
- if (rpz != NULL) {
- rpz_detach(&rpz, rpzs);
+ /*
+ * Forget the last of view's rpz machinery after the last reference.
+ */
+ for (rpz_num = 0; rpz_num < DNS_RPZ_MAX_ZONES; ++rpz_num) {
+ rpz = rpzs->zones[rpz_num];
+ rpzs->zones[rpz_num] = NULL;
+ if (rpz != NULL) {
+ rpz_detach(&rpz, rpzs);
+ }
}
- }
- if (rpzs->rps_cstr_size != 0) {
+ if (rpzs->rps_cstr_size != 0) {
#ifdef USE_DNSRPS
- librpz->client_detach(&rpzs->rps_client);
+ librpz->client_detach(&rpzs->rps_client);
#endif
- isc_mem_put(rpzs->mctx, rpzs->rps_cstr,
- rpzs->rps_cstr_size);
- }
+ isc_mem_put(rpzs->mctx, rpzs->rps_cstr,
+ rpzs->rps_cstr_size);
+ }
- cidr_free(rpzs);
- if (rpzs->rbt != NULL) {
- dns_rbt_destroy(&rpzs->rbt);
+ cidr_free(rpzs);
+ if (rpzs->rbt != NULL) {
+ dns_rbt_destroy(&rpzs->rbt);
+ }
+ DESTROYLOCK(&rpzs->maint_lock);
+ isc_rwlock_destroy(&rpzs->search_lock);
+ isc_task_destroy(&rpzs->updater);
+ isc_mem_putanddetach(&rpzs->mctx, rpzs, sizeof(*rpzs));
}
- DESTROYLOCK(&rpzs->maint_lock);
- isc_rwlock_destroy(&rpzs->search_lock);
- isc_refcount_destroy(&rpzs->refs);
- isc_task_destroy(&rpzs->updater);
- isc_mem_putanddetach(&rpzs->mctx, rpzs, sizeof(*rpzs));
}
/*
cleanup_refs:
tkey->magic = 0;
- while (refs-- > 0)
- isc_refcount_decrement(&tkey->refs, NULL);
+ while (refs-- > 0) {
+ (void)isc_refcount_decrement(&tkey->refs);
+ }
isc_refcount_destroy(&tkey->refs);
if (tkey->key != NULL)
REQUIRE(VALID_TSIG_KEY(source));
REQUIRE(targetp != NULL && *targetp == NULL);
- isc_refcount_increment(&source->refs, NULL);
+ isc_refcount_increment(&source->refs);
*targetp = source;
}
void
dns_tsigkey_detach(dns_tsigkey_t **keyp) {
dns_tsigkey_t *key;
- unsigned int refs;
REQUIRE(keyp != NULL);
REQUIRE(VALID_TSIG_KEY(*keyp));
key = *keyp;
- isc_refcount_decrement(&key->refs, &refs);
- if (refs == 0)
+ if (isc_refcount_decrement(&key->refs) == 1) {
tsigkey_free(key);
+ }
*keyp = NULL;
}
return (ISC_R_NOTFOUND);
}
#endif
- isc_refcount_increment(&key->refs, NULL);
+ isc_refcount_increment(&key->refs);
RWUNLOCK(&ring->lock, isc_rwlocktype_read);
adjust_lru(key);
*tsigkey = key;
result = keyring_add(ring, name, tkey);
if (result == ISC_R_SUCCESS)
- isc_refcount_increment(&tkey->refs, NULL);
+ isc_refcount_increment(&tkey->refs);
return (result);
}
dns_tsigkeyring_detach(&view->dynamickeys);
cleanup_references:
- isc_refcount_decrement(&view->references, NULL);
+ (void)isc_refcount_decrement(&view->references);
isc_refcount_destroy(&view->references);
if (view->fwdtable != NULL)
REQUIRE(DNS_VIEW_VALID(source));
REQUIRE(targetp != NULL && *targetp == NULL);
- isc_refcount_increment(&source->references, NULL);
+ isc_refcount_increment(&source->references);
*targetp = source;
}
static void
view_flushanddetach(dns_view_t **viewp, bool flush) {
dns_view_t *view;
- unsigned int refs;
bool done = false;
REQUIRE(viewp != NULL);
if (flush)
view->flush = true;
- isc_refcount_decrement(&view->references, &refs);
- if (refs == 0) {
+ if (isc_refcount_decrement(&view->references) == 1) {
dns_zone_t *mkzone = NULL, *rdzone = NULL;
LOCK(&view->lock);
isc_stats_detach(&zone->gluecachestats);
free_erefs:
- isc_refcount_decrement(&zone->erefs, NULL);
+ (void)isc_refcount_decrement(&zone->erefs);
isc_refcount_destroy(&zone->erefs);
ZONEDB_DESTROYLOCK(&zone->dblock);
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, NULL);
+ isc_refcount_increment(&source->erefs);
*target = source;
}
dns_zone_t *zone;
dns_zone_t *raw = NULL;
dns_zone_t *secure = NULL;
- unsigned int refs;
bool free_now = false;
REQUIRE(zonep != NULL && DNS_ZONE_VALID(*zonep));
zone = *zonep;
- isc_refcount_decrement(&zone->erefs, &refs);
-
- if (refs == 0) {
+ if (isc_refcount_decrement(&zone->erefs) == 1) {
LOCK_ZONE(zone);
INSIST(zone != zone->raw);
/*
/* dns_zone_attach(raw, &zone->raw); */
- isc_refcount_increment(&raw->erefs, NULL);
+ isc_refcount_increment(&raw->erefs);
zone->raw = raw;
/* dns_zone_iattach(zone, &raw->secure); */
* Sample implementations
*/
-typedef struct isc_refcount {
- atomic_int_fast32_t refs;
-} isc_refcount_t;
-
-#define isc_refcount_init(rp, n) \
- atomic_init(&(rp)->refs, n)
-
-#define isc_refcount_current(rp) \
- atomic_load_explicit(&(rp)->refs, memory_order_relaxed)
-
-#define isc_refcount_destroy(rp) \
- ISC_REQUIRE(isc_refcount_current(rp) == 0)
-
-#define isc_refcount_increment0(rp, tp) \
- do { \
- unsigned int *_tmp = (unsigned int *)(tp); \
- int32_t prev; \
- prev = atomic_fetch_add_explicit \
- (&(rp)->refs, 1, memory_order_relaxed); \
- if (_tmp != NULL) \
- *_tmp = prev + 1; \
- } while (0)
-
-#define isc_refcount_increment(rp, tp) \
- do { \
- unsigned int *_tmp = (unsigned int *)(tp); \
- int32_t prev; \
- prev = atomic_fetch_add_explicit \
- (&(rp)->refs, 1, memory_order_relaxed); \
- ISC_REQUIRE(prev > 0); \
- if (_tmp != NULL) \
- *_tmp = prev + 1; \
- } while (0)
-
-#define isc_refcount_decrement(rp, tp) \
- do { \
- unsigned int *_tmp = (unsigned int *)(tp); \
- int32_t prev; \
- prev = atomic_fetch_sub_explicit \
- (&(rp)->refs, 1, memory_order_relaxed); \
- ISC_REQUIRE(prev > 0); \
- if (_tmp != NULL) \
- *_tmp = prev - 1; \
- } while (0)
+typedef atomic_uint_fast32_t isc_refcount_t;
+
+#define isc_refcount_init(target, value) \
+ atomic_init(target, value)
+
+#define isc_refcount_current(target) \
+ atomic_load_explicit(target, memory_order_acquire)
+
+#define isc_refcount_destroy(target) \
+ ISC_REQUIRE(isc_refcount_current(target) == 0)
+
+#define isc_refcount_increment0(target) \
+ atomic_fetch_add_explicit(target, 1, memory_order_relaxed)
+
+#define isc_refcount_increment(target) \
+ atomic_fetch_add_explicit(target, 1, memory_order_relaxed)
+
+#define isc_refcount_decrement(target) \
+ atomic_fetch_sub_explicit(target, 1, memory_order_release)
ISC_LANG_ENDDECLS
void
isc__mem_attach(isc_mem_t *source0, isc_mem_t **targetp) {
isc__mem_t *source = (isc__mem_t *)source0;
- int_fast32_t refs;
REQUIRE(VALID_CONTEXT(source));
REQUIRE(targetp != NULL && *targetp == NULL);
- isc_refcount_increment(&source->references, &refs);
+ isc_refcount_increment(&source->references);
*targetp = (isc_mem_t *)source;
}
void
isc__mem_detach(isc_mem_t **ctxp) {
isc__mem_t *ctx;
- int_fast32_t refs;
REQUIRE(ctxp != NULL);
ctx = (isc__mem_t *)*ctxp;
REQUIRE(VALID_CONTEXT(ctx));
- isc_refcount_decrement(&ctx->references, &refs);
-
- if (refs == 0) {
+ if (isc_refcount_decrement(&ctx->references) == 1) {
destroy(ctx);
}
isc__mem_t *ctx;
size_info *si;
size_t oldsize;
- int_fast32_t refs;
REQUIRE(ctxp != NULL);
ctx = (isc__mem_t *)*ctxp;
}
isc__mem_free((isc_mem_t *)ctx, ptr FLARG_PASS);
- isc_refcount_decrement(&ctx->references, &refs);
-
- if (refs == 0) {
+ if (isc_refcount_decrement(&ctx->references) == 1) {
destroy(ctx);
}
}
MCTXUNLOCK(ctx, &ctx->lock);
- isc_refcount_decrement(&ctx->references, &refs);
-
- if (refs == 0) {
+ if (isc_refcount_decrement(&ctx->references) == 1) {
destroy(ctx);
}
}
void
isc__mem_destroy(isc_mem_t **ctxp) {
isc__mem_t *ctx;
- int_fast32_t refs;
/*
* This routine provides legacy support for callers who use mctxs
ctx = (isc__mem_t *)*ctxp;
REQUIRE(VALID_CONTEXT(ctx));
- isc_refcount_decrement(&ctx->references, &refs);
#if ISC_MEM_TRACKLINES
- if (refs >= 1) {
+ if (isc_refcount_decrement(&ctx->references) != 1) {
print_active(ctx, stderr);
}
+#else
+ (void)isc_refcount_decrement(&ctx->references);
#endif
isc_refcount_destroy(&ctx->references);
destroy(ctx);
static void
_deref_prefix(isc_prefix_t *prefix) {
- int refs;
-
if (prefix == NULL)
return;
- isc_refcount_decrement(&prefix->refcount, &refs);
-
- if (refs <= 0) {
+ if (isc_refcount_decrement(&prefix->refcount) == 1) {
isc_refcount_destroy(&prefix->refcount);
isc_mem_putanddetach(&prefix->mctx, prefix,
sizeof(isc_prefix_t));
return (ret);
}
- isc_refcount_increment(&prefix->refcount, NULL);
+ isc_refcount_increment(&prefix->refcount);
*target = prefix;
return (ISC_R_SUCCESS);
REQUIRE(src != NULL);
REQUIRE(dest != NULL && *dest == NULL);
- isc_refcount_increment(&src->references, NULL);
+ isc_refcount_increment(&src->references);
*dest = src;
}
cfg_aclconfctx_detach(cfg_aclconfctx_t **actxp) {
cfg_aclconfctx_t *actx;
dns_acl_t *dacl, *next;
- unsigned int refs;
REQUIRE(actxp != NULL && *actxp != NULL);
actx = *actxp;
- isc_refcount_decrement(&actx->references, &refs);
- if (refs == 0) {
+ if (isc_refcount_decrement(&actx->references) == 1) {
for (dacl = ISC_LIST_HEAD(actx->named_acl_cache);
dacl != NULL;
dacl = next)
REQUIRE(src != NULL);
REQUIRE(dest != NULL && *dest == NULL);
- isc_refcount_increment(&src->references, NULL);
+ isc_refcount_increment(&src->references);
*dest = src;
}
void
cfg_parser_destroy(cfg_parser_t **pctxp) {
cfg_parser_t *pctx;
- unsigned int refs;
REQUIRE(pctxp != NULL && *pctxp != NULL);
pctx = *pctxp;
*pctxp = NULL;
- isc_refcount_decrement(&pctx->references, &refs);
- if (refs == 0) {
+ if (isc_refcount_decrement(&pctx->references) == 1) {
isc_lex_destroy(&pctx->lexer);
/*
* Cleaning up open_files does not
void
cfg_obj_destroy(cfg_parser_t *pctx, cfg_obj_t **objp) {
cfg_obj_t *obj;
- unsigned int refs;
REQUIRE(objp != NULL && *objp != NULL);
REQUIRE(pctx != NULL);
obj = *objp;
- isc_refcount_decrement(&obj->references, &refs);
- if (refs == 0) {
+ if (isc_refcount_decrement(&obj->references) == 1) {
obj->type->rep->free(pctx, obj);
isc_refcount_destroy(&obj->references);
isc_mem_put(pctx->mctx, obj, sizeof(cfg_obj_t));
REQUIRE(src != NULL);
REQUIRE(dest != NULL && *dest == NULL);
- isc_refcount_increment(&src->references, NULL);
+ isc_refcount_increment(&src->references);
*dest = src;
}
REQUIRE(SCTX_VALID(src));
REQUIRE(dest != NULL && *dest == NULL);
- isc_refcount_increment(&src->references, NULL);
+ isc_refcount_increment(&src->references);
*dest = src;
}
void
ns_server_detach(ns_server_t **sctxp) {
ns_server_t *sctx;
- unsigned int refs;
REQUIRE(sctxp != NULL);
sctx = *sctxp;
REQUIRE(SCTX_VALID(sctx));
- isc_refcount_decrement(&sctx->references, &refs);
- if (refs == 0) {
+ if (isc_refcount_decrement(&sctx->references) == 1) {
ns_altsecret_t *altsecret;
sctx->magic = 0;