[threads] Store MonoInternalThread in MonoThreadInfo for use when detaching (#5058)
[mono.git] / mono / metadata / runtime.c
index 2b8118f693749bca3761ca69a0090fe88ddf18c3..cd0c0e6123a81ab07a0ee56a2d4aabdf654b25c3 100644 (file)
@@ -1,10 +1,12 @@
-/*
- * runtime.c: Runtime functions
+/**
+ * \file
+ * Runtime functions
  *
  * Authors:
  *  Jonathan Pryor 
  *
  * Copyright 2010 Novell, Inc (http://www.novell.com)
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  */
 
 #include <config.h>
@@ -26,11 +28,10 @@ static gboolean shutting_down = FALSE;
 
 /** 
  * mono_runtime_set_shutting_down:
+ * \deprecated This function can break the shutdown sequence.
  *
- * Invoked by System.Environment.Exit to flag that the runtime
+ * Invoked by \c System.Environment.Exit to flag that the runtime
  * is shutting down.
- *
- * Deprecated. This function can break the shutdown sequence.
  */
 void
 mono_runtime_set_shutting_down (void)
@@ -40,12 +41,8 @@ mono_runtime_set_shutting_down (void)
 
 /**
  * mono_runtime_is_shutting_down:
- *
- * Returns whether the runtime has been flagged for shutdown.
- *
- * This is consumed by the P:System.Environment.HasShutdownStarted
- * property.
- *
+ * This is consumed by the \c P:System.Environment.HasShutdownStarted property.
+ * \returns whether the runtime has been flagged for shutdown.
  */
 gboolean
 mono_runtime_is_shutting_down (void)
@@ -56,6 +53,7 @@ mono_runtime_is_shutting_down (void)
 static void
 fire_process_exit_event (MonoDomain *domain, gpointer user_data)
 {
+       MonoError error;
        MonoClassField *field;
        gpointer pa [2];
        MonoObject *delegate, *exc;
@@ -69,7 +67,8 @@ fire_process_exit_event (MonoDomain *domain, gpointer user_data)
 
        pa [0] = domain;
        pa [1] = NULL;
-       mono_runtime_delegate_invoke (delegate, pa, &exc);
+       mono_runtime_delegate_try_invoke (delegate, pa, &exc, &error);
+       mono_error_cleanup (&error);
 }
 
 static void
@@ -81,11 +80,14 @@ mono_runtime_fire_process_exit_event (void)
 }
 
 
-/*
+/**
+ * mono_runtime_try_shutdown:
+ *
  * Try to initialize runtime shutdown.
+ *
  * After this call completes the thread pool will stop accepting new jobs and no further threads will be created.
  *
- * @return true if shutdown was initiated by this call or false is other thread beat this one
+ * Returns: TRUE if shutdown was initiated by this call or false is other thread beat this one.
  */
 gboolean
 mono_runtime_try_shutdown (void)
@@ -103,9 +105,6 @@ mono_runtime_try_shutdown (void)
 
        mono_runtime_set_shutting_down ();
 
-       /* This will kill the tp threads which cannot be suspended */
-       mono_thread_pool_cleanup ();
-
        /*TODO move the follow to here:
        mono_thread_suspend_all_other_threads (); OR  mono_thread_wait_all_other_threads
 
@@ -115,13 +114,6 @@ mono_runtime_try_shutdown (void)
        return TRUE;
 }
 
-
-gboolean
-mono_runtime_is_critical_method (MonoMethod *method)
-{
-       return FALSE;
-}
-
 /*
 Coordinate the creation of all remaining TLS slots in the runtime.
 No further TLS slots should be created after this function finishes.
@@ -132,6 +124,25 @@ void
 mono_runtime_init_tls (void)
 {
        mono_marshal_init_tls ();
-       mono_thread_pool_init_tls ();
-       mono_thread_init_tls ();
+}
+
+char*
+mono_runtime_get_aotid (void)
+{
+       int i;
+       guint8 aotid_sum = 0;
+       MonoDomain* domain = mono_domain_get ();
+
+       if (!domain->entry_assembly || !domain->entry_assembly->image)
+               return NULL;
+
+       guint8 (*aotid)[16] = &domain->entry_assembly->image->aotid;
+
+       for (i = 0; i < 16; ++i)
+               aotid_sum |= (*aotid)[i];
+
+       if (aotid_sum == 0)
+               return NULL;
+
+       return mono_guid_to_string ((guint8*) aotid);
 }