Browse files

Make MonoThreadCleanupFunc take an InternalThread instead of a Thread.

Move its definition to threads-types.h since it is not public API. Use this
to remove the workaround in thread_cleanup () so the JIT info for threads is
properly cleaned up at shutdown.
  • Loading branch information...
1 parent 28e93c3 commit 8d2deaba77b04b3854d343337912f6119cd6daf6 @vargaz vargaz committed Sep 18, 2010
Showing with 11 additions and 19 deletions.
  1. +4 −0 mono/metadata/threads-types.h
  2. +3 −11 mono/metadata/threads.c
  3. +0 −3 mono/metadata/threads.h
  4. +4 −5 mono/mini/mini.c
View
4 mono/metadata/threads-types.h
@@ -52,12 +52,16 @@ typedef LPTHREAD_START_ROUTINE WapiThreadStart;
typedef struct _MonoInternalThread MonoInternalThread;
+typedef void (*MonoThreadCleanupFunc) (MonoInternalThread* thread);
+
gpointer mono_create_thread (WapiSecurityAttributes *security,
guint32 stacksize, WapiThreadStart start,
gpointer param, guint32 create, gsize *tid) MONO_INTERNAL;
MonoInternalThread* mono_thread_create_internal (MonoDomain *domain, gpointer func, gpointer arg, gboolean threadpool_thread) MONO_INTERNAL;
+void mono_threads_install_cleanup (MonoThreadCleanupFunc func) MONO_INTERNAL;
+
void ves_icall_System_Threading_Thread_ConstructInternalThread (MonoThread *this) MONO_INTERNAL;
HANDLE ves_icall_System_Threading_Thread_Thread_internal(MonoThread *this_obj, MonoObject *start) MONO_INTERNAL;
void ves_icall_System_Threading_InternalThread_Thread_free_internal(MonoInternalThread *this_obj, HANDLE thread) MONO_INTERNAL;
View
14 mono/metadata/threads.c
@@ -556,6 +556,9 @@ static void thread_cleanup (MonoInternalThread *thread)
mono_array_set (thread->cached_culture_info, MonoObject*, i, NULL);
}
+ if (mono_thread_cleanup_fn)
+ mono_thread_cleanup_fn (thread);
+
/* if the thread is not in the hash it has been removed already */
if (!handle_remove (thread))
return;
@@ -578,17 +581,6 @@ static void thread_cleanup (MonoInternalThread *thread)
mono_free_static_data (thread->static_data, TRUE);
thread->static_data = NULL;
- /*
- * FIXME: The check for shutting_down here is a kludge and
- * should be removed. The reason we need it here is because
- * mono_thread_manage() does not wait for finalizer threads,
- * so we might still be at this point in a finalizer thread
- * after the main thread has cleared the root domain, so
- * thread could have been zeroed out.
- */
- if (mono_thread_cleanup_fn && !shutting_down)
- mono_thread_cleanup_fn (thread->root_domain_thread);
-
small_id_free (thread->small_id);
thread->small_id = -2;
}
View
3 mono/metadata/threads.h
@@ -17,8 +17,6 @@
MONO_BEGIN_DECLS
-typedef void (*MonoThreadCleanupFunc) (MonoThread* thread);
-
/* This callback should return TRUE if the runtime must wait for the thread, FALSE otherwise */
typedef mono_bool (*MonoThreadManageCallback) (MonoThread* thread);
@@ -41,7 +39,6 @@ extern MonoThread *mono_thread_attach (MonoDomain *domain);
extern void mono_thread_detach (MonoThread *thread);
extern void mono_thread_exit (void);
-void mono_threads_install_cleanup (MonoThreadCleanupFunc func);
void mono_thread_set_manage_callback (MonoThread *thread, MonoThreadManageCallback func);
extern void mono_threads_set_default_stacksize (uint32_t stacksize);
View
9 mono/mini/mini.c
@@ -2543,10 +2543,9 @@ mono_thread_attach_cb (intptr_t tid, gpointer stack_start)
}
static void
-mini_thread_cleanup (MonoThread *thread)
+mini_thread_cleanup (MonoInternalThread *thread)
{
- MonoInternalThread *internal = thread->internal_thread;
- MonoJitTlsData *jit_tls = internal->jit_data;
+ MonoJitTlsData *jit_tls = thread->jit_data;
if (jit_tls) {
mono_debugger_thread_cleanup (jit_tls);
@@ -2555,15 +2554,15 @@ mini_thread_cleanup (MonoThread *thread)
mono_free_altstack (jit_tls);
g_free (jit_tls->first_lmf);
g_free (jit_tls);
- internal->jit_data = NULL;
+ thread->jit_data = NULL;
/* We can't clean up tls information if we are on another thread, it will clean up the wrong stuff
* It would be nice to issue a warning when this happens outside of the shutdown sequence. but it's
* not a trivial thing.
*
* The current offender is mono_thread_manage which cleanup threads from the outside.
*/
- if (internal == mono_thread_internal_current ()) {
+ if (thread == mono_thread_internal_current ()) {
TlsSetValue (mono_jit_tls_id, NULL);
#ifdef HAVE_KW_THREAD

0 comments on commit 8d2deab

Please sign in to comment.