2 * runtime.c: Runtime functions
7 * Copyright 2010 Novell, Inc (http://www.novell.com)
14 #include <mono/metadata/appdomain.h>
15 #include <mono/metadata/class.h>
16 #include <mono/metadata/class-internals.h>
17 #include <mono/metadata/runtime.h>
18 #include <mono/metadata/monitor.h>
19 #include <mono/metadata/threads-types.h>
20 #include <mono/metadata/threadpool.h>
21 #include <mono/utils/atomic.h>
23 static gboolean shutting_down_inited = FALSE;
24 static gboolean shutting_down = FALSE;
27 * mono_runtime_set_shutting_down:
29 * Invoked by System.Environment.Exit to flag that the runtime
32 * Deprecated. This function can break the shutdown sequence.
35 mono_runtime_set_shutting_down (void)
41 * mono_runtime_is_shutting_down:
43 * Returns whether the runtime has been flagged for shutdown.
45 * This is consumed by the P:System.Environment.HasShutdownStarted
50 mono_runtime_is_shutting_down (void)
56 fire_process_exit_event (MonoDomain *domain, gpointer user_data)
58 MonoClassField *field;
60 MonoObject *delegate, *exc;
62 field = mono_class_get_field_from_name (mono_defaults.appdomain_class, "ProcessExit");
65 delegate = *(MonoObject **)(((char *)domain->domain) + field->offset);
71 mono_runtime_delegate_invoke (delegate, pa, &exc);
75 mono_runtime_fire_process_exit_event (void)
77 #ifndef MONO_CROSS_COMPILE
78 mono_domain_foreach (fire_process_exit_event, NULL);
84 * Try to initialize runtime shutdown.
85 * After this call completes the thread pool will stop accepting new jobs and no further threads will be created.
87 * @return true if shutdown was initiated by this call or false is other thread beat this one
90 mono_runtime_try_shutdown (void)
92 if (InterlockedCompareExchange (&shutting_down_inited, TRUE, FALSE))
95 mono_runtime_fire_process_exit_event ();
99 mono_threads_set_shutting_down ();
101 /* No new threads will be created after this point */
103 mono_runtime_set_shutting_down ();
105 /* This will kill the tp threads which cannot be suspended */
106 mono_thread_pool_cleanup ();
108 /*TODO move the follow to here:
109 mono_thread_suspend_all_other_threads (); OR mono_thread_wait_all_other_threads
111 mono_runtime_quit ();
119 mono_runtime_is_critical_method (MonoMethod *method)
121 if (mono_monitor_is_il_fastpath_wrapper (method))