CHECK(dns_name_dupwithoffsets(origin, mctx, &sampledb->common.origin));
- CHECK(isc_refcount_init(&sampledb->refs, 1));
+ isc_refcount_init(&sampledb->refs, 1);
/* Translate instance name to instance pointer. */
sampledb->inst = driverarg;
acl->name = NULL;
- result = isc_refcount_init(&acl->refcount, 1);
- if (result != ISC_R_SUCCESS) {
- isc_mem_put(mctx, acl, sizeof(*acl));
- return (result);
- }
+ isc_refcount_init(&acl->refcount, 1);
result = dns_iptable_create(mctx, &acl->iptable);
if (result != ISC_R_SUCCESS) {
if (result != ISC_R_SUCCESS)
goto cleanup_newzones;
- result = isc_refcount_init(&new_zones->refs, 1);
- if (result != ISC_R_SUCCESS)
- goto cleanup_mutex;
+ isc_refcount_init(&new_zones->refs, 1);
result = isc_ht_init(&new_zones->zones, mctx, 4);
if (result != ISC_R_SUCCESS)
isc_ht_destroy(&new_zones->zones);
cleanup_refcount:
isc_refcount_destroy(&new_zones->refs);
- cleanup_mutex:
isc_mutex_destroy(&new_zones->lock);
cleanup_newzones:
isc_mem_put(mctx, new_zones, sizeof(*new_zones));
memset(env, 0, sizeof(dns_dtenv_t));
- CHECK(isc_refcount_init(&env->refcount, 1));
+ isc_refcount_init(&env->refcount, 1);
CHECK(isc_stats_create(mctx, &env->stats, dns_dnstapcounter_max));
env->path = isc_mem_strdup(mctx, path);
if (env->path == NULL)
return (NULL);
}
- result = isc_refcount_init(&key->refs, 1);
- if (result != ISC_R_SUCCESS) {
- dns_name_free(key->key_name, mctx);
- isc_mem_put(mctx, key->key_name, sizeof(dns_name_t));
- isc_mem_put(mctx, key, sizeof(dst_key_t));
- return (NULL);
- }
+ isc_refcount_init(&key->refs, 1);
isc_mem_attach(mctx, &key->mctx);
key->key_alg = alg;
key->key_flags = flags;
goto cleanup_rbt;
}
- result = isc_refcount_init(&keytable->active_nodes, 0);
- if (result != ISC_R_SUCCESS) {
- goto cleanup_rwlock;
- }
-
- result = isc_refcount_init(&keytable->references, 1);
- if (result != ISC_R_SUCCESS) {
- goto cleanup_active_nodes;
- }
+ isc_refcount_init(&keytable->active_nodes, 0);
+ isc_refcount_init(&keytable->references, 1);
keytable->mctx = NULL;
isc_mem_attach(mctx, &keytable->mctx);
return (ISC_R_SUCCESS);
- cleanup_active_nodes:
- isc_refcount_destroy(&keytable->active_nodes);
-
- cleanup_rwlock:
- isc_rwlock_destroy(&keytable->rwlock);
-
cleanup_rbt:
dns_rbt_destroy(&keytable->table);
isc_result_t
dns_keynode_create(isc_mem_t *mctx, dns_keynode_t **target) {
- isc_result_t result;
dns_keynode_t *knode;
REQUIRE(target != NULL && *target == NULL);
knode->key = NULL;
knode->next = NULL;
- result = isc_refcount_init(&knode->refcount, 1);
- if (result != ISC_R_SUCCESS)
- return (result);
+ isc_refcount_init(&knode->refcount, 1);
*target = knode;
return (ISC_R_SUCCESS);
nta_create(dns_ntatable_t *ntatable, const dns_name_t *name,
dns_nta_t **target)
{
- isc_result_t result;
dns_nta_t *nta = NULL;
dns_view_t *view;
dns_rdataset_init(&nta->rdataset);
dns_rdataset_init(&nta->sigrdataset);
- result = isc_refcount_init(&nta->refcount, 1);
- if (result != ISC_R_SUCCESS) {
- isc_mem_put(view->mctx, nta, sizeof(dns_nta_t));
- return (result);
- }
+ isc_refcount_init(&nta->refcount, 1);
nta->name = dns_fixedname_initname(&nta->fn);
dns_name_copy(name, nta->name, NULL);
isc_result_t
dns_order_create(isc_mem_t *mctx, dns_order_t **orderp) {
dns_order_t *order;
- isc_result_t result;
REQUIRE(orderp != NULL && *orderp == NULL);
ISC_LIST_INIT(order->ents);
/* Implicit attach. */
- result = isc_refcount_init(&order->references, 1);
- if (result != ISC_R_SUCCESS) {
- isc_mem_put(mctx, order, sizeof(*order));
- return (result);
- }
+ isc_refcount_init(&order->references, 1);
order->mctx = NULL;
isc_mem_attach(mctx, &order->mctx);
isc_mem_put(mctx, portlist, sizeof(*portlist));
return (result);
}
- result = isc_refcount_init(&portlist->refcount, 1);
- if (result != ISC_R_SUCCESS) {
- DESTROYLOCK(&portlist->lock);
- isc_mem_put(mctx, portlist, sizeof(*portlist));
- return (result);
- }
+ isc_refcount_init(&portlist->refcount, 1);
portlist->list = NULL;
portlist->allocated = 0;
portlist->active = 0;
if (version == NULL)
return (NULL);
version->serial = serial;
- result = isc_refcount_init(&version->references, references);
- if (result != ISC_R_SUCCESS) {
- isc_mem_put(mctx, version, sizeof(*version));
- return (NULL);
- }
+
+ isc_refcount_init(&version->references, references);
+
result = isc_rwlock_init(&version->glue_rwlock, 0, 0);
if (result != ISC_R_SUCCESS) {
isc_refcount_destroy(&version->references);
for (i = 0; i < (int)(rbtdb->node_lock_count); i++) {
result = NODE_INITLOCK(&rbtdb->node_locks[i].lock);
if (result == ISC_R_SUCCESS) {
- result = isc_refcount_init(&rbtdb->node_locks[i].references, 0);
- if (result != ISC_R_SUCCESS)
- NODE_DESTROYLOCK(&rbtdb->node_locks[i].lock);
+ isc_refcount_init(&rbtdb->node_locks[i].references, 0);
}
if (result != ISC_R_SUCCESS) {
while (i-- > 0) {
/*
* Misc. Initialization.
*/
- result = isc_refcount_init(&rbtdb->references, 1);
- if (result != ISC_R_SUCCESS) {
- free_rbtdb(rbtdb, false, NULL);
- return (result);
- }
+ isc_refcount_init(&rbtdb->references, 1);
rbtdb->attributes = 0;
rbtdb->task = NULL;
rbtdb->serve_stale_ttl = 0;
if (result != ISC_R_SUCCESS)
goto cleanup_mutex;
- result = isc_refcount_init(&zones->refs, 1);
- if (result != ISC_R_SUCCESS)
- goto cleanup_refcount;
+ isc_refcount_init(&zones->refs, 1);
zones->rps_cstr = rps_cstr;
zones->rps_cstr_size = rps_cstr_size;
isc_refcount_decrement(&zones->refs, NULL);
isc_refcount_destroy(&zones->refs);
-cleanup_refcount:
DESTROYLOCK(&zones->maint_lock);
cleanup_mutex:
}
memset(zone, 0, sizeof(*zone));
- result = isc_refcount_init(&zone->refs, 1);
- if (result != ISC_R_SUCCESS)
- goto cleanup_refcount;
+ isc_refcount_init(&zone->refs, 1);
result = isc_timer_create(rpzs->timermgr, isc_timertype_inactive,
NULL, NULL, rpzs->updater,
isc_refcount_decrement(&zone->refs, NULL);
isc_refcount_destroy(&zone->refs);
-cleanup_refcount:
isc_mem_put(zone->rpzs->mctx, zone, sizeof(*zone));
return (result);
refs = 1;
if (ring != NULL)
refs++;
- ret = isc_refcount_init(&tkey->refs, refs);
- if (ret != ISC_R_SUCCESS)
- goto cleanup_creator;
+
+ isc_refcount_init(&tkey->refs, refs);
tkey->generated = generated;
tkey->inception = inception;
while (refs-- > 0)
isc_refcount_decrement(&tkey->refs, NULL);
isc_refcount_destroy(&tkey->refs);
- cleanup_creator:
+
if (tkey->key != NULL)
dst_key_free(&tkey->key);
if (tkey->creator != NULL) {
view->rdclass = rdclass;
view->frozen = false;
view->task = NULL;
- result = isc_refcount_init(&view->references, 1);
- if (result != ISC_R_SUCCESS)
- goto cleanup_fwdtable;
+ isc_refcount_init(&view->references, 1);
view->weakrefs = 0;
view->attributes = (DNS_VIEWATTR_RESSHUTDOWN|DNS_VIEWATTR_ADBSHUTDOWN|
DNS_VIEWATTR_REQSHUTDOWN);
isc_refcount_decrement(&view->references, NULL);
isc_refcount_destroy(&view->references);
- cleanup_fwdtable:
if (view->fwdtable != NULL)
dns_fwdtable_destroy(&view->fwdtable);
zone->db = NULL;
zone->zmgr = NULL;
ISC_LINK_INIT(zone, link);
- result = isc_refcount_init(&zone->erefs, 1); /* Implicit attach. */
- if (result != ISC_R_SUCCESS) {
- goto free_dblock;
- }
+ isc_refcount_init(&zone->erefs, 1); /* Implicit attach. */
zone->irefs = 0;
dns_name_init(&zone->origin, NULL);
zone->strnamerd = NULL;
isc_refcount_decrement(&zone->erefs, NULL);
isc_refcount_destroy(&zone->erefs);
- free_dblock:
ZONEDB_DESTROYLOCK(&zone->dblock);
free_mutex:
md5.@O@ mem.@O@ mutexblock.@O@ \
netaddr.@O@ netscope.@O@ nonce.@O@ openssl_shim.@O@ pool.@O@ \
parseint.@O@ portset.@O@ quota.@O@ radix.@O@ random.@O@ \
- ratelimiter.@O@ refcount.@O@ region.@O@ regex.@O@ result.@O@ \
+ ratelimiter.@O@ region.@O@ regex.@O@ result.@O@ \
rwlock.@O@ \
serial.@O@ sha1.@O@ sha2.@O@ sockaddr.@O@ stats.@O@ \
string.@O@ strtoul.@O@ symtab.@O@ task.@O@ taskpool.@O@ \
md5.c mem.c mutexblock.c \
netaddr.c netscope.c nonce.c openssl_shim.c pool.c \
parseint.c portset.c quota.c radix.c random.c \
- ratelimiter.c refcount.c region.c regex.c result.c rwlock.c \
+ ratelimiter.c region.c regex.c result.c rwlock.c \
serial.c sha1.c sha2.c sockaddr.c stats.c string.c \
strtoul.c symtab.c task.c taskpool.c timer.c \
tm.c version.c
*/
/*
- * isc_result_t
+ * void
* isc_refcount_init(isc_refcount_t *ref, unsigned int n);
*
* Initialize the reference counter. There will be 'n' initial references.
#if defined(ISC_REFCOUNT_HAVESTDATOMIC)
+#define isc_refcount_init(rp, n) atomic_init(&(rp)->refs, n)
+
#define isc_refcount_current(rp) \
((unsigned int)(atomic_load_explicit(&(rp)->refs, \
memory_order_relaxed)))
#else /* ISC_REFCOUNT_HAVESTDATOMIC */
+#define isc_refcount_init(rp, n) isc_atomic_store(&(rp)->refs, n)
+
#define isc_refcount_current(rp) \
((unsigned int)(isc_atomic_xadd(&(rp)->refs, 0)))
#define isc_refcount_destroy(rp) ISC_REQUIRE(isc_refcount_current(rp) == 0)
isc_mutex_t lock;
} isc_refcount_t;
+#define isc_refcount_init(rp, n) \
+ do { \
+ REQUIRE(isc_mutex_init(&(rp)->lock) == ISC_R_SUCCESS); \
+ (rp)->refs = n; \
+ } while(0);
+
/*% Destroys a reference counter. */
#define isc_refcount_destroy(rp) \
do { \
int refs;
} isc_refcount_t;
+#define isc_refcount_init(rp, n) ((rp)->refs = n)
#define isc_refcount_destroy(rp) ISC_REQUIRE((rp)->refs == 0)
#define isc_refcount_current(rp) ((unsigned int)((rp)->refs))
#endif /* ISC_PLATFORM_USETHREADS */
-isc_result_t
-isc_refcount_init(isc_refcount_t *ref, unsigned int n);
-
ISC_LANG_ENDDECLS
#endif /* ISC_REFCOUNT_H */
+++ /dev/null
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * See the COPYRIGHT file distributed with this work for additional
- * information regarding copyright ownership.
- */
-
-
-#include <config.h>
-
-#include <stddef.h>
-
-#include <isc/mutex.h>
-#include <isc/refcount.h>
-#include <isc/result.h>
-#include <isc/util.h>
-
-isc_result_t
-isc_refcount_init(isc_refcount_t *ref, unsigned int n) {
- REQUIRE(ref != NULL);
-
- ref->refs = n;
-#if defined(ISC_PLATFORM_USETHREADS) && !defined(ISC_REFCOUNT_HAVEATOMIC)
- return (isc_mutex_init(&ref->lock));
-#else
- return (ISC_R_SUCCESS);
-#endif
-}
isc_ratelimiter_setpushpop
isc_ratelimiter_shutdown
isc_ratelimiter_stall
-isc_refcount_init
isc_regex_validate
isc_region_compare
isc_resource_getcurlimit
isc_result_t
cfg_aclconfctx_create(isc_mem_t *mctx, cfg_aclconfctx_t **ret) {
- isc_result_t result;
cfg_aclconfctx_t *actx;
REQUIRE(mctx != NULL);
if (actx == NULL)
return (ISC_R_NOMEMORY);
- result = isc_refcount_init(&actx->references, 1);
- if (result != ISC_R_SUCCESS)
- goto cleanup;
+ isc_refcount_init(&actx->references, 1);
actx->mctx = NULL;
isc_mem_attach(mctx, &actx->mctx);
*ret = actx;
return (ISC_R_SUCCESS);
-
- cleanup:
- isc_mem_put(mctx, actx, sizeof(*actx));
- return (result);
}
void
pctx->mctx = NULL;
isc_mem_attach(mctx, &pctx->mctx);
- result = isc_refcount_init(&pctx->references, 1);
- if (result != ISC_R_SUCCESS) {
- isc_mem_putanddetach(&pctx->mctx, pctx, sizeof(*pctx));
- return (result);
- }
+ isc_refcount_init(&pctx->references, 1);
pctx->lctx = lctx;
pctx->lexer = NULL;
isc_result_t
cfg_create_obj(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
- isc_result_t result;
cfg_obj_t *obj;
REQUIRE(pctx != NULL);
obj->line = pctx->line;
obj->pctx = pctx;
- result = isc_refcount_init(&obj->references, 1);
- if (result != ISC_R_SUCCESS) {
- isc_mem_put(pctx->mctx, obj, sizeof(cfg_obj_t));
- return (result);
- }
+ isc_refcount_init(&obj->references, 1);
+
*ret = obj;
return (ISC_R_SUCCESS);
isc_mem_attach(mctx, &sctx->mctx);
- result = isc_refcount_init(&sctx->references, 1);
- if (result != ISC_R_SUCCESS)
- goto cleanup;
+ isc_refcount_init(&sctx->references, 1);
CHECKFATAL(isc_quota_init(&sctx->xfroutquota, 10));
CHECKFATAL(isc_quota_init(&sctx->tcpquota, 10));
*sctxp = sctx;
return (ISC_R_SUCCESS);
-
- cleanup:
- isc_mem_putanddetach(&sctx->mctx, sctx, sizeof(*sctx));
-
- return (result);
}
void