/* Unlocked. */
unsigned int magic;
isc_mem_t *mctx;
- isc_refcount_t active_nodes;
+ atomic_uint_fast32_t active_nodes;
isc_refcount_t references;
isc_rwlock_t rwlock;
/* Locked by rwlock. */
goto cleanup_rbt;
}
- isc_refcount_init(&keytable->active_nodes, 0);
+ atomic_init(&keytable->active_nodes, 0);
isc_refcount_init(&keytable->references, 1);
keytable->mctx = NULL;
if (isc_refcount_decrement(&keytable->references) == 1) {
isc_refcount_destroy(&keytable->references);
- isc_refcount_destroy(&keytable->active_nodes);
+ REQUIRE(atomic_load_acquire(&keytable->active_nodes) == 0);
dns_rbt_destroy(&keytable->table);
isc_rwlock_destroy(&keytable->rwlock);
keytable->magic = 0;
DNS_RBTFIND_NOOPTIONS, NULL, NULL);
if (result == ISC_R_SUCCESS) {
if (node->data != NULL) {
- isc_refcount_increment0(&keytable->active_nodes);
- dns_keynode_attach(node->data, keynodep);
- } else
+ dns_keytable_attachkeynode(keytable, node->data,
+ keynodep);
+ } else {
result = ISC_R_NOTFOUND;
- } else if (result == DNS_R_PARTIALMATCH)
+ }
+ } else if (result == DNS_R_PARTIALMATCH) {
result = ISC_R_NOTFOUND;
+ }
RWUNLOCK(&keytable->rwlock, isc_rwlocktype_read);
return (result);
return (ISC_R_NOTFOUND);
}
- dns_keynode_attach(keynode->next, nextnodep);
- isc_refcount_increment(&keytable->active_nodes);
+ dns_keytable_attachkeynode(keytable, keynode->next, nextnodep);
return (ISC_R_SUCCESS);
}
}
}
if (knode != NULL) {
- isc_refcount_increment0(&keytable->active_nodes);
- dns_keynode_attach(knode, keynodep);
+ dns_keytable_attachkeynode(keytable, knode, keynodep);
} else {
result = DNS_R_PARTIALMATCH;
}
}
}
if (knode != NULL) {
- isc_refcount_increment(&keytable->active_nodes);
+ dns_keytable_attachkeynode(keytable, knode, nextnodep);
result = ISC_R_SUCCESS;
- dns_keynode_attach(knode, nextnodep);
} else {
result = ISC_R_NOTFOUND;
}
REQUIRE(VALID_KEYNODE(source));
REQUIRE(target != NULL && *target == NULL);
- isc_refcount_increment(&keytable->active_nodes);
+ REQUIRE(atomic_fetch_add_relaxed(&keytable->active_nodes, 1) < UINT32_MAX);
dns_keynode_attach(source, target);
}
REQUIRE(VALID_KEYTABLE(keytable));
REQUIRE(keynodep != NULL && VALID_KEYNODE(*keynodep));
- INSIST(isc_refcount_decrement(&keytable->active_nodes) > 0);
+ REQUIRE(atomic_fetch_sub_release(&keytable->active_nodes, 1) > 0);
+
dns_keynode_detach(keytable->mctx, keynodep);
}
}
goto cleanup;
}
- isc_refcount_increment0(&keytable->active_nodes);
+ REQUIRE(atomic_fetch_add_relaxed(&keytable->active_nodes, 1)
+ < UINT32_MAX);
for (;;) {
dns_rbtnodechain_current(&chain, foundname, origin, &node);
if (node->data != NULL) {
break;
}
}
- INSIST(isc_refcount_decrement(&keytable->active_nodes) > 0);
+ REQUIRE(atomic_fetch_sub_release(&keytable->active_nodes, 1) > 0);
cleanup:
dns_rbtnodechain_invalidate(&chain);