Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / sgen / sgen-protocol.c
index a399aa088da2fbe59635d443d777a79200698986..b53965b4aebe1e503d32a8e3444a4f28a79f495b 100644 (file)
@@ -1,6 +1,6 @@
-/*
- * sgen-protocol.c: Binary protocol of internal activity, to aid
- * debugging.
+/**
+ * \file
+ * Binary protocol of internal activity, to aid debugging.
  *
  * Copyright 2001-2003 Ximian, Inc
  * Copyright 2003-2010 Novell, Inc.
@@ -16,7 +16,7 @@
 #include "sgen-gc.h"
 #include "sgen-protocol.h"
 #include "sgen-memory-governor.h"
-#include "sgen-thread-pool.h"
+#include "sgen-workers.h"
 #include "sgen-client.h"
 #include "mono/utils/mono-membar.h"
 #include "mono/utils/mono-proclib.h"
@@ -340,30 +340,41 @@ static void
 protocol_entry (unsigned char type, gpointer data, int size)
 {
        int index;
+       gboolean include_worker_index = type != PROTOCOL_ID (binary_protocol_header);
+       int entry_size = size + 1 + (include_worker_index ? 1 : 0); // type + worker_index + size
        BinaryProtocolBuffer *buffer;
 
        if (binary_protocol_file == invalid_file_value)
                return;
 
-       if (sgen_thread_pool_is_thread_pool_thread (mono_native_thread_id_get ()))
-               type |= 0x80;
-
        lock_recursive ();
 
  retry:
        buffer = binary_protocol_get_buffer (size + 1);
  retry_same_buffer:
        index = buffer->index;
-       if (index + 1 + size > BINARY_PROTOCOL_BUFFER_SIZE)
+       if (index + entry_size > BINARY_PROTOCOL_BUFFER_SIZE)
                goto retry;
 
-       if (InterlockedCompareExchange (&buffer->index, index + 1 + size, index) != index)
+       if (InterlockedCompareExchange (&buffer->index, index + entry_size, index) != index)
                goto retry_same_buffer;
 
        /* FIXME: if we're interrupted at this point, we have a buffer
           entry that contains random data. */
 
        buffer->buffer [index++] = type;
+       /* We should never change the header format */
+       if (include_worker_index) {
+               int worker_index;
+               MonoNativeThreadId tid = mono_native_thread_id_get ();
+               /*
+                * If the thread is not a worker thread we insert 0, which is interpreted
+                * as gc thread. Worker indexes are 1 based.
+                */
+               worker_index = sgen_thread_pool_is_thread_pool_thread (tid);
+               /* FIXME Consider using different index bases for different thread pools */
+               buffer->buffer [index++] = (unsigned char) worker_index;
+       }
        memcpy (buffer->buffer + index, data, size);
        index += size;