From 523648de784942ae57f1ff0fb55f00916c768142 Mon Sep 17 00:00:00 2001 From: Rodrigo Kumpera Date: Thu, 6 Jun 2013 18:50:04 -0400 Subject: [PATCH] Add mono_thread_attach_full function that can forces a thread to be attached during shutdown. A thread must be forcibly attached during shutdown if the runtime needs it to run and needs it to be functional. --- mono/metadata/threads-types.h | 1 + mono/metadata/threads.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/mono/metadata/threads-types.h b/mono/metadata/threads-types.h index 8d49c52c3f7..b08a3100a43 100644 --- a/mono/metadata/threads-types.h +++ b/mono/metadata/threads-types.h @@ -225,5 +225,6 @@ gpointer mono_get_special_static_data_for_thread (MonoInternalThread *thread, gu MonoException* mono_thread_resume_interruption (void) MONO_INTERNAL; void mono_threads_perform_thread_dump (void) MONO_INTERNAL; +MonoThread *mono_thread_attach_full (MonoDomain *domain, gboolean force_attach) MONO_INTERNAL; #endif /* _MONO_METADATA_THREADS_TYPES_H_ */ diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index 0371e45c869..809a9bfc84e 100644 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -245,7 +245,7 @@ mono_thread_get_tls_offset (void) * If handle_store() returns FALSE the thread must not be started * because Mono is shutting down. */ -static gboolean handle_store(MonoThread *thread) +static gboolean handle_store(MonoThread *thread, gboolean force_attach) { mono_threads_lock (); @@ -254,7 +254,7 @@ static gboolean handle_store(MonoThread *thread) if (threads_starting_up) mono_g_hash_table_remove (threads_starting_up, thread); - if (shutting_down) { + if (shutting_down && !force_attach) { mono_threads_unlock (); return FALSE; } @@ -794,7 +794,7 @@ mono_thread_create_internal (MonoDomain *domain, gpointer func, gpointer arg, gb if (threadpool_thread) mono_thread_set_state (internal, ThreadState_Background); - if (handle_store (thread)) + if (handle_store (thread, FALSE)) ResumeThread (thread_handle); /* Check that the managed and unmanaged layout of MonoInternalThread matches */ @@ -904,6 +904,12 @@ mono_thread_get_stack_bounds (guint8 **staddr, size_t *stsize) MonoThread * mono_thread_attach (MonoDomain *domain) { + return mono_thread_attach_full (domain, FALSE); +} + +MonoThread * +mono_thread_attach_full (MonoDomain *domain, gboolean force_attach) +{ MonoThreadInfo *info; MonoInternalThread *thread; MonoThread *current_thread; @@ -960,7 +966,7 @@ mono_thread_attach (MonoDomain *domain) current_thread = new_thread_with_internal (domain, thread); - if (!handle_store (current_thread)) { + if (!handle_store (current_thread, force_attach)) { /* Mono is shutting down, so just wait for the end */ for (;;) Sleep (10000); @@ -1170,7 +1176,7 @@ static void mono_thread_start (MonoThread *thread) * launched, to avoid the main thread deadlocking while trying * to clean up a thread that will never be signalled. */ - if (!handle_store (thread)) + if (!handle_store (thread, FALSE)) return; ResumeThread (internal->handle); -- 2.11.4.GIT