[threads] Rework MonoThreadInfoCallbacks.thread_{register,detach,unregister} callback...
[mono.git] / mono / metadata / domain.c
index 12e88ace7cc7775f155ace68f0e9a3c4cf13f005..1d353b1da070a4857d2e7a883eaa61ff73a88d38 100644 (file)
@@ -99,9 +99,9 @@ static const MonoRuntimeInfo *current_runtime = NULL;
 /* This is the list of runtime versions supported by this JIT.
  */
 static const MonoRuntimeInfo supported_runtimes[] = {
-       {"v4.0.30319","4.5",               NULL, { {4,0,0,0}, {10,0,0,0}, {4,0,0,0}, {4,0,0,0}, {4,0,0,0} } },
-       {"mobile",    "2.1", "7cec85d7bea7798e", { {2,0,5,0}, {10,0,0,0}, {2,0,5,0}, {2,0,5,0}, {4,0,0,0} } },
-       {"moonlight", "2.1",               NULL, { {2,0,5,0}, { 9,0,0,0}, {3,5,0,0}, {3,0,0,0}, NOT_AVAIL } },
+       {"v4.0.30319","4.5", { {4,0,0,0}, {10,0,0,0}, {4,0,0,0}, {4,0,0,0}, {4,0,0,0} } },
+       {"mobile",    "2.1", { {2,0,5,0}, {10,0,0,0}, {2,0,5,0}, {2,0,5,0}, {4,0,0,0} } },
+       {"moonlight", "2.1", { {2,0,5,0}, { 9,0,0,0}, {3,5,0,0}, {3,0,0,0}, NOT_AVAIL } },
 };
 
 #undef NOT_AVAIL
@@ -409,7 +409,6 @@ mono_domain_create (void)
        domain->assembly_bindings_parsed = FALSE;
        domain->class_vtable_array = g_ptr_array_new ();
        domain->proxy_vtable_hash = g_hash_table_new ((GHashFunc)mono_ptrarray_hash, (GCompareFunc)mono_ptrarray_equal);
-       domain->static_data_array = NULL;
        mono_jit_code_hash_init (&domain->jit_code_hash);
        domain->ldstr_table = mono_g_hash_table_new_type ((GHashFunc)mono_string_hash, (GCompareFunc)mono_string_equal, MONO_HASH_KEY_VALUE_GC, MONO_ROOT_SOURCE_DOMAIN, "domain string constants table");
        domain->num_jit_info_tables = 1;
@@ -465,7 +464,7 @@ mono_init_internal (const char *filename, const char *exe_filename, const char *
        MonoAssembly *ass = NULL;
        MonoImageOpenStatus status = MONO_IMAGE_OK;
        const MonoRuntimeInfo* runtimes [G_N_ELEMENTS (supported_runtimes) + 1] = { NULL };
-       int n, dummy;
+       int n;
 
 #ifdef DEBUG_DOMAIN_UNLOAD
        debug_domain_unload = TRUE;
@@ -502,7 +501,7 @@ mono_init_internal (const char *filename, const char *exe_filename, const char *
        mono_counters_register ("Max HashTable Chain Length", MONO_COUNTER_INT|MONO_COUNTER_METADATA, &mono_g_hash_table_max_chain_length);
 
        mono_gc_base_init ();
-       mono_thread_info_attach (&dummy);
+       mono_thread_info_attach ();
 
        mono_coop_mutex_init_recursive (&appdomains_mutex);
 
@@ -1038,10 +1037,6 @@ mono_domain_free (MonoDomain *domain, gboolean force)
 
        mono_debug_domain_unload (domain);
 
-       mono_appdomains_lock ();
-       appdomains_list [domain->domain_id] = NULL;
-       mono_appdomains_unlock ();
-
        /* must do this early as it accesses fields and types */
        if (domain->special_static_fields) {
                mono_alloc_special_static_data_free (domain->special_static_fields);
@@ -1150,10 +1145,6 @@ mono_domain_free (MonoDomain *domain, gboolean force)
        domain->class_vtable_array = NULL;
        g_hash_table_destroy (domain->proxy_vtable_hash);
        domain->proxy_vtable_hash = NULL;
-       if (domain->static_data_array) {
-               mono_gc_free_fixed (domain->static_data_array);
-               domain->static_data_array = NULL;
-       }
        mono_internal_hash_table_destroy (&domain->jit_code_hash);
 
        /*
@@ -1219,6 +1210,10 @@ mono_domain_free (MonoDomain *domain, gboolean force)
 
        mono_gc_deregister_root ((char*)&(domain->MONO_DOMAIN_FIRST_GC_TRACKED));
 
+       mono_appdomains_lock ();
+       appdomains_list [domain->domain_id] = NULL;
+       mono_appdomains_unlock ();
+
        /* FIXME: anything else required ? */
 
        mono_gc_free_fixed (domain);
@@ -1399,6 +1394,12 @@ mono_context_set (MonoAppContext * new_context)
        SET_APPCONTEXT (new_context);
 }
 
+void
+mono_context_set_handle (MonoAppContextHandle new_context)
+{
+       SET_APPCONTEXT (MONO_HANDLE_RAW (new_context));
+}
+
 /**
  * mono_context_get:
  *
@@ -1410,6 +1411,17 @@ mono_context_get (void)
        return GET_APPCONTEXT ();
 }
 
+/**
+ * mono_context_get_handle:
+ *
+ * Returns: the current Mono Application Context.
+ */
+MonoAppContextHandle
+mono_context_get_handle (void)
+{
+       return MONO_HANDLE_NEW (MonoAppContext, GET_APPCONTEXT ());
+}
+
 /**
  * mono_context_get_id:
  * \param context the context to operate on.
@@ -1436,40 +1448,6 @@ mono_context_get_domain_id (MonoAppContext *context)
        return context->domain_id;
 }
 
-/* LOCKING: the caller holds the lock for this domain */
-void
-mono_domain_add_class_static_data (MonoDomain *domain, MonoClass *klass, gpointer data, guint32 *bitmap)
-{
-       /* Note [Domain Static Data Array]:
-        *
-        * Entry 0 in the array is the index of the next free slot.
-        * Entry 1 is the total size of the array.
-        */
-       int next;
-       if (domain->static_data_array) {
-               int size = GPOINTER_TO_INT (domain->static_data_array [1]);
-               next = GPOINTER_TO_INT (domain->static_data_array [0]);
-               if (next >= size) {
-                       /* 'data' is allocated by alloc_fixed */
-                       gpointer *new_array = (gpointer *)mono_gc_alloc_fixed (sizeof (gpointer) * (size * 2), MONO_GC_ROOT_DESCR_FOR_FIXED (size * 2), MONO_ROOT_SOURCE_DOMAIN, "static field list");
-                       mono_gc_memmove_aligned (new_array, domain->static_data_array, sizeof (gpointer) * size);
-                       size *= 2;
-                       new_array [1] = GINT_TO_POINTER (size);
-                       mono_gc_free_fixed (domain->static_data_array);
-                       domain->static_data_array = new_array;
-               }
-       } else {
-               int size = 32;
-               gpointer *new_array = (gpointer *)mono_gc_alloc_fixed (sizeof (gpointer) * size, MONO_GC_ROOT_DESCR_FOR_FIXED (size), MONO_ROOT_SOURCE_DOMAIN, "static field list");
-               next = 2;
-               new_array [0] = GINT_TO_POINTER (next);
-               new_array [1] = GINT_TO_POINTER (size);
-               domain->static_data_array = new_array;
-       }
-       domain->static_data_array [next++] = data;
-       domain->static_data_array [0] = GINT_TO_POINTER (next);
-}
-
 /**
  * mono_get_corlib:
  * Use this function to get the \c MonoImage* for the \c mscorlib.dll assembly