util: Make the reference debuggin code more C++ friendly.

C++ doesn't accept function <-> void* conversions without a putting a
fight.
This commit is contained in:
José Fonseca 2010-08-21 10:34:42 +01:00
parent 7a40d15e6c
commit 04c2a22175
4 changed files with 30 additions and 13 deletions

View File

@ -5,6 +5,11 @@
extern "C" { extern "C" {
#endif #endif
struct pipe_reference;
struct pipe_resource;
struct pipe_surface;
struct pipe_sampler_view;
/* a 256-byte buffer is necessary and sufficient */ /* a 256-byte buffer is necessary and sufficient */
void debug_describe_reference(char* buf, const struct pipe_reference*ptr); void debug_describe_reference(char* buf, const struct pipe_reference*ptr);
void debug_describe_resource(char* buf, const struct pipe_resource *ptr); void debug_describe_resource(char* buf, const struct pipe_resource *ptr);

View File

@ -84,7 +84,7 @@ static void dump_stack(const char* symbols[STACK_LEN])
os_stream_write(stream, "\n", 1); os_stream_write(stream, "\n", 1);
} }
void debug_reference_slowpath(const struct pipe_reference* p, void* pget_desc, int change) void debug_reference_slowpath(const struct pipe_reference* p, debug_reference_descriptor get_desc, int change)
{ {
if(debug_refcnt_state < 0) if(debug_refcnt_state < 0)
return; return;
@ -107,7 +107,6 @@ void debug_reference_slowpath(const struct pipe_reference* p, void* pget_desc, i
const char* symbols[STACK_LEN]; const char* symbols[STACK_LEN];
char buf[1024]; char buf[1024];
void (*get_desc)(char*, const struct pipe_reference*) = pget_desc;
unsigned i; unsigned i;
unsigned refcnt = p->count; unsigned refcnt = p->count;
unsigned serial; unsigned serial;

View File

@ -15,19 +15,26 @@
extern "C" { extern "C" {
#endif #endif
typedef void (*debug_reference_descriptor)(char*, const struct pipe_reference*);
#if defined(DEBUG) && (!defined(PIPE_OS_WINDOWS) || defined(PIPE_SUBSYSTEM_WINDOWS_USER)) #if defined(DEBUG) && (!defined(PIPE_OS_WINDOWS) || defined(PIPE_SUBSYSTEM_WINDOWS_USER))
extern int debug_refcnt_state; extern int debug_refcnt_state;
void debug_reference_slowpath(const struct pipe_reference* p, void* get_desc, int change); void debug_reference_slowpath(const struct pipe_reference* p, debug_reference_descriptor get_desc, int change);
static INLINE void debug_reference(const struct pipe_reference* p, void* get_desc, int change) static INLINE void debug_reference(const struct pipe_reference* p, debug_reference_descriptor get_desc, int change)
{ {
if(debug_refcnt_state >= 0) if (debug_refcnt_state >= 0)
debug_reference_slowpath(p, get_desc, change); debug_reference_slowpath(p, get_desc, change);
} }
#else #else
static INLINE void debug_reference(const struct pipe_reference* p, void* get_desc, const char* op)
{} static INLINE void debug_reference(const struct pipe_reference* p, debug_reference_descriptor get_desc, int change)
{
}
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -69,7 +69,9 @@ pipe_is_referenced(struct pipe_reference *reference)
* \return TRUE if the object's refcount hits zero and should be destroyed. * \return TRUE if the object's refcount hits zero and should be destroyed.
*/ */
static INLINE boolean static INLINE boolean
pipe_reference_described(struct pipe_reference *ptr, struct pipe_reference *reference, void* get_desc) pipe_reference_described(struct pipe_reference *ptr,
struct pipe_reference *reference,
debug_reference_descriptor get_desc)
{ {
boolean destroy = FALSE; boolean destroy = FALSE;
@ -96,7 +98,8 @@ pipe_reference_described(struct pipe_reference *ptr, struct pipe_reference *refe
static INLINE boolean static INLINE boolean
pipe_reference(struct pipe_reference *ptr, struct pipe_reference *reference) pipe_reference(struct pipe_reference *ptr, struct pipe_reference *reference)
{ {
return pipe_reference_described(ptr, reference, debug_describe_reference); return pipe_reference_described(ptr, reference,
(debug_reference_descriptor)debug_describe_reference);
} }
static INLINE void static INLINE void
@ -104,7 +107,8 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf)
{ {
struct pipe_surface *old_surf = *ptr; struct pipe_surface *old_surf = *ptr;
if (pipe_reference_described(&(*ptr)->reference, &surf->reference, debug_describe_surface)) if (pipe_reference_described(&(*ptr)->reference, &surf->reference,
(debug_reference_descriptor)debug_describe_surface))
old_surf->texture->screen->tex_surface_destroy(old_surf); old_surf->texture->screen->tex_surface_destroy(old_surf);
*ptr = surf; *ptr = surf;
} }
@ -114,7 +118,8 @@ pipe_resource_reference(struct pipe_resource **ptr, struct pipe_resource *tex)
{ {
struct pipe_resource *old_tex = *ptr; struct pipe_resource *old_tex = *ptr;
if (pipe_reference_described(&(*ptr)->reference, &tex->reference, debug_describe_resource)) if (pipe_reference_described(&(*ptr)->reference, &tex->reference,
(debug_reference_descriptor)debug_describe_resource))
old_tex->screen->resource_destroy(old_tex->screen, old_tex); old_tex->screen->resource_destroy(old_tex->screen, old_tex);
*ptr = tex; *ptr = tex;
} }
@ -124,7 +129,8 @@ pipe_sampler_view_reference(struct pipe_sampler_view **ptr, struct pipe_sampler_
{ {
struct pipe_sampler_view *old_view = *ptr; struct pipe_sampler_view *old_view = *ptr;
if (pipe_reference_described(&(*ptr)->reference, &view->reference, debug_describe_sampler_view)) if (pipe_reference_described(&(*ptr)->reference, &view->reference,
(debug_reference_descriptor)debug_describe_sampler_view))
old_view->context->sampler_view_destroy(old_view->context, old_view); old_view->context->sampler_view_destroy(old_view->context, old_view);
*ptr = view; *ptr = view;
} }