Skip to content

Commit

Permalink
Add peek() debug method to fetch current counter value for debug
Browse files Browse the repository at this point in the history
purposes.
  • Loading branch information
sobomax committed Sep 10, 2024
1 parent 29f92f9 commit 6563e75
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/rtpp_refcnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ static void rtpp_refcnt_use_stdfree(struct rtpp_refcnt *, void *);

#if RTPP_DEBUG_refcnt
static void rtpp_refcnt_traceen(struct rtpp_refcnt *, HERETYPE);
static int rtpp_refcnt_peek(struct rtpp_refcnt *);
#endif

DEFINE_SMETHODS(rtpp_refcnt,
Expand All @@ -96,6 +97,7 @@ DEFINE_SMETHODS(rtpp_refcnt,
.reg_pd = &rtpp_refcnt_reg_pd,
#if RTPP_DEBUG_refcnt
.traceen = rtpp_refcnt_traceen,
.peek = rtpp_refcnt_peek,
#endif
.attach = &rtpp_refcnt_attach,
.use_stdfree = &rtpp_refcnt_use_stdfree,
Expand Down Expand Up @@ -300,6 +302,15 @@ rtpp_refcnt_traceen(struct rtpp_refcnt *pub, HERETYPE mlp)
int oldcnt = atomic_load_explicit(&pvt->cnt, memory_order_relaxed);
fprintf(stderr, CODEPTR_FMT(": rtpp_refcnt(%p, %u).traceen()\n", mlp, pub, oldcnt));
}

static int
rtpp_refcnt_peek(struct rtpp_refcnt *pub)
{
struct rtpp_refcnt_priv *pvt;

PUB2PVT(pub, pvt);
return atomic_load_explicit(&pvt->cnt, memory_order_relaxed);
}
#endif

static void
Expand Down
2 changes: 2 additions & 0 deletions src/rtpp_refcnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ DECLARE_METHOD(rtpp_refcnt, refcnt_reg_pd, void, rtpp_refcnt_dtor_t, void *);
DECLARE_METHOD(rtpp_refcnt, refcnt_attach, void, rtpp_refcnt_dtor_t, void *);
DECLARE_METHOD(rtpp_refcnt, refcnt_traceen, void, const struct rtpp_codeptr *);
DECLARE_METHOD(rtpp_refcnt, refcnt_use_stdfree, void, void *);
DECLARE_METHOD(rtpp_refcnt, refcnt_peek, int);

DECLARE_SMETHODS(rtpp_refcnt)
{
Expand All @@ -50,6 +51,7 @@ DECLARE_SMETHODS(rtpp_refcnt)
METHOD_ENTRY(refcnt_attach, attach);
METHOD_ENTRY(refcnt_traceen, traceen);
METHOD_ENTRY(refcnt_use_stdfree, use_stdfree);
METHOD_ENTRY(refcnt_peek, peek);
};

struct rtpp_refcnt
Expand Down

0 comments on commit 6563e75

Please sign in to comment.