[profiler] Add an extra assert.
authorAlex Rønne Petersen <alexrp@xamarin.com>
Mon, 12 Sep 2016 08:43:38 +0000 (10:43 +0200)
committerAlex Rønne Petersen <alexrp@xamarin.com>
Sun, 2 Oct 2016 16:44:51 +0000 (18:44 +0200)
mono/profiler/mono-profiler-log.c

index 091272e5f6697688e52fda7c57c6c64a9cf707d7..0785378f04bf61bb2e23236848d8bc9ca957cef8 100644 (file)
@@ -512,6 +512,9 @@ struct _LogBuffer {
 typedef struct {
        MonoLinkedListSetNode node;
 
+       // Was this thread added to the LLS?
+       gboolean attached;
+
        // The current log buffer for this thread.
        LogBuffer *buffer;
 
@@ -823,6 +826,12 @@ create_buffer (void)
        return buf;
 }
 
+/*
+ * Must be called with the reader lock held if thread is the current thread, or
+ * the exclusive lock if thread is a different thread. However, if thread is
+ * the current thread, and init_thread () was called with add_to_lls = FALSE,
+ * then no locking is necessary.
+ */
 static void
 init_buffer_state (MonoProfilerThread *thread)
 {
@@ -859,6 +868,7 @@ init_thread (gboolean add_to_lls)
 
        thread = malloc (sizeof (MonoProfilerThread));
        thread->node.key = thread_id ();
+       thread->attached = add_to_lls;
        thread->call_depth = 0;
        thread->busy = 0;
 
@@ -883,6 +893,8 @@ init_thread (gboolean add_to_lls)
 static void
 deinit_thread (MonoProfilerThread *thread)
 {
+       g_assert (!thread->attached && "Why are we manually freeing an attached thread?");
+
        free (thread);
        PROF_TLS_SET (NULL);
 }
@@ -1255,6 +1267,12 @@ dump_header (MonoProfiler *profiler)
        free (hbuf);
 }
 
+/*
+ * Must be called with the reader lock held if thread is the current thread, or
+ * the exclusive lock if thread is a different thread. However, if thread is
+ * the current thread, and init_thread () was called with add_to_lls = FALSE,
+ * then no locking is necessary.
+ */
 static void
 send_buffer (MonoProfiler *prof, MonoProfilerThread *thread)
 {