Mesa (master): util: Make the reference debuggin code more C++ friendly.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Sat Aug 21 09:38:55 UTC 2010


Module: Mesa
Branch: master
Commit: 04c2a22175d7c27ee380f986eece2772eddd6fcc
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=04c2a22175d7c27ee380f986eece2772eddd6fcc

Author: José Fonseca <jfonseca at vmware.com>
Date:   Sat Aug 21 10:34:42 2010 +0100

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

C++ doesn't accept function <-> void* conversions without a putting a
fight.

---

 src/gallium/auxiliary/util/u_debug_describe.h |    5 +++++
 src/gallium/auxiliary/util/u_debug_refcnt.c   |    3 +--
 src/gallium/auxiliary/util/u_debug_refcnt.h   |   19 +++++++++++++------
 src/gallium/auxiliary/util/u_inlines.h        |   16 +++++++++++-----
 4 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_debug_describe.h b/src/gallium/auxiliary/util/u_debug_describe.h
index 8c32f02..33587ec 100644
--- a/src/gallium/auxiliary/util/u_debug_describe.h
+++ b/src/gallium/auxiliary/util/u_debug_describe.h
@@ -5,6 +5,11 @@
 extern "C" {
 #endif
 
+struct pipe_reference;
+struct pipe_resource;
+struct pipe_surface;
+struct pipe_sampler_view;
+
 /* a 256-byte buffer is necessary and sufficient */
 void debug_describe_reference(char* buf, const struct pipe_reference*ptr);
 void debug_describe_resource(char* buf, const struct pipe_resource *ptr);
diff --git a/src/gallium/auxiliary/util/u_debug_refcnt.c b/src/gallium/auxiliary/util/u_debug_refcnt.c
index 9d6fca5..32e09ae 100644
--- a/src/gallium/auxiliary/util/u_debug_refcnt.c
+++ b/src/gallium/auxiliary/util/u_debug_refcnt.c
@@ -84,7 +84,7 @@ static void dump_stack(const char* symbols[STACK_LEN])
    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)
       return;
@@ -107,7 +107,6 @@ void debug_reference_slowpath(const struct pipe_reference* p, void* pget_desc, i
       const char* symbols[STACK_LEN];
       char buf[1024];
 
-      void (*get_desc)(char*, const struct pipe_reference*) = pget_desc;
       unsigned i;
       unsigned refcnt = p->count;
       unsigned serial;
diff --git a/src/gallium/auxiliary/util/u_debug_refcnt.h b/src/gallium/auxiliary/util/u_debug_refcnt.h
index ba40999..4c4a18e 100644
--- a/src/gallium/auxiliary/util/u_debug_refcnt.h
+++ b/src/gallium/auxiliary/util/u_debug_refcnt.h
@@ -15,19 +15,26 @@
 extern "C" {
 #endif
 
+typedef void (*debug_reference_descriptor)(char*, const struct pipe_reference*);
+
 #if defined(DEBUG) && (!defined(PIPE_OS_WINDOWS) || defined(PIPE_SUBSYSTEM_WINDOWS_USER))
+
 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)
-		debug_reference_slowpath(p, get_desc, change);
+   if (debug_refcnt_state >= 0)
+      debug_reference_slowpath(p, get_desc, change);
 }
+
 #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
 
 #ifdef __cplusplus
diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h
index 90b0903..78473bf 100644
--- a/src/gallium/auxiliary/util/u_inlines.h
+++ b/src/gallium/auxiliary/util/u_inlines.h
@@ -69,7 +69,9 @@ pipe_is_referenced(struct pipe_reference *reference)
  * \return TRUE if the object's refcount hits zero and should be destroyed.
  */
 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;
 
@@ -96,7 +98,8 @@ pipe_reference_described(struct pipe_reference *ptr, struct pipe_reference *refe
 static INLINE boolean
 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
@@ -104,7 +107,8 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf)
 {
    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);
    *ptr = surf;
 }
@@ -114,7 +118,8 @@ pipe_resource_reference(struct pipe_resource **ptr, struct pipe_resource *tex)
 {
    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);
    *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;
 
-   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);
    *ptr = view;
 }




More information about the mesa-commit mailing list