[runtime] Add a mono_threads_close_thread_handle () function and use it to close...
authorZoltan Varga <vargaz@gmail.com>
Thu, 1 Sep 2016 11:34:00 +0000 (13:34 +0200)
committerGitHub <noreply@github.com>
Thu, 1 Sep 2016 11:34:00 +0000 (13:34 +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 43dd5a430bcc4082614c473c1cbe4cb2fe25338e..f090ccaf6dd17146034aba83ac5823be5e552b75 100644 (file)
@@ -1085,7 +1085,7 @@ mono_thread_detach_internal (MonoInternalThread *thread)
        SET_CURRENT_OBJECT (NULL);
        mono_domain_unset ();
 
-       /* Don't need to CloseHandle this thread, even though we took a
+       /* Don't need to close the handle to this thread, even though we took a
         * reference in mono_thread_attach (), because the GC will do it
         * when the Thread object is finalised.
         */
@@ -1214,7 +1214,7 @@ ves_icall_System_Threading_InternalThread_Thread_free_internal (MonoInternalThre
         * when thread_cleanup () can be called after this.
         */
        if (thread)
-               CloseHandle (thread);
+               mono_threads_close_thread_handle (thread);
 
        if (this_obj->synch_cs) {
                MonoCoopMutex *synch_cs = this_obj->synch_cs;
@@ -2989,7 +2989,8 @@ struct wait_data
        guint32 num;
 };
 
-static void wait_for_tids (struct wait_data *wait, guint32 timeout)
+static void
+wait_for_tids (struct wait_data *wait, guint32 timeout)
 {
        guint32 i, ret;
        
@@ -3006,7 +3007,7 @@ static void wait_for_tids (struct wait_data *wait, guint32 timeout)
        }
        
        for(i=0; i<wait->num; i++)
-               CloseHandle (wait->handles[i]);
+               mono_threads_close_thread_handle (wait->handles [i]);
 
        if (ret == WAIT_TIMEOUT)
                return;
@@ -3069,7 +3070,7 @@ static void wait_for_tids_or_state_change (struct wait_data *wait, guint32 timeo
        }
        
        for(i=0; i<wait->num; i++)
-               CloseHandle (wait->handles[i]);
+               mono_threads_close_thread_handle (wait->handles [i]);
 
        if (ret == WAIT_TIMEOUT)
                return;
@@ -3389,7 +3390,7 @@ void mono_thread_suspend_all_other_threads (void)
                             || mono_gc_is_finalizer_internal_thread (thread)
                             || (thread->flags & MONO_THREAD_FLAG_DONT_MANAGE)
                        ) {
-                               //CloseHandle (wait->handles [i]);
+                               //mono_threads_close_thread_handle (wait->handles [i]);
                                wait->threads [i] = NULL; /* ignore this thread in next loop */
                                continue;
                        }
@@ -3400,7 +3401,7 @@ void mono_thread_suspend_all_other_threads (void)
                                (thread->state & ThreadState_StopRequested) != 0 ||
                                (thread->state & ThreadState_Stopped) != 0) {
                                UNLOCK_THREAD (thread);
-                               CloseHandle (wait->handles [i]);
+                               mono_threads_close_thread_handle (wait->handles [i]);
                                wait->threads [i] = NULL; /* ignore this thread in next loop */
                                continue;
                        }
index c92f7bb316f814400e151a10f59a798ca5a74697..4d1afeba132a1dd3702810ff5531d8d43e95753c 100644 (file)
@@ -274,6 +274,12 @@ mono_threads_platform_open_thread_handle (HANDLE handle, MonoNativeThreadId tid)
        return handle;
 }
 
+void
+mono_threads_platform_close_thread_handle (HANDLE handle)
+{
+       mono_w32handle_unref (handle);
+}
+
 int
 mono_threads_pthread_kill (MonoThreadInfo *info, int signum)
 {
index d2b3b5e2ea357281d6e7b9ce9e47c6edf496e1d1..ca6159b07f52e277b41d35a7b756a37201f81c87 100644 (file)
@@ -319,6 +319,12 @@ mono_threads_platform_open_thread_handle (HANDLE handle, MonoNativeThreadId tid)
        return OpenThread (THREAD_ALL_ACCESS, TRUE, tid);
 }
 
+void
+mono_threads_platform_close_thread_handle (HANDLE handle)
+{
+       CloseHandle (handle);
+}
+
 #if defined(_MSC_VER)
 const DWORD MS_VC_EXCEPTION=0x406D1388;
 #pragma pack(push,8)
index fe503bf9f1bfb2d8eb956b089a39c41833edde50..53a14e38440effbc912513977065b4231edcb4b1 100644 (file)
@@ -1364,6 +1364,12 @@ mono_threads_open_thread_handle (HANDLE handle, MonoNativeThreadId tid)
        return mono_threads_platform_open_thread_handle (handle, tid);
 }
 
+void
+mono_threads_close_thread_handle (HANDLE handle)
+{
+       return mono_threads_platform_close_thread_handle (handle);
+}
+
 #define INTERRUPT_STATE ((MonoThreadInfoInterruptToken*) (size_t) -1)
 
 struct _MonoThreadInfoInterruptToken {
index a59430e855cf2b374f77fd96db6022890b693862..778deb5b51c584fa6a80b7f99ffd1b806078eda7 100644 (file)
@@ -473,6 +473,9 @@ mono_threads_get_max_stack_size (void);
 HANDLE
 mono_threads_open_thread_handle (HANDLE handle, MonoNativeThreadId tid);
 
+void
+mono_threads_close_thread_handle (HANDLE handle);
+
 MONO_API void
 mono_threads_attach_tools_thread (void);
 
@@ -540,6 +543,7 @@ 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_thread_handle (HANDLE handle, MonoNativeThreadId tid);
+void mono_threads_platform_close_thread_handle (HANDLE handle);
 void mono_threads_platform_set_exited (THREAD_INFO_TYPE *info);
 void mono_threads_platform_describe (THREAD_INFO_TYPE *info, GString *text);
 void mono_threads_platform_own_mutex (THREAD_INFO_TYPE *info, gpointer mutex_handle);