trace: Make calls dumping threadsafe.
authorJosé Fonseca <jfonseca@vmware.com>
Wed, 8 Apr 2009 15:24:31 +0000 (16:24 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Wed, 8 Apr 2009 15:26:05 +0000 (16:26 +0100)
src/gallium/drivers/trace/tr_dump.c

index f9ee7876cbe2a2d63021e9491b61827a6bfc8f01..2618883e70d4c8f8991436e060dbeed9eb331332 100644 (file)
@@ -45,6 +45,7 @@
 #endif
 
 #include "pipe/p_compiler.h"
+#include "pipe/p_thread.h"
 #include "util/u_debug.h"
 #include "util/u_memory.h"
 #include "util/u_string.h"
@@ -58,6 +59,7 @@
 
 static struct util_stream *stream = NULL;
 static unsigned refcount = 0;
+static pipe_mutex call_mutex;
 static long unsigned call_no = 0;
 
 
@@ -220,6 +222,7 @@ trace_dump_trace_close(void)
       stream = NULL;
       refcount = 0;
       call_no = 0;
+      pipe_mutex_destroy(call_mutex);
    }
 }
 
@@ -237,6 +240,8 @@ boolean trace_dump_trace_begin()
       if(!stream)
          return FALSE;
 
+      pipe_mutex_init(call_mutex);
+
       trace_dump_writes("<?xml version='1.0' encoding='UTF-8'?>\n");
       trace_dump_writes("<?xml-stylesheet type='text/xsl' href='trace.xsl'?>\n");
       trace_dump_writes("<trace version='0.1'>\n");
@@ -267,6 +272,7 @@ void trace_dump_trace_end(void)
 
 void trace_dump_call_begin(const char *klass, const char *method)
 {
+   pipe_mutex_lock(call_mutex);
    ++call_no;
    trace_dump_indent(1);
    trace_dump_writes("<call no=\'");
@@ -285,6 +291,7 @@ void trace_dump_call_end(void)
    trace_dump_tag_end("call");
    trace_dump_newline();
    util_stream_flush(stream);
+   pipe_mutex_unlock(call_mutex);
 }
 
 void trace_dump_arg_begin(const char *name)