From 31dd3aca62a9ececbd2209cfdd05013e8f3dc473 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Sat, 31 Oct 2009 22:36:20 +0000 Subject: [PATCH] Backport: 2009-10-31 Miguel de Icaza * threads.c: refactor the code that initializes the thread_start_args into a reusable function and use this in the two methods that start up threads. svn path=/branches/mono-2-6/mono/; revision=145155 --- mono/metadata/ChangeLog | 6 ++++++ mono/metadata/threads.c | 34 ++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/mono/metadata/ChangeLog b/mono/metadata/ChangeLog index a3569f608c0..076abbfbb08 100644 --- a/mono/metadata/ChangeLog +++ b/mono/metadata/ChangeLog @@ -1,3 +1,9 @@ +2009-10-31 Miguel de Icaza + + * threads.c: refactor the code that initializes the + thread_start_args into a reusable function and use this in the two + methods that start up threads. + 2009-10-31 Zoltan Varga * appdomain.c (mono_domain_try_unload): Applied patch from Romain Tartière. diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index 8ba07955744..0d9691f72d2 100644 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -637,8 +637,7 @@ static guint32 WINAPI start_wrapper(void *data) } mono_threads_lock (); - if (thread_start_args) - mono_g_hash_table_remove (thread_start_args, thread); + mono_g_hash_table_remove (thread_start_args, thread); mono_threads_unlock (); g_free (start_info); @@ -740,6 +739,24 @@ gpointer mono_create_thread (WapiSecurityAttributes *security, return res; } +/* + * The thread start argument may be an object reference, and there is + * no ref to keep it alive when the new thread is started but not yet + * registered with the collector. So we store it in a GC tracked hash + * table. + * + * LOCKING: Assumes the threads lock is held. + */ +static void +register_thread_start_argument (MonoThread *thread, struct StartInfo *start_info) +{ + if (thread_start_args == NULL) { + MONO_GC_REGISTER_ROOT (thread_start_args); + thread_start_args = mono_g_hash_table_new (NULL, NULL); + } + mono_g_hash_table_insert (thread_start_args, thread, start_info->start_arg); +} + MonoThread* mono_thread_create_internal (MonoDomain *domain, gpointer func, gpointer arg, gboolean threadpool_thread) { MonoThread *thread; @@ -766,17 +783,9 @@ MonoThread* mono_thread_create_internal (MonoDomain *domain, gpointer func, gpoi MONO_GC_REGISTER_ROOT (threads_starting_up); threads_starting_up = mono_g_hash_table_new (NULL, NULL); } - if (thread_start_args == NULL) { - MONO_GC_REGISTER_ROOT (thread_start_args); - thread_start_args = mono_g_hash_table_new (NULL, NULL); - } + + register_thread_start_argument (thread, start_info); mono_g_hash_table_insert (threads_starting_up, thread, thread); - /* - * The argument may be an object reference, and there is no ref to keep it alive - * when the new thread is started but not yet registered with the collector. So - * we store it in a GC tracked hash table. - */ - mono_g_hash_table_insert (thread_start_args, thread, start_info->start_arg); mono_threads_unlock (); /* Create suspended, so we can do some housekeeping before the thread @@ -1021,6 +1030,7 @@ HANDLE ves_icall_System_Threading_Thread_Thread_internal(MonoThread *this, } mono_threads_lock (); + register_thread_start_argument (this, start_info); if (threads_starting_up == NULL) { MONO_GC_REGISTER_ROOT (threads_starting_up); threads_starting_up = mono_g_hash_table_new (NULL, NULL); -- 2.11.4.GIT