Improve qp-trie refcount debugging

Add some qp-trie tracing macros which can be enabled by a
developer. These print a message when a leaf is attached or
detached, indicating which part of the qp-trie implementation
did so. The refcount methods must now return the refcount value
so it can be printed by the trace macros.
This commit is contained in:
Tony Finch
2023-02-17 18:28:24 +00:00
parent 7dcde5d2fc
commit a8b29f0365
7 changed files with 57 additions and 20 deletions

View File

@@ -37,10 +37,11 @@ struct {
dns_fixedname_t fixed;
} item[1024 * 1024];
static void
static uint32_t
item_check(void *ctx, void *pval, uint32_t ival) {
UNUSED(ctx);
assert(pval == &item[ival]);
return (1);
}
static size_t

View File

@@ -95,17 +95,19 @@ qpkey_from_smallname(dns_qpkey_t key, void *ctx, void *pval, uint32_t ival) {
return (dns_qpkey_fromname(key, &name));
}
static void
static uint32_t
smallname_attach(void *ctx, void *pval, uint32_t ival) {
UNUSED(ctx);
isc_refcount_increment0(smallname_refcount(pval, ival));
return (isc_refcount_increment0(smallname_refcount(pval, ival)));
}
static void
static uint32_t
smallname_detach(void *ctx, void *pval, uint32_t ival) {
if (isc_refcount_decrement(smallname_refcount(pval, ival)) == 1) {
uint32_t refs = isc_refcount_decrement(smallname_refcount(pval, ival));
if (refs == 1) {
isc_mem_free(ctx, pval);
}
return (refs);
}
static void

View File

@@ -89,11 +89,12 @@ static struct {
dns_qpkey_t key;
} *item;
static void
static uint32_t
item_refcount(void *ctx, void *pval, uint32_t ival) {
UNUSED(ctx);
UNUSED(pval);
UNUSED(ival);
return (1);
}
static size_t

View File

@@ -104,18 +104,19 @@ static struct {
dns_qpkey_t ascii;
} item[ITEM_COUNT];
static void
static uint32_t
item_attach(void *ctx, void *pval, uint32_t ival) {
INSIST(ctx == NULL);
INSIST(pval == &item[ival]);
item[ival].refcount++;
assert_null(ctx);
assert_ptr_equal(pval, &item[ival]);
return (item[ival].refcount++);
}
static void
static uint32_t
item_detach(void *ctx, void *pval, uint32_t ival) {
assert_null(ctx);
assert_ptr_equal(pval, &item[ival]);
item[ival].refcount--;
assert_int_not_equal(item[ival].refcount, 0);
return (item[ival].refcount--);
}
static size_t