trace: Add initializer for static variables
authorJakob Bornecrantz <jakob@vmware.com>
Mon, 20 Apr 2009 14:05:01 +0000 (16:05 +0200)
committerJakob Bornecrantz <jakob@vmware.com>
Mon, 20 Apr 2009 14:07:44 +0000 (16:07 +0200)
src/gallium/drivers/trace/tr_dump.c
src/gallium/drivers/trace/tr_dump.h
src/gallium/drivers/trace/tr_screen.c

index 63811b7c81ead514fe8817b6e4ba6005a8924cf6..3a1409e95a7e1820b61a8916602749431dd4c1e9 100644 (file)
@@ -62,6 +62,7 @@ static unsigned refcount = 0;
 static pipe_mutex call_mutex;
 static long unsigned call_no = 0;
 static boolean dumping = FALSE;
+static boolean initialized = FALSE;
 
 
 static INLINE void
@@ -227,10 +228,22 @@ trace_dump_trace_close(void)
    }
 }
 
+void trace_dump_init()
+{
+   if (initialized)
+      return;
+
+   pipe_mutex_init(call_mutex);
+   dumping = FALSE;
+   initialized = TRUE;
+}
+
 boolean trace_dump_trace_begin()
 {
    const char *filename;
 
+   assert(initialized);
+
    filename = debug_get_option("GALLIUM_TRACE", NULL);
    if(!filename)
       return FALSE;
@@ -241,8 +254,6 @@ 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");
index 8b72b5c9fc07e8ac1cfb9c00ff2219579ee66398..31ac70802f0bb8872511d8b1bef30445b0c1b795 100644 (file)
@@ -42,6 +42,11 @@ struct pipe_texture;
 struct pipe_surface;
 struct pipe_transfer;
 
+/*
+ * Call before use.
+ */
+void trace_dump_init(void);
+
 /*
  * Low level dumping controls.
  *
index 549525b82a5c08c5c8bbbdf9a828f72851771fd8..12a85353428413315d38a97499cde68cc0e0c0b7 100644 (file)
@@ -840,6 +840,8 @@ trace_screen_create(struct pipe_screen *screen)
    if(!screen)
       goto error1;
 
+   trace_dump_init();
+
    if(!trace_dump_trace_begin())
       goto error1;