X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fauxiliary%2Futil%2Fu_debug_refcnt.c;h=f849e59cb3e9e6069dfd609076d32fff4d3b7328;hb=2d6059d8877aed82f4a1a5fac10bca80bdf6ab0e;hp=0a4786442fc080e10f84916dfac738293f1b1909;hpb=9e6a6bd575fb71d13d8cc384a128b232910658a4;p=mesa.git diff --git a/src/gallium/auxiliary/util/u_debug_refcnt.c b/src/gallium/auxiliary/util/u_debug_refcnt.c index 0a4786442fc..f849e59cb3e 100644 --- a/src/gallium/auxiliary/util/u_debug_refcnt.c +++ b/src/gallium/auxiliary/util/u_debug_refcnt.c @@ -44,6 +44,7 @@ #include "util/u_string.h" #include "util/u_hash_table.h" #include "os/os_thread.h" +#include "pipe/p_config.h" int debug_refcnt_state; @@ -52,31 +53,12 @@ static FILE *stream; /* TODO: maybe move this serial machinery to a stand-alone module and * expose it? */ -pipe_static_mutex(serials_mutex); +static mtx_t serials_mutex = _MTX_INITIALIZER_NP; -static struct util_hash_table *serials_hash; +static struct hash_table *serials_hash; static unsigned serials_last; -static unsigned -hash_ptr(void *p) -{ - return (unsigned) (uintptr_t) p; -} - - -static int -compare_ptr(void *a, void *b) -{ - if (a == b) - return 0; - else if (a < b) - return -1; - else - return 1; -} - - /** * Return a small integer serial number for the given pointer. */ @@ -85,18 +67,18 @@ debug_serial(void *p, unsigned *pserial) { unsigned serial; boolean found = TRUE; -#ifdef PIPE_SUBSYSTEM_WINDOWS_USER +#ifdef PIPE_OS_WINDOWS static boolean first = TRUE; if (first) { - pipe_mutex_init(serials_mutex); + (void) mtx_init(&serials_mutex, mtx_plain); first = FALSE; } #endif - pipe_mutex_lock(serials_mutex); + mtx_lock(&serials_mutex); if (!serials_hash) - serials_hash = util_hash_table_create(hash_ptr, compare_ptr); + serials_hash = util_hash_table_create_ptr_keys(); serial = (unsigned) (uintptr_t) util_hash_table_get(serials_hash, p); if (!serial) { @@ -109,10 +91,10 @@ debug_serial(void *p, unsigned *pserial) os_abort(); } - util_hash_table_set(serials_hash, p, (void *) (uintptr_t) serial); + _mesa_hash_table_insert(serials_hash, p, (void *) (uintptr_t) serial); found = FALSE; } - pipe_mutex_unlock(serials_mutex); + mtx_unlock(&serials_mutex); *pserial = serial; @@ -126,25 +108,17 @@ debug_serial(void *p, unsigned *pserial) static void debug_serial_delete(void *p) { - pipe_mutex_lock(serials_mutex); - util_hash_table_remove(serials_hash, p); - pipe_mutex_unlock(serials_mutex); + mtx_lock(&serials_mutex); + _mesa_hash_table_remove_key(serials_hash, p); + mtx_unlock(&serials_mutex); } +#if defined(PIPE_OS_WINDOWS) +#define STACK_LEN 60 +#else #define STACK_LEN 64 - -static void -dump_stack(const char *symbols[STACK_LEN]) -{ - unsigned i; - for (i = 0; i < STACK_LEN; ++i) { - if (symbols[i]) - fprintf(stream, "%s\n", symbols[i]); - } - fprintf(stream, "\n"); -} - +#endif /** * Log a reference count change to the log file (if enabled). @@ -180,7 +154,6 @@ debug_reference_slowpath(const struct pipe_reference *p, if (debug_refcnt_state > 0) { struct debug_stack_frame frames[STACK_LEN]; - const char *symbols[STACK_LEN]; char buf[1024]; unsigned i; unsigned refcnt = p->count; @@ -188,18 +161,12 @@ debug_reference_slowpath(const struct pipe_reference *p, boolean existing = debug_serial((void *) p, &serial); debug_backtrace_capture(frames, 1, STACK_LEN); - for (i = 0; i < STACK_LEN; ++i) { - if (frames[i].function) - symbols[i] = debug_symbol_name_cached(frames[i].function); - else - symbols[i] = 0; - } get_desc(buf, p); if (!existing) { fprintf(stream, "<%s> %p %u Create\n", buf, (void *) p, serial); - dump_stack(symbols); + debug_backtrace_print(stream, frames, STACK_LEN); /* this is here to provide a gradual change even if we don't see * the initialization @@ -207,20 +174,20 @@ debug_reference_slowpath(const struct pipe_reference *p, for (i = 1; i <= refcnt - change; ++i) { fprintf(stream, "<%s> %p %u AddRef %u\n", buf, (void *) p, serial, i); - dump_stack(symbols); + debug_backtrace_print(stream, frames, STACK_LEN); } } if (change) { fprintf(stream, "<%s> %p %u %s %u\n", buf, (void *) p, serial, change > 0 ? "AddRef" : "Release", refcnt); - dump_stack(symbols); + debug_backtrace_print(stream, frames, STACK_LEN); } if (!refcnt) { debug_serial_delete((void *) p); fprintf(stream, "<%s> %p %u Destroy\n", buf, (void *) p, serial); - dump_stack(symbols); + debug_backtrace_print(stream, frames, STACK_LEN); } fflush(stream);