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

dns/stats.c: use isc_refcount_t

This commit is contained in:
Witold Kręcicki
2019-05-17 13:35:51 +02:00
parent de73904d03
commit 44e2088449

View File

@@ -17,6 +17,7 @@
#include <isc/magic.h>
#include <isc/mem.h>
#include <isc/refcount.h>
#include <isc/stats.h>
#include <isc/util.h>
@@ -64,15 +65,11 @@ enum {
};
struct dns_stats {
/*% Unlocked */
unsigned int magic;
dns_statstype_t type;
isc_mem_t *mctx;
isc_mutex_t lock;
isc_stats_t *counters;
/*% Locked by lock */
unsigned int references;
isc_refcount_t references;
};
typedef struct rdatadumparg {
@@ -99,9 +96,7 @@ dns_stats_attach(dns_stats_t *stats, dns_stats_t **statsp) {
REQUIRE(DNS_STATS_VALID(stats));
REQUIRE(statsp != NULL && *statsp == NULL);
LOCK(&stats->lock);
stats->references++;
UNLOCK(&stats->lock);
isc_refcount_increment(&stats->references);
*statsp = stats;
}
@@ -115,13 +110,8 @@ dns_stats_detach(dns_stats_t **statsp) {
stats = *statsp;
*statsp = NULL;
LOCK(&stats->lock);
stats->references--;
UNLOCK(&stats->lock);
if (stats->references == 0) {
if (isc_refcount_decrement(&stats->references) == 1) {
isc_stats_detach(&stats->counters);
isc_mutex_destroy(&stats->lock);
isc_mem_putanddetach(&stats->mctx, stats, sizeof(*stats));
}
}
@@ -141,9 +131,7 @@ create_stats(isc_mem_t *mctx, dns_statstype_t type, int ncounters,
return (ISC_R_NOMEMORY);
stats->counters = NULL;
stats->references = 1;
isc_mutex_init(&stats->lock);
isc_refcount_init(&stats->references, 1);
result = isc_stats_create(mctx, &stats->counters, ncounters);
if (result != ISC_R_SUCCESS)
@@ -158,7 +146,6 @@ create_stats(isc_mem_t *mctx, dns_statstype_t type, int ncounters,
return (ISC_R_SUCCESS);
clean_mutex:
isc_mutex_destroy(&stats->lock);
isc_mem_put(mctx, stats, sizeof(*stats));
return (result);