mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 22:45:39 +00:00
lib/dns/ssu.c: use isc_refcount_t
This commit is contained in:
committed by
Witold Kręcicki
parent
38a973a33f
commit
2a57d0b00c
@@ -17,6 +17,7 @@
|
|||||||
#include <isc/mem.h>
|
#include <isc/mem.h>
|
||||||
#include <isc/netaddr.h>
|
#include <isc/netaddr.h>
|
||||||
#include <isc/print.h>
|
#include <isc/print.h>
|
||||||
|
#include <isc/refcount.h>
|
||||||
#include <isc/result.h>
|
#include <isc/result.h>
|
||||||
#include <isc/string.h>
|
#include <isc/string.h>
|
||||||
#include <isc/util.h>
|
#include <isc/util.h>
|
||||||
@@ -51,8 +52,7 @@ struct dns_ssurule {
|
|||||||
struct dns_ssutable {
|
struct dns_ssutable {
|
||||||
unsigned int magic;
|
unsigned int magic;
|
||||||
isc_mem_t *mctx;
|
isc_mem_t *mctx;
|
||||||
unsigned int references;
|
isc_refcount_t references;
|
||||||
isc_mutex_t lock;
|
|
||||||
dns_dlzdb_t *dlzdatabase;
|
dns_dlzdb_t *dlzdatabase;
|
||||||
ISC_LIST(dns_ssurule_t) rules;
|
ISC_LIST(dns_ssurule_t) rules;
|
||||||
};
|
};
|
||||||
@@ -65,10 +65,7 @@ dns_ssutable_create(isc_mem_t *mctx, dns_ssutable_t **tablep) {
|
|||||||
REQUIRE(mctx != NULL);
|
REQUIRE(mctx != NULL);
|
||||||
|
|
||||||
table = isc_mem_get(mctx, sizeof(dns_ssutable_t));
|
table = isc_mem_get(mctx, sizeof(dns_ssutable_t));
|
||||||
if (table == NULL)
|
isc_refcount_init(&table->references, 1);
|
||||||
return (ISC_R_NOMEMORY);
|
|
||||||
isc_mutex_init(&table->lock);
|
|
||||||
table->references = 1;
|
|
||||||
table->mctx = NULL;
|
table->mctx = NULL;
|
||||||
isc_mem_attach(mctx, &table->mctx);
|
isc_mem_attach(mctx, &table->mctx);
|
||||||
ISC_LIST_INIT(table->rules);
|
ISC_LIST_INIT(table->rules);
|
||||||
@@ -101,7 +98,7 @@ destroy(dns_ssutable_t *table) {
|
|||||||
rule->magic = 0;
|
rule->magic = 0;
|
||||||
isc_mem_put(mctx, rule, sizeof(dns_ssurule_t));
|
isc_mem_put(mctx, rule, sizeof(dns_ssurule_t));
|
||||||
}
|
}
|
||||||
isc_mutex_destroy(&table->lock);
|
isc_refcount_destroy(&table->references);
|
||||||
table->magic = 0;
|
table->magic = 0;
|
||||||
isc_mem_putanddetach(&table->mctx, table, sizeof(dns_ssutable_t));
|
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(VALID_SSUTABLE(source));
|
||||||
REQUIRE(targetp != NULL && *targetp == NULL);
|
REQUIRE(targetp != NULL && *targetp == NULL);
|
||||||
|
|
||||||
LOCK(&source->lock);
|
isc_refcount_increment(&source->references);
|
||||||
|
|
||||||
INSIST(source->references > 0);
|
|
||||||
source->references++;
|
|
||||||
INSIST(source->references != 0);
|
|
||||||
|
|
||||||
UNLOCK(&source->lock);
|
|
||||||
|
|
||||||
*targetp = source;
|
*targetp = source;
|
||||||
}
|
}
|
||||||
@@ -125,23 +116,15 @@ dns_ssutable_attach(dns_ssutable_t *source, dns_ssutable_t **targetp) {
|
|||||||
void
|
void
|
||||||
dns_ssutable_detach(dns_ssutable_t **tablep) {
|
dns_ssutable_detach(dns_ssutable_t **tablep) {
|
||||||
dns_ssutable_t *table;
|
dns_ssutable_t *table;
|
||||||
bool done = false;
|
|
||||||
|
|
||||||
REQUIRE(tablep != NULL);
|
REQUIRE(tablep != NULL);
|
||||||
table = *tablep;
|
table = *tablep;
|
||||||
REQUIRE(VALID_SSUTABLE(table));
|
REQUIRE(VALID_SSUTABLE(table));
|
||||||
|
|
||||||
LOCK(&table->lock);
|
|
||||||
|
|
||||||
INSIST(table->references > 0);
|
|
||||||
if (--table->references == 0)
|
|
||||||
done = true;
|
|
||||||
UNLOCK(&table->lock);
|
|
||||||
|
|
||||||
*tablep = NULL;
|
*tablep = NULL;
|
||||||
|
|
||||||
if (done)
|
if (isc_refcount_decrement(&table->references) == 1) {
|
||||||
destroy(table);
|
destroy(table);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
|
Reference in New Issue
Block a user