if (mono_thread_internal_has_appdomain_ref (mono_thread_internal_current (), domain) && (mono_thread_interruption_requested ())) {
/* The unload thread tries to abort us */
/* The icall wrapper will execute the abort */
+ mono_threads_close_thread_handle (thread_handle);
unload_data_unref (thread_data);
return;
}
}
+ mono_threads_close_thread_handle (thread_handle);
+
if (thread_data->failure_reason) {
/* Roll back the state change */
domain->state = MONO_APPDOMAIN_CREATED;
info = mono_thread_info_current ();
internal = thread->internal_thread;
- internal->handle = mono_thread_info_get_handle (info);
+ internal->handle = mono_thread_info_duplicate_handle (info);
internal->tid = MONO_NATIVE_THREAD_ID_TO_UINT (mono_native_thread_id_get ());
internal->thread_info = info;
internal->small_id = info->small_id;
mono_coop_sem_wait (&start_info->registered, MONO_SEM_FLAGS_NONE);
+ mono_threads_close_thread_handle (thread_handle);
+
THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Done launching thread %p (%"G_GSIZE_FORMAT")", __func__, mono_native_thread_id_get (), internal, (gsize)internal->tid));
ret = !start_info->failed;
for (i = 0; i < threads->len; ++i) {
WaitForSingleObjectEx (g_ptr_array_index (threads, i), INFINITE, FALSE);
+ mono_threads_close_thread_handle (g_ptr_array_index (threads, i));
}
} else {
methods_len = 0;
if (thread_handle == INVALID_HANDLE_VALUE)
g_error ("%s: failed to create handle", __func__);
- /* We need to keep the handle alive, as long as the corresponding managed
- * thread object is alive. The handle is going to be unref when calling
- * the finalizer on the MonoThreadInternal object */
- mono_w32handle_ref (thread_handle);
-
g_assert (!info->handle);
info->handle = thread_handle;
}
return (int)lim.rlim_max;
}
+gpointer
+mono_threads_platform_duplicate_handle (MonoThreadInfo *info)
+{
+ g_assert (info->handle);
+ mono_w32handle_ref (info->handle);
+ return info->handle;
+}
+
HANDLE
mono_threads_platform_open_thread_handle (HANDLE handle, MonoNativeThreadId tid)
{
return INT_MAX;
}
+gpointer
+mono_threads_platform_duplicate_handle (MonoThreadInfo *info)
+{
+ HANDLE thread_handle;
+
+ g_assert (info->handle);
+ DuplicateHandle (GetCurrentProcess (), info->handle, GetCurrentProcess (), &thread_handle, THREAD_ALL_ACCESS, TRUE, 0);
+
+ return thread_handle;
+}
+
HANDLE
mono_threads_platform_open_thread_handle (HANDLE handle, MonoNativeThreadId tid)
{
gpointer start_routine_arg;
gint32 priority;
MonoCoopSem registered;
- MonoThreadInfo *info;
+ gpointer handle;
} CreateThreadData;
static gsize WINAPI
mono_threads_platform_set_priority (info, priority);
- thread_data->info = info;
+ thread_data->handle = mono_thread_info_duplicate_handle (info);
mono_coop_sem_post (&thread_data->registered);
mono_threads_create_thread (MonoThreadStart start, gpointer arg, MonoThreadParm *tp, MonoNativeThreadId *out_tid)
{
CreateThreadData *thread_data;
- MonoThreadInfo *info;
gint res;
gpointer ret;
res = mono_coop_sem_wait (&thread_data->registered, MONO_SEM_FLAGS_NONE);
g_assert (res == 0);
- info = thread_data->info;
- g_assert (info);
-
- ret = info->handle;
+ ret = thread_data->handle;
g_assert (ret);
done:
}
gpointer
-mono_thread_info_get_handle (THREAD_INFO_TYPE *info)
+mono_thread_info_duplicate_handle (MonoThreadInfo *info)
{
- g_assert (info->handle);
- return info->handle;
+ g_assert (mono_thread_info_is_current (info));
+ return mono_threads_platform_duplicate_handle (info);
}
void
void mono_threads_platform_disown_mutex (THREAD_INFO_TYPE *info, gpointer mutex_handle);
MonoThreadPriority mono_threads_platform_get_priority (THREAD_INFO_TYPE *info);
void mono_threads_platform_set_priority (THREAD_INFO_TYPE *info, MonoThreadPriority priority);
+gpointer mono_threads_platform_duplicate_handle (THREAD_INFO_TYPE *info);
void mono_threads_coop_begin_global_suspend (void);
void mono_threads_coop_end_global_suspend (void);
mono_thread_info_is_current (THREAD_INFO_TYPE *info);
gpointer
-mono_thread_info_get_handle (THREAD_INFO_TYPE *info);
+mono_thread_info_duplicate_handle (THREAD_INFO_TYPE *info);
void
mono_thread_info_describe (THREAD_INFO_TYPE *info, GString *text);