8 * Copyright 2010 Novell, Inc (http://www.novell.com)
9 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
16 #include <mono/metadata/appdomain.h>
17 #include <mono/metadata/class.h>
18 #include <mono/metadata/class-internals.h>
19 #include <mono/metadata/runtime.h>
20 #include <mono/metadata/monitor.h>
21 #include <mono/metadata/threads-types.h>
22 #include <mono/metadata/threadpool.h>
23 #include <mono/metadata/marshal.h>
24 #include <mono/utils/atomic.h>
26 static gboolean shutting_down_inited = FALSE;
27 static gboolean shutting_down = FALSE;
30 * mono_runtime_set_shutting_down:
32 * Invoked by System.Environment.Exit to flag that the runtime
35 * Deprecated. This function can break the shutdown sequence.
38 mono_runtime_set_shutting_down (void)
44 * mono_runtime_is_shutting_down:
46 * Returns whether the runtime has been flagged for shutdown.
48 * This is consumed by the P:System.Environment.HasShutdownStarted
53 mono_runtime_is_shutting_down (void)
59 fire_process_exit_event (MonoDomain *domain, gpointer user_data)
62 MonoClassField *field;
64 MonoObject *delegate, *exc;
66 field = mono_class_get_field_from_name (mono_defaults.appdomain_class, "ProcessExit");
69 delegate = *(MonoObject **)(((char *)domain->domain) + field->offset);
75 mono_runtime_delegate_try_invoke (delegate, pa, &exc, &error);
76 mono_error_cleanup (&error);
80 mono_runtime_fire_process_exit_event (void)
82 #ifndef MONO_CROSS_COMPILE
83 mono_domain_foreach (fire_process_exit_event, NULL);
89 * mono_runtime_try_shutdown:
91 * Try to initialize runtime shutdown.
93 * After this call completes the thread pool will stop accepting new jobs and no further threads will be created.
95 * Returns: TRUE if shutdown was initiated by this call or false is other thread beat this one.
98 mono_runtime_try_shutdown (void)
100 if (InterlockedCompareExchange (&shutting_down_inited, TRUE, FALSE))
103 mono_runtime_fire_process_exit_event ();
105 shutting_down = TRUE;
107 mono_threads_set_shutting_down ();
109 /* No new threads will be created after this point */
111 mono_runtime_set_shutting_down ();
113 /*TODO move the follow to here:
114 mono_thread_suspend_all_other_threads (); OR mono_thread_wait_all_other_threads
116 mono_runtime_quit ();
124 mono_runtime_is_critical_method (MonoMethod *method)
130 Coordinate the creation of all remaining TLS slots in the runtime.
131 No further TLS slots should be created after this function finishes.
132 This restriction exists because AOT requires offsets to be constant
136 mono_runtime_init_tls (void)
138 mono_marshal_init_tls ();
142 mono_runtime_get_aotid (void)
145 guint8 aotid_sum = 0;
146 MonoDomain* domain = mono_domain_get ();
148 if (!domain->entry_assembly || !domain->entry_assembly->image)
151 guint8 (*aotid)[16] = &domain->entry_assembly->image->aotid;
153 for (i = 0; i < 16; ++i)
154 aotid_sum |= (*aotid)[i];
159 return mono_guid_to_string ((guint8*) aotid);