Add debugging to object lifecycle

This commit is contained in:
Behdad Esfahbod 2009-11-05 19:37:58 -05:00
parent 25edb940ab
commit 799b3c375a
1 changed files with 18 additions and 0 deletions

View File

@ -31,6 +31,21 @@
#define HB_REFCOUNT_PRIVATE_H #define HB_REFCOUNT_PRIVATE_H
#ifndef HB_DEBUG_OBJECT
#define HB_DEBUG_OBJECT HB_DEBUG
#endif
#if HB_DEBUG_OBJECT
#include <stdio.h>
#define HB_OBJECT_DEBUG_OUT(obj) fprintf (stderr, "%p refcount=%d %s\n", \
obj, \
HB_REFERENCE_COUNT_GET_VALUE (obj->ref_count), \
__FUNCTION__)
#else
#define HB_OBJECT_DEBUG_OUT(obj) 0
#endif
/* Encapsulate operations on the object's reference count */ /* Encapsulate operations on the object's reference count */
typedef struct { typedef struct {
hb_atomic_int_t ref_count; hb_atomic_int_t ref_count;
@ -70,6 +85,7 @@ typedef struct {
HB_LIKELY (( \ HB_LIKELY (( \
(obj) = (Type *) calloc (1, sizeof (Type)), \ (obj) = (Type *) calloc (1, sizeof (Type)), \
HB_OBJECT_DO_INIT_EXPR (obj), \ HB_OBJECT_DO_INIT_EXPR (obj), \
HB_OBJECT_DEBUG_OUT (obj), \
(obj) \ (obj) \
)) ))
@ -78,6 +94,7 @@ typedef struct {
int old_count; \ int old_count; \
if (HB_UNLIKELY (!(obj) || HB_OBJECT_IS_INERT (obj))) \ if (HB_UNLIKELY (!(obj) || HB_OBJECT_IS_INERT (obj))) \
return obj; \ return obj; \
HB_OBJECT_DEBUG_OUT (obj); \
old_count = hb_reference_count_inc (obj->ref_count); \ old_count = hb_reference_count_inc (obj->ref_count); \
assert (old_count > 0); \ assert (old_count > 0); \
return obj; \ return obj; \
@ -95,6 +112,7 @@ typedef struct {
int old_count; \ int old_count; \
if (HB_UNLIKELY (!(obj) || HB_OBJECT_IS_INERT (obj))) \ if (HB_UNLIKELY (!(obj) || HB_OBJECT_IS_INERT (obj))) \
return; \ return; \
HB_OBJECT_DEBUG_OUT (obj); \
old_count = hb_reference_count_dec (obj->ref_count); \ old_count = hb_reference_count_dec (obj->ref_count); \
assert (old_count > 0); \ assert (old_count > 0); \
if (old_count != 1) \ if (old_count != 1) \