X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Fthreads.c;h=c756a06c94082952563abe49d4326798d669fb8a;hb=5c11fe647563fa051f73d3571da839dfccd26f8e;hp=fe4365c29ba9a33999ae99de23761190997aa13b;hpb=82bcac8efac8c2556cf748b062592a4fdc2ecc3e;p=mono.git diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index fe4365c29ba..c756a06c940 100644 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -695,11 +695,11 @@ mono_thread_attach_internal (MonoThread *thread, gboolean force_attach, gboolean if (shutting_down && !force_attach) { mono_threads_unlock (); + mono_thread_pop_appdomain_ref (); return FALSE; } if (!threads) { - MONO_GC_REGISTER_ROOT_FIXED (threads, MONO_ROOT_SOURCE_THREADING, "threads table"); threads = mono_g_hash_table_new_type (NULL, NULL, MONO_HASH_VALUE_GC, MONO_ROOT_SOURCE_THREADING, "threads table"); } @@ -915,7 +915,7 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, MonoObject *sta */ mono_threads_join_threads (); - mono_error_init (error); + error_init (error); mono_threads_lock (); if (shutting_down) { @@ -923,7 +923,6 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, MonoObject *sta return FALSE; } if (threads_starting_up == NULL) { - MONO_GC_REGISTER_ROOT_FIXED (threads_starting_up, MONO_ROOT_SOURCE_THREADING, "starting threads table"); threads_starting_up = mono_g_hash_table_new_type (NULL, NULL, MONO_HASH_KEY_VALUE_GC, MONO_ROOT_SOURCE_THREADING, "starting threads table"); } mono_g_hash_table_insert (threads_starting_up, thread, thread); @@ -1019,7 +1018,7 @@ mono_thread_create_internal (MonoDomain *domain, gpointer func, gpointer arg, gb MonoInternalThread *internal; gboolean res; - mono_error_init (error); + error_init (error); internal = create_internal_thread_object (); @@ -1551,7 +1550,7 @@ ves_icall_System_Threading_Thread_GetName_internal (MonoInternalThread *this_obj MonoError error; MonoString* str; - mono_error_init (&error); + error_init (&error); LOCK_THREAD (this_obj); @@ -1573,7 +1572,7 @@ mono_thread_set_name_internal (MonoInternalThread *this_obj, MonoString *name, g { LOCK_THREAD (this_obj); - mono_error_init (error); + error_init (error); if (reset) { this_obj->flags &= ~MONO_THREAD_FLAG_NAME_SET; @@ -1663,7 +1662,7 @@ byte_array_to_domain (MonoArray *arr, MonoDomain *domain, MonoError *error) { MonoArray *copy; - mono_error_init (error); + error_init (error); if (!arr) return NULL; @@ -1744,7 +1743,7 @@ mono_join_uninterrupted (MonoThreadHandle* thread_to_join, gint32 ms, MonoError gint32 diff_ms; gint32 wait = ms; - mono_error_init (error); + error_init (error); start = (ms == -1) ? 0 : mono_msec_ticks (); for (;;) { @@ -1853,7 +1852,7 @@ mono_wait_uninterrupted (MonoInternalThread *thread, guint32 numhandles, gpointe gint32 diff_ms; gint32 wait = ms; - mono_error_init (error); + error_init (error); start = (ms == -1) ? 0 : mono_100ns_ticks (); do { @@ -3210,22 +3209,21 @@ remove_and_abort_threads (gpointer key, gpointer value, gpointer user) if (wait->num >= MONO_W32HANDLE_MAXIMUM_WAIT_OBJECTS) return FALSE; - /* The finalizer thread is not a background thread */ - if (!mono_native_thread_id_equals (thread_get_tid (thread), self) - && (thread->state & ThreadState_Background) != 0 - && (thread->flags & MONO_THREAD_FLAG_DONT_MANAGE) == 0 - ) { + if (mono_native_thread_id_equals (thread_get_tid (thread), self)) + return FALSE; + if (mono_gc_is_finalizer_internal_thread (thread)) + return FALSE; + + if ((thread->state & ThreadState_Background) && !(thread->flags & MONO_THREAD_FLAG_DONT_MANAGE)) { wait->handles[wait->num] = mono_threads_open_thread_handle (thread->handle); wait->threads[wait->num] = thread; wait->num++; THREAD_DEBUG (g_print ("%s: Aborting id: %"G_GSIZE_FORMAT"\n", __func__, (gsize)thread->tid)); mono_thread_internal_abort (thread); - return TRUE; } - return !mono_native_thread_id_equals (thread_get_tid (thread), self) - && !mono_gc_is_finalizer_internal_thread (thread); + return TRUE; } /** @@ -3663,7 +3661,7 @@ mono_threads_get_thread_dump (MonoArray **out_threads, MonoArray **out_stack_fra MonoDebugSourceLocation *location; int tindex, nthreads; - mono_error_init (error); + error_init (error); *out_threads = NULL; *out_stack_frames = NULL; @@ -4905,7 +4903,7 @@ self_abort_internal (MonoError *error) { MonoException *exc; - mono_error_init (error); + error_init (error); /* FIXME this is insanely broken, it doesn't cause interruption to happen synchronously * since passing FALSE to mono_thread_request_interruption makes sure it returns NULL */ @@ -5003,11 +5001,33 @@ self_suspend_internal (void) event = thread->suspended; MONO_ENTER_GC_SAFE; - res = mono_os_event_wait_one (event, MONO_INFINITE_WAIT); + res = mono_os_event_wait_one (event, MONO_INFINITE_WAIT, TRUE); g_assert (res == MONO_OS_EVENT_WAIT_RET_SUCCESS_0 || res == MONO_OS_EVENT_WAIT_RET_ALERTED); MONO_EXIT_GC_SAFE; } +static void +suspend_for_shutdown_async_call (gpointer unused) +{ + for (;;) + mono_thread_info_yield (); +} + +static SuspendThreadResult +suspend_for_shutdown_critical (MonoThreadInfo *info, gpointer unused) +{ + mono_thread_info_setup_async_call (info, suspend_for_shutdown_async_call, NULL); + return MonoResumeThread; +} + +void +mono_thread_internal_suspend_for_shutdown (MonoInternalThread *thread) +{ + g_assert (thread != mono_thread_internal_current ()); + + mono_thread_info_safe_suspend_and_run (thread_get_tid (thread), FALSE, suspend_for_shutdown_critical, NULL); +} + /* * mono_thread_is_foreign: * @thread: the thread to query