[io-layer] Extract wapi_current_thread_desc
authorLudovic Henry <ludovic@xamarin.com>
Thu, 7 Jul 2016 15:07:40 +0000 (17:07 +0200)
committerLudovic Henry <ludovic@xamarin.com>
Thu, 4 Aug 2016 13:40:47 +0000 (15:40 +0200)
mono/io-layer/threads.h
mono/io-layer/wthreads.c
mono/metadata/threads.c
mono/mini/mini-exceptions.c
mono/utils/mono-threads-posix.c
mono/utils/mono-threads-windows.c
mono/utils/mono-threads.c
mono/utils/mono-threads.h

index b1ec1869e30d2a8fe08f13880d19c58a4b7d4f54..85dba03c37bb57a5230ca76430349efa36fcc648 100644 (file)
@@ -43,8 +43,6 @@ typedef enum {
 
 gpointer wapi_create_thread_handle (void);
 
-char *wapi_current_thread_desc (void);
-
 extern gint32 GetThreadPriority (gpointer handle);
 extern gboolean SetThreadPriority (gpointer handle, gint32 priority);
 
index 69adff874ecdf30a38b586250763f80cbe6e67d7..16d8abe4e397cb8c1fabc53a16708cd685e50223 100644 (file)
@@ -382,33 +382,3 @@ SetThreadPriority (gpointer handle, gint32 priority)
        
        return FALSE;
 }
-
-char*
-wapi_current_thread_desc (void)
-{
-       MonoW32HandleThread *thread;
-       MonoThreadInfo *info;
-       gpointer thread_handle;
-       int i;
-       GString* text;
-       char *res;
-
-       info = mono_thread_info_current ();
-
-       thread_handle = mono_thread_info_get_handle (info);
-       thread = lookup_thread (thread_handle);
-
-       text = g_string_new (0);
-       g_string_append_printf (text, "thread handle %p state : ", thread_handle);
-
-       mono_thread_info_describe_interrupt_token (info, text);
-
-       g_string_append_printf (text, " owns (");
-       for (i = 0; i < thread->owned_mutexes->len; i++)
-               g_string_append_printf (text, i > 0 ? ", %p" : "%p", g_ptr_array_index (thread->owned_mutexes, i));
-       g_string_append_printf (text, ")");
-
-       res = text->str;
-       g_string_free (text, FALSE);
-       return res;
-}
index dc307dc601e31fbc76856d95eabd6e4fbc334a82..b2ca672135c81d1035b8269d123d1569117586a2 100644 (file)
@@ -3479,11 +3479,9 @@ get_thread_dump (MonoThreadInfo *info, gpointer ud)
 
 #if 0
 /* This no longer works with remote unwinding */
-#ifndef HOST_WIN32
-       wapi_desc = wapi_current_thread_desc ();
-       g_string_append_printf (text, " tid=0x%p this=0x%p %s\n", (gpointer)(gsize)thread->tid, thread,  wapi_desc);
-       free (wapi_desc);
-#endif
+       g_string_append_printf (text, " tid=0x%p this=0x%p ", (gpointer)(gsize)thread->tid, thread);
+       mono_thread_info_describe (info, text);
+       g_string_append (text, "\n");
 #endif
 
        if (thread == mono_thread_internal_current ())
index 9c375a9aee767a3d055b8926db1cdf440d15f8ca..d16cee8cee3daa00962ced9e1ed97a12959fc445 100644 (file)
@@ -2484,9 +2484,6 @@ mono_print_thread_dump_internal (void *sigctx, MonoContext *start_ctx)
 #endif
        GString* text;
        char *name;
-#ifndef HOST_WIN32
-       char *wapi_desc;
-#endif
        GError *error = NULL;
 
        if (!thread)
@@ -2504,11 +2501,9 @@ mono_print_thread_dump_internal (void *sigctx, MonoContext *start_ctx)
        else
                g_string_append (text, "\n\"<unnamed thread>\"");
 
-#ifndef HOST_WIN32
-       wapi_desc = wapi_current_thread_desc ();
-       g_string_append_printf (text, " tid=0x%p this=0x%p %s\n", (gpointer)(gsize)thread->tid, thread,  wapi_desc);
-       free (wapi_desc);
-#endif
+       g_string_append_printf (text, " tid=0x%p this=0x%p ", (gpointer)(gsize)thread->tid, thread);
+       mono_thread_info_describe ((MonoThreadInfo*) thread->thread_info, text);
+       g_string_append (text, "\n");
 
 #ifdef MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX
        if (start_ctx) {
index 9cbc786cc4f27ef5a3f3c6c7844dc1511d0628ca..5cc8f13f03d920f09c5ce2282c08b2fb9d310ccb 100644 (file)
@@ -378,6 +378,27 @@ mono_threads_platform_set_exited (MonoThreadInfo *info)
        info->handle = NULL;
 }
 
+void
+mono_threads_platform_describe (MonoThreadInfo *info, GString *text)
+{
+       MonoW32HandleThread *thread_data;
+       int i;
+
+       g_assert (info->handle);
+
+       if (!mono_w32handle_lookup (info->handle, MONO_W32HANDLE_THREAD, (gpointer*) &thread_data))
+               g_error ("unknown thread handle %p", info->handle);
+
+       g_string_append_printf (text, "thread handle %p state : ", info->handle);
+
+       mono_thread_info_describe_interrupt_token (info, text);
+
+       g_string_append_printf (text, ", owns (");
+       for (i = 0; i < thread_data->owned_mutexes->len; i++)
+               g_string_append_printf (text, i > 0 ? ", %p" : "%p", g_ptr_array_index (thread_data->owned_mutexes, i));
+       g_string_append_printf (text, ")");
+}
+
 #endif /* defined(_POSIX_VERSION) || defined(__native_client__) */
 
 #if defined(USE_POSIX_BACKEND)
index 82b3a37312c97d27224c4dfc34e178761fb2d361..f27633c61a07f733c7df212c64c54025c6f3b500 100644 (file)
@@ -367,4 +367,10 @@ mono_threads_platform_set_exited (MonoThreadInfo *info)
 {
 }
 
+void
+mono_threads_platform_describe (MonoThreadInfo *info, GString *text)
+{
+       /* TODO */
+}
+
 #endif
index 9e267e0e7adc43c57538733a1277617ba6a60831..fab55f6afecf0c3b65be10ec37173be56fb5c7f2 100644 (file)
@@ -1577,3 +1577,9 @@ mono_thread_info_get_handle (THREAD_INFO_TYPE *info)
        g_assert (info->handle);
        return info->handle;
 }
+
+void
+mono_thread_info_describe (MonoThreadInfo *info, GString *text)
+{
+       mono_threads_platform_describe (info, text);
+}
index 6ed2b5db68dc1c13727ab62898fe5056ca73f81a..816fa169c791eedbcd62a40380691e941bfc25d8 100644 (file)
@@ -531,6 +531,7 @@ void mono_threads_platform_unregister (THREAD_INFO_TYPE *info);
 HANDLE mono_threads_platform_open_handle (void);
 HANDLE mono_threads_platform_open_thread_handle (HANDLE handle, MonoNativeThreadId tid);
 void mono_threads_platform_set_exited (THREAD_INFO_TYPE *info);
+void mono_threads_platform_describe (THREAD_INFO_TYPE *info, GString *text);
 
 void mono_threads_coop_begin_global_suspend (void);
 void mono_threads_coop_end_global_suspend (void);
@@ -648,4 +649,7 @@ mono_thread_info_is_current (THREAD_INFO_TYPE *info);
 gpointer
 mono_thread_info_get_handle (THREAD_INFO_TYPE *info);
 
+void
+mono_thread_info_describe (THREAD_INFO_TYPE *info, GString *text);
+
 #endif /* __MONO_THREADS_H__ */