mirror of
https://github.com/isc-projects/bind9.git
synced 2026-02-25 10:59:35 -05:00
isc/stats: use isc_refcount_t
This commit is contained in:
parent
420f84f3f5
commit
3fcf98c8d3
1 changed files with 5 additions and 18 deletions
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include <isc/magic.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/refcount.h>
|
||||
#include <isc/stats.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
|
|
@ -22,14 +23,10 @@
|
|||
#define NS_STATS_VALID(x) ISC_MAGIC_VALID(x, NS_STATS_MAGIC)
|
||||
|
||||
struct ns_stats {
|
||||
/*% Unlocked */
|
||||
unsigned int magic;
|
||||
isc_mem_t *mctx;
|
||||
isc_mutex_t lock;
|
||||
isc_stats_t *counters;
|
||||
|
||||
/*% Locked by lock */
|
||||
unsigned int references;
|
||||
isc_refcount_t references;
|
||||
};
|
||||
|
||||
void
|
||||
|
|
@ -37,9 +34,7 @@ ns_stats_attach(ns_stats_t *stats, ns_stats_t **statsp) {
|
|||
REQUIRE(NS_STATS_VALID(stats));
|
||||
REQUIRE(statsp != NULL && *statsp == NULL);
|
||||
|
||||
LOCK(&stats->lock);
|
||||
stats->references++;
|
||||
UNLOCK(&stats->lock);
|
||||
isc_refcount_increment(&stats->references);
|
||||
|
||||
*statsp = stats;
|
||||
}
|
||||
|
|
@ -53,13 +48,8 @@ ns_stats_detach(ns_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));
|
||||
}
|
||||
}
|
||||
|
|
@ -76,9 +66,7 @@ ns_stats_create(isc_mem_t *mctx, int ncounters, ns_stats_t **statsp) {
|
|||
return (ISC_R_NOMEMORY);
|
||||
|
||||
stats->counters = NULL;
|
||||
stats->references = 1;
|
||||
|
||||
isc_mutex_init(&stats->lock);
|
||||
atomic_init(&stats->references, 1);
|
||||
|
||||
result = isc_stats_create(mctx, &stats->counters, ncounters);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
|
|
@ -92,7 +80,6 @@ ns_stats_create(isc_mem_t *mctx, int ncounters, ns_stats_t **statsp) {
|
|||
return (ISC_R_SUCCESS);
|
||||
|
||||
clean_mutex:
|
||||
isc_mutex_destroy(&stats->lock);
|
||||
isc_mem_put(mctx, stats, sizeof(*stats));
|
||||
|
||||
return (result);
|
||||
|
|
|
|||
Loading…
Reference in a new issue