2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

lib/dns/ssu.c: use isc_refcount_t

This commit is contained in:
Ondřej Surý
2019-05-20 16:54:46 +02:00
committed by Witold Kręcicki
parent 38a973a33f
commit 2a57d0b00c

View File

@@ -17,6 +17,7 @@
#include <isc/mem.h>
#include <isc/netaddr.h>
#include <isc/print.h>
#include <isc/refcount.h>
#include <isc/result.h>
#include <isc/string.h>
#include <isc/util.h>
@@ -51,8 +52,7 @@ struct dns_ssurule {
struct dns_ssutable {
unsigned int magic;
isc_mem_t *mctx;
unsigned int references;
isc_mutex_t lock;
isc_refcount_t references;
dns_dlzdb_t *dlzdatabase;
ISC_LIST(dns_ssurule_t) rules;
};
@@ -65,10 +65,7 @@ dns_ssutable_create(isc_mem_t *mctx, dns_ssutable_t **tablep) {
REQUIRE(mctx != NULL);
table = isc_mem_get(mctx, sizeof(dns_ssutable_t));
if (table == NULL)
return (ISC_R_NOMEMORY);
isc_mutex_init(&table->lock);
table->references = 1;
isc_refcount_init(&table->references, 1);
table->mctx = NULL;
isc_mem_attach(mctx, &table->mctx);
ISC_LIST_INIT(table->rules);
@@ -101,7 +98,7 @@ destroy(dns_ssutable_t *table) {
rule->magic = 0;
isc_mem_put(mctx, rule, sizeof(dns_ssurule_t));
}
isc_mutex_destroy(&table->lock);
isc_refcount_destroy(&table->references);
table->magic = 0;
isc_mem_putanddetach(&table->mctx, table, sizeof(dns_ssutable_t));
}
@@ -111,13 +108,7 @@ dns_ssutable_attach(dns_ssutable_t *source, dns_ssutable_t **targetp) {
REQUIRE(VALID_SSUTABLE(source));
REQUIRE(targetp != NULL && *targetp == NULL);
LOCK(&source->lock);
INSIST(source->references > 0);
source->references++;
INSIST(source->references != 0);
UNLOCK(&source->lock);
isc_refcount_increment(&source->references);
*targetp = source;
}
@@ -125,23 +116,15 @@ dns_ssutable_attach(dns_ssutable_t *source, dns_ssutable_t **targetp) {
void
dns_ssutable_detach(dns_ssutable_t **tablep) {
dns_ssutable_t *table;
bool done = false;
REQUIRE(tablep != NULL);
table = *tablep;
REQUIRE(VALID_SSUTABLE(table));
LOCK(&table->lock);
INSIST(table->references > 0);
if (--table->references == 0)
done = true;
UNLOCK(&table->lock);
*tablep = NULL;
if (done)
if (isc_refcount_decrement(&table->references) == 1) {
destroy(table);
}
}
isc_result_t