static MonoCoopMutex reference_queue_mutex;
static GSList *domains_to_finalize;
-static MonoMList *threads_to_finalize;
static gboolean finalizer_thread_exited;
/* Uses finalizer_mutex */
return res;
}
-static gboolean
-add_thread_to_finalize (MonoInternalThread *thread, MonoError *error)
-{
- mono_error_init (error);
- mono_finalizer_lock ();
- if (!threads_to_finalize)
- MONO_GC_REGISTER_ROOT_SINGLE (threads_to_finalize, MONO_ROOT_SOURCE_FINALIZER_QUEUE, "finalizable threads list");
- threads_to_finalize = mono_mlist_append_checked (threads_to_finalize, (MonoObject*)thread, error);
- mono_finalizer_unlock ();
- return is_ok (error);
-}
-
/*
* actually, we might want to queue the finalize requests in a separate thread,
* but we need to be careful about the execution domain of the thread...
if (mono_gc_is_finalizer_internal_thread (t))
/* Avoid finalizing ourselves */
return;
-
- if (t->threadpool_thread && finalizing_root_domain) {
- /* Don't finalize threadpool threads when
- shutting down - they're finalized when the
- threadpool shuts down. */
- if (!add_thread_to_finalize (t, &error))
- goto unhandled_error;
- return;
- }
}
if (o->vtable->klass->image == mono_defaults.corlib && !strcmp (o->vtable->klass->name, "DynamicMethod") && finalizing_root_domain) {
mono_domain_set_internal (caller_domain);
}
-void
-mono_gc_finalize_threadpool_threads (void)
-{
- while (threads_to_finalize) {
- MonoInternalThread *thread = (MonoInternalThread*) mono_mlist_get_data (threads_to_finalize);
-
- /* Force finalization of the thread. */
- thread->threadpool_thread = FALSE;
- mono_object_register_finalizer ((MonoObject*)thread);
-
- mono_gc_run_finalize (thread, NULL);
-
- threads_to_finalize = mono_mlist_next (threads_to_finalize);
- }
-}
-
gpointer
mono_gc_out_of_memory (size_t size)
{
goto done;
}
- if (domain == mono_get_root_domain ()) {
- mono_threadpool_cleanup ();
- mono_gc_finalize_threadpool_threads ();
- }
-
done:
if (InterlockedDecrement (&req->ref) == 0) {
mono_coop_sem_destroy (&req->done);
mono_gc_init_finalizer_thread (void)
{
MonoError error;
- gc_thread = mono_thread_create_internal (mono_domain_get (), finalizer_thread, NULL, FALSE, 0, &error);
+ gc_thread = mono_thread_create_internal (mono_domain_get (), finalizer_thread, NULL, MONO_THREAD_CREATE_FLAGS_NONE, &error);
mono_error_assert_ok (&error);
}