mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-01 06:55:30 +00:00
dns/stats.c: use isc_refcount_t
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <isc/magic.h>
|
#include <isc/magic.h>
|
||||||
#include <isc/mem.h>
|
#include <isc/mem.h>
|
||||||
|
#include <isc/refcount.h>
|
||||||
#include <isc/stats.h>
|
#include <isc/stats.h>
|
||||||
#include <isc/util.h>
|
#include <isc/util.h>
|
||||||
|
|
||||||
@@ -64,15 +65,11 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct dns_stats {
|
struct dns_stats {
|
||||||
/*% Unlocked */
|
|
||||||
unsigned int magic;
|
unsigned int magic;
|
||||||
dns_statstype_t type;
|
dns_statstype_t type;
|
||||||
isc_mem_t *mctx;
|
isc_mem_t *mctx;
|
||||||
isc_mutex_t lock;
|
|
||||||
isc_stats_t *counters;
|
isc_stats_t *counters;
|
||||||
|
isc_refcount_t references;
|
||||||
/*% Locked by lock */
|
|
||||||
unsigned int references;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct rdatadumparg {
|
typedef struct rdatadumparg {
|
||||||
@@ -99,9 +96,7 @@ dns_stats_attach(dns_stats_t *stats, dns_stats_t **statsp) {
|
|||||||
REQUIRE(DNS_STATS_VALID(stats));
|
REQUIRE(DNS_STATS_VALID(stats));
|
||||||
REQUIRE(statsp != NULL && *statsp == NULL);
|
REQUIRE(statsp != NULL && *statsp == NULL);
|
||||||
|
|
||||||
LOCK(&stats->lock);
|
isc_refcount_increment(&stats->references);
|
||||||
stats->references++;
|
|
||||||
UNLOCK(&stats->lock);
|
|
||||||
|
|
||||||
*statsp = stats;
|
*statsp = stats;
|
||||||
}
|
}
|
||||||
@@ -115,13 +110,8 @@ dns_stats_detach(dns_stats_t **statsp) {
|
|||||||
stats = *statsp;
|
stats = *statsp;
|
||||||
*statsp = NULL;
|
*statsp = NULL;
|
||||||
|
|
||||||
LOCK(&stats->lock);
|
if (isc_refcount_decrement(&stats->references) == 1) {
|
||||||
stats->references--;
|
|
||||||
UNLOCK(&stats->lock);
|
|
||||||
|
|
||||||
if (stats->references == 0) {
|
|
||||||
isc_stats_detach(&stats->counters);
|
isc_stats_detach(&stats->counters);
|
||||||
isc_mutex_destroy(&stats->lock);
|
|
||||||
isc_mem_putanddetach(&stats->mctx, stats, sizeof(*stats));
|
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);
|
return (ISC_R_NOMEMORY);
|
||||||
|
|
||||||
stats->counters = NULL;
|
stats->counters = NULL;
|
||||||
stats->references = 1;
|
isc_refcount_init(&stats->references, 1);
|
||||||
|
|
||||||
isc_mutex_init(&stats->lock);
|
|
||||||
|
|
||||||
result = isc_stats_create(mctx, &stats->counters, ncounters);
|
result = isc_stats_create(mctx, &stats->counters, ncounters);
|
||||||
if (result != ISC_R_SUCCESS)
|
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);
|
return (ISC_R_SUCCESS);
|
||||||
|
|
||||||
clean_mutex:
|
clean_mutex:
|
||||||
isc_mutex_destroy(&stats->lock);
|
|
||||||
isc_mem_put(mctx, stats, sizeof(*stats));
|
isc_mem_put(mctx, stats, sizeof(*stats));
|
||||||
|
|
||||||
return (result);
|
return (result);
|
||||||
|
Reference in New Issue
Block a user