[threads] Get thread handle from MonoThreadInfo when attaching
authorLudovic Henry <ludovic@xamarin.com>
Thu, 14 Jul 2016 16:36:54 +0000 (18:36 +0200)
committerLudovic Henry <ludovic@xamarin.com>
Wed, 24 Aug 2016 18:56:24 +0000 (20:56 +0200)
mono/metadata/threads.c
mono/utils/mono-threads-posix.c
mono/utils/mono-threads-windows.c
mono/utils/mono-threads.c
mono/utils/mono-threads.h

index d9dc57ab4f65ad6c0154794572f8f28257817078..6870f431e8b802c73647b150c39fdee3a1083416 100644 (file)
@@ -1005,7 +1005,6 @@ mono_thread_attach_full (MonoDomain *domain, gboolean force_attach)
        MonoThreadInfo *info;
        MonoInternalThread *thread;
        MonoThread *current_thread;
-       HANDLE thread_handle;
        MonoNativeThreadId tid;
 
        if ((thread = mono_thread_internal_current ())) {
@@ -1019,21 +1018,17 @@ mono_thread_attach_full (MonoDomain *domain, gboolean force_attach)
                g_error ("Thread %"G_GSIZE_FORMAT" calling into managed code is not registered with the GC. On UNIX, this can be fixed by #include-ing <gc.h> before <pthread.h> in the file containing the thread creation code.", mono_native_thread_id_get ());
        }
 
-       thread = create_internal_thread ();
-
-       thread_handle = mono_thread_info_open_handle ();
-       g_assert (thread_handle);
+       info = mono_thread_info_current ();
 
        tid=mono_native_thread_id_get ();
 
-       thread->handle = thread_handle;
+       thread = create_internal_thread ();
+       thread->handle = mono_thread_info_get_handle (info);
        thread->tid = MONO_NATIVE_THREAD_ID_TO_UINT (tid);
        thread->stack_ptr = &tid;
 
-       THREAD_DEBUG (g_message ("%s: Attached thread ID %"G_GSIZE_FORMAT" (handle %p)", __func__, tid, thread_handle));
+       THREAD_DEBUG (g_message ("%s: Attached thread ID %"G_GSIZE_FORMAT" (handle %p)", __func__, tid, thread->handle));
 
-       info = mono_thread_info_current ();
-       g_assert (info);
        thread->thread_info = info;
        thread->small_id = info->small_id;
 
index d8982e946aafaeb4d0048be10650abcfe36cd32b..60f5585e1823dbb35454d0a5197cc0886d02efc0 100644 (file)
@@ -263,20 +263,6 @@ mono_threads_platform_unregister (MonoThreadInfo *info)
        mono_threads_platform_set_exited (info);
 }
 
-HANDLE
-mono_threads_platform_open_handle (void)
-{
-       MonoThreadInfo *info;
-
-       info = mono_thread_info_current ();
-       g_assert (info);
-       g_assert (info->handle);
-
-       mono_w32handle_ref (info->handle);
-
-       return info->handle;
-}
-
 int
 mono_threads_get_max_stack_size (void)
 {
index 6c33743cfb63af5e231414c0698bab14c1233154..f66e6936b6dc1df123ab5060db34eb65a74ef86f 100644 (file)
@@ -322,24 +322,6 @@ mono_threads_platform_unregister (MonoThreadInfo *info)
 {
 }
 
-HANDLE
-mono_threads_platform_open_handle (void)
-{
-       HANDLE thread_handle;
-
-       thread_handle = GetCurrentThread ();
-       g_assert (thread_handle);
-
-       /*
-        * The handle returned by GetCurrentThread () is a pseudo handle, so it can't be used to
-        * refer to the thread from other threads for things like aborting.
-        */
-       DuplicateHandle (GetCurrentProcess (), thread_handle, GetCurrentProcess (), &thread_handle,
-                                        THREAD_ALL_ACCESS, TRUE, 0);
-
-       return thread_handle;
-}
-
 int
 mono_threads_get_max_stack_size (void)
 {
index 456bb97ea9d5f6f9fe0a1803230d8540e58d7457..5add7fe0f86f32f82803d805762bd4d865e4d78e 100644 (file)
@@ -1352,19 +1352,6 @@ mono_thread_info_exit (void)
        mono_threads_platform_exit (0);
 }
 
-/*
- * mono_thread_info_open_handle:
- *
- *   Return a io-layer/win32 handle for the current thread.
- * The handle need to be closed by calling CloseHandle () when it is no
- * longer needed.
- */
-HANDLE
-mono_thread_info_open_handle (void)
-{
-       return mono_threads_platform_open_handle ();
-}
-
 /*
  * mono_threads_open_thread_handle:
  *
index 15841081f675511cb87ae1b5e35a542c11070f7b..96e197980a05fce513369c12755c83b74a836c9d 100644 (file)
@@ -434,9 +434,6 @@ mono_thread_info_tls_set (THREAD_INFO_TYPE *info, MonoTlsKey key, gpointer value
 void
 mono_thread_info_exit (void);
 
-HANDLE
-mono_thread_info_open_handle (void);
-
 void
 mono_thread_info_set_exited (THREAD_INFO_TYPE *info);
 
@@ -543,7 +540,6 @@ void mono_threads_platform_resume_created (THREAD_INFO_TYPE *info, MonoNativeThr
 void mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize);
 gboolean mono_threads_platform_yield (void);
 void mono_threads_platform_exit (int exit_code);
-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);