gallium/util: re-indent u_debug_refcnt.[ch]
Wrap comments to 78 columns, etc. Reviewed-by: Eduardo Lima Mitev <elima@igalia.com>
This commit is contained in:
@@ -42,30 +42,38 @@
|
|||||||
|
|
||||||
int debug_refcnt_state;
|
int debug_refcnt_state;
|
||||||
|
|
||||||
FILE* stream;
|
FILE *stream;
|
||||||
|
|
||||||
/* TODO: maybe move this serial machinery to a stand-alone module and expose it? */
|
/* TODO: maybe move this serial machinery to a stand-alone module and
|
||||||
|
* expose it?
|
||||||
|
*/
|
||||||
pipe_static_mutex(serials_mutex);
|
pipe_static_mutex(serials_mutex);
|
||||||
|
|
||||||
static struct util_hash_table* serials_hash;
|
static struct util_hash_table *serials_hash;
|
||||||
static unsigned serials_last;
|
static unsigned serials_last;
|
||||||
|
|
||||||
static unsigned hash_ptr(void* p)
|
|
||||||
|
static unsigned
|
||||||
|
hash_ptr(void *p)
|
||||||
{
|
{
|
||||||
return (unsigned)(uintptr_t)p;
|
return (unsigned) (uintptr_t) p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compare_ptr(void* a, void* b)
|
|
||||||
|
static int
|
||||||
|
compare_ptr(void *a, void *b)
|
||||||
{
|
{
|
||||||
if(a == b)
|
if (a == b)
|
||||||
return 0;
|
return 0;
|
||||||
else if(a < b)
|
else if (a < b)
|
||||||
return -1;
|
return -1;
|
||||||
else
|
else
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean debug_serial(void* p, unsigned* pserial)
|
|
||||||
|
static boolean
|
||||||
|
debug_serial(void *p, unsigned *pserial)
|
||||||
{
|
{
|
||||||
unsigned serial;
|
unsigned serial;
|
||||||
boolean found = TRUE;
|
boolean found = TRUE;
|
||||||
@@ -81,79 +89,82 @@ static boolean debug_serial(void* p, unsigned* pserial)
|
|||||||
pipe_mutex_lock(serials_mutex);
|
pipe_mutex_lock(serials_mutex);
|
||||||
if (!serials_hash)
|
if (!serials_hash)
|
||||||
serials_hash = util_hash_table_create(hash_ptr, compare_ptr);
|
serials_hash = util_hash_table_create(hash_ptr, compare_ptr);
|
||||||
serial = (unsigned)(uintptr_t)util_hash_table_get(serials_hash, p);
|
|
||||||
if(!serial)
|
serial = (unsigned) (uintptr_t) util_hash_table_get(serials_hash, p);
|
||||||
{
|
if (!serial) {
|
||||||
/* time to stop logging... (you'll have a 100 GB logfile at least at this point)
|
/* time to stop logging... (you'll have a 100 GB logfile at least at
|
||||||
* TODO: avoid this
|
* this point) TODO: avoid this
|
||||||
*/
|
*/
|
||||||
serial = ++serials_last;
|
serial = ++serials_last;
|
||||||
if(!serial)
|
if (!serial) {
|
||||||
{
|
|
||||||
debug_error("More than 2^32 objects detected, aborting.\n");
|
debug_error("More than 2^32 objects detected, aborting.\n");
|
||||||
os_abort();
|
os_abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
util_hash_table_set(serials_hash, p, (void*)(uintptr_t)serial);
|
util_hash_table_set(serials_hash, p, (void *) (uintptr_t) serial);
|
||||||
found = FALSE;
|
found = FALSE;
|
||||||
}
|
}
|
||||||
pipe_mutex_unlock(serials_mutex);
|
pipe_mutex_unlock(serials_mutex);
|
||||||
|
|
||||||
*pserial = serial;
|
*pserial = serial;
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void debug_serial_delete(void* p)
|
|
||||||
|
static void
|
||||||
|
debug_serial_delete(void *p)
|
||||||
{
|
{
|
||||||
pipe_mutex_lock(serials_mutex);
|
pipe_mutex_lock(serials_mutex);
|
||||||
util_hash_table_remove(serials_hash, p);
|
util_hash_table_remove(serials_hash, p);
|
||||||
pipe_mutex_unlock(serials_mutex);
|
pipe_mutex_unlock(serials_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define STACK_LEN 64
|
#define STACK_LEN 64
|
||||||
|
|
||||||
static void dump_stack(const char* symbols[STACK_LEN])
|
static void
|
||||||
|
dump_stack(const char *symbols[STACK_LEN])
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
for(i = 0; i < STACK_LEN; ++i)
|
for (i = 0; i < STACK_LEN; ++i) {
|
||||||
{
|
if (symbols[i])
|
||||||
if(symbols[i])
|
|
||||||
fprintf(stream, "%s\n", symbols[i]);
|
fprintf(stream, "%s\n", symbols[i]);
|
||||||
}
|
}
|
||||||
fprintf(stream, "\n");
|
fprintf(stream, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug_reference_slowpath(const struct pipe_reference* p, debug_reference_descriptor get_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;
|
||||||
|
|
||||||
if(!debug_refcnt_state)
|
if (!debug_refcnt_state) {
|
||||||
{
|
const char *filename = debug_get_option("GALLIUM_REFCNT_LOG", NULL);
|
||||||
const char* filename = debug_get_option("GALLIUM_REFCNT_LOG", NULL);
|
if (filename && filename[0])
|
||||||
if(filename && filename[0])
|
|
||||||
stream = fopen(filename, "wt");
|
stream = fopen(filename, "wt");
|
||||||
|
|
||||||
if(stream)
|
if (stream)
|
||||||
debug_refcnt_state = 1;
|
debug_refcnt_state = 1;
|
||||||
else
|
else
|
||||||
debug_refcnt_state = -1;
|
debug_refcnt_state = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(debug_refcnt_state > 0)
|
if (debug_refcnt_state > 0) {
|
||||||
{
|
|
||||||
struct debug_stack_frame frames[STACK_LEN];
|
struct debug_stack_frame frames[STACK_LEN];
|
||||||
const char* symbols[STACK_LEN];
|
const char *symbols[STACK_LEN];
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
unsigned i;
|
unsigned i;
|
||||||
unsigned refcnt = p->count;
|
unsigned refcnt = p->count;
|
||||||
unsigned serial;
|
unsigned serial;
|
||||||
boolean existing = debug_serial((void*)p, &serial);
|
boolean existing = debug_serial((void *) p, &serial);
|
||||||
|
|
||||||
debug_backtrace_capture(frames, 1, STACK_LEN);
|
debug_backtrace_capture(frames, 1, STACK_LEN);
|
||||||
for(i = 0; i < STACK_LEN; ++i)
|
for (i = 0; i < STACK_LEN; ++i) {
|
||||||
{
|
if (frames[i].function)
|
||||||
if(frames[i].function)
|
|
||||||
symbols[i] = debug_symbol_name_cached(frames[i].function);
|
symbols[i] = debug_symbol_name_cached(frames[i].function);
|
||||||
else
|
else
|
||||||
symbols[i] = 0;
|
symbols[i] = 0;
|
||||||
@@ -161,30 +172,28 @@ void debug_reference_slowpath(const struct pipe_reference* p, debug_reference_de
|
|||||||
|
|
||||||
get_desc(buf, p);
|
get_desc(buf, p);
|
||||||
|
|
||||||
if(!existing)
|
if (!existing) {
|
||||||
{
|
|
||||||
fprintf(stream, "<%s> %p %u Create\n", buf, (void *) p, serial);
|
fprintf(stream, "<%s> %p %u Create\n", buf, (void *) p, serial);
|
||||||
dump_stack(symbols);
|
dump_stack(symbols);
|
||||||
|
|
||||||
/* this is there to provide a gradual change even if we don't see the initialization */
|
/* this is here to provide a gradual change even if we don't see
|
||||||
for(i = 1; i <= refcnt - change; ++i)
|
* the initialization
|
||||||
{
|
*/
|
||||||
|
for (i = 1; i <= refcnt - change; ++i) {
|
||||||
fprintf(stream, "<%s> %p %u AddRef %u\n", buf, (void *) p,
|
fprintf(stream, "<%s> %p %u AddRef %u\n", buf, (void *) p,
|
||||||
serial, i);
|
serial, i);
|
||||||
dump_stack(symbols);
|
dump_stack(symbols);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(change)
|
if (change) {
|
||||||
{
|
|
||||||
fprintf(stream, "<%s> %p %u %s %u\n", buf, (void *) p, serial,
|
fprintf(stream, "<%s> %p %u %s %u\n", buf, (void *) p, serial,
|
||||||
change > 0 ? "AddRef" : "Release", refcnt);
|
change > 0 ? "AddRef" : "Release", refcnt);
|
||||||
dump_stack(symbols);
|
dump_stack(symbols);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!refcnt)
|
if (!refcnt) {
|
||||||
{
|
debug_serial_delete((void *) p);
|
||||||
debug_serial_delete((void*)p);
|
|
||||||
fprintf(stream, "<%s> %p %u Destroy\n", buf, (void *) p, serial);
|
fprintf(stream, "<%s> %p %u Destroy\n", buf, (void *) p, serial);
|
||||||
dump_stack(symbols);
|
dump_stack(symbols);
|
||||||
}
|
}
|
||||||
|
@@ -40,9 +40,13 @@ typedef void (*debug_reference_descriptor)(char*, const struct pipe_reference*);
|
|||||||
|
|
||||||
extern int debug_refcnt_state;
|
extern int debug_refcnt_state;
|
||||||
|
|
||||||
void debug_reference_slowpath(const struct pipe_reference* p, debug_reference_descriptor 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, debug_reference_descriptor 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);
|
||||||
@@ -50,7 +54,9 @@ static inline void debug_reference(const struct pipe_reference* p, debug_referen
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static inline void debug_reference(const struct pipe_reference* p, debug_reference_descriptor get_desc, int change)
|
static inline void
|
||||||
|
debug_reference(const struct pipe_reference* p,
|
||||||
|
debug_reference_descriptor get_desc, int change)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user