* Dietmar Maurer (dietmar@ximian.com)
* Patrik Torstensson
*
- * (C) 2001 Ximian, Inc.
+ * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
+ * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
*/
#include <config.h>
* but we can't depend on this).
*/
static guint32 appdomain_thread_id = -1;
+
+/*
+ * Avoid calling TlsSetValue () if possible, since in the io-layer, it acquires
+ * a global lock (!) so it is a contention point.
+ */
+#if (defined(__i386__) || defined(__x86_64__)) && !defined(PLATFORM_WIN32)
+#define NO_TLS_SET_VALUE
+#endif
#ifdef HAVE_KW_THREAD
+
static __thread MonoDomain * tls_appdomain MONO_TLS_FAST;
+
#define GET_APPDOMAIN() tls_appdomain
+
+#ifdef NO_TLS_SET_VALUE
+#define SET_APPDOMAIN(x) do { \
+ tls_appdomain = x; \
+} while (FALSE)
+#else
#define SET_APPDOMAIN(x) do { \
tls_appdomain = x; \
TlsSetValue (appdomain_thread_id, x); \
} while (FALSE)
+#endif
-#else
+#else /* !HAVE_KW_THREAD */
#define GET_APPDOMAIN() ((MonoDomain *)TlsGetValue (appdomain_thread_id))
#define SET_APPDOMAIN(x) TlsSetValue (appdomain_thread_id, x);
guint32
mono_domain_get_tls_key (void)
{
+#ifdef NO_TLS_SET_VALUE
+ g_assert_not_reached ();
+ return 0;
+#else
return appdomain_thread_id;
+#endif
}
gint32
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 ((GHashFunc)mono_string_hash, (GCompareFunc)mono_string_equal);
+ domain->ldstr_table = mono_g_hash_table_new_type ((GHashFunc)mono_string_hash, (GCompareFunc)mono_string_equal, MONO_HASH_KEY_VALUE_GC);
domain->num_jit_info_tables = 1;
domain->jit_info_table = jit_info_table_new (domain);
domain->jit_info_free_queue = NULL;
InitializeCriticalSection (&domain->assemblies_lock);
InitializeCriticalSection (&domain->jit_code_hash_lock);
- domain->shared_generics_hash = NULL;
domain->method_rgctx_hash = NULL;
mono_appdomains_lock ();
return ass;
}
-MonoJitInfo*
-mono_domain_lookup_shared_generic (MonoDomain *domain, MonoMethod *method)
-{
- if (!domain->shared_generics_hash)
- return NULL;
-
- return g_hash_table_lookup (domain->shared_generics_hash, method);
-}
-
-void
-mono_domain_register_shared_generic (MonoDomain *domain, MonoMethod *method, MonoJitInfo *jit_info)
-{
- if (!domain->shared_generics_hash)
- domain->shared_generics_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
-
- g_assert (domain->shared_generics_hash);
-
- g_hash_table_insert (domain->shared_generics_hash, method, jit_info);
-}
-
void
mono_domain_free (MonoDomain *domain, gboolean force)
{
}
g_hash_table_destroy (domain->finalizable_objects_hash);
domain->finalizable_objects_hash = NULL;
- if (domain->shared_generics_hash) {
- g_hash_table_destroy (domain->shared_generics_hash);
- domain->shared_generics_hash = NULL;
- }
if (domain->method_rgctx_hash) {
g_hash_table_destroy (domain->method_rgctx_hash);
domain->method_rgctx_hash = NULL;
return domain->domain_id;
}
+/*
+ * mono_domain_alloc:
+ *
+ * LOCKING: Acquires the domain lock.
+ */
gpointer
mono_domain_alloc (MonoDomain *domain, guint size)
{
+ gpointer res;
+
+ mono_domain_lock (domain);
mono_perfcounters->loader_bytes += size;
- return mono_mempool_alloc (domain->mp, size);
+ res = mono_mempool_alloc (domain->mp, size);
+ mono_domain_unlock (domain);
+
+ return res;
}
+/*
+ * mono_domain_alloc0:
+ *
+ * LOCKING: Acquires the domain lock.
+ */
gpointer
mono_domain_alloc0 (MonoDomain *domain, guint size)
{
+ gpointer res;
+
+ mono_domain_lock (domain);
mono_perfcounters->loader_bytes += size;
- return mono_mempool_alloc0 (domain->mp, size);
+ res = mono_mempool_alloc0 (domain->mp, size);
+ mono_domain_unlock (domain);
+
+ return res;
}
+/*
+ * mono_domain_code_reserve:
+ *
+ * LOCKING: Acquires the domain lock.
+ */
+void*
+mono_domain_code_reserve (MonoDomain *domain, int size)
+{
+ gpointer res;
+
+ mono_domain_lock (domain);
+ res = mono_code_manager_reserve (domain->code_mp, size);
+ mono_domain_unlock (domain);
+
+ return res;
+}
+
+/*
+ * mono_domain_code_reserve_align:
+ *
+ * LOCKING: Acquires the domain lock.
+ */
+void*
+mono_domain_code_reserve_align (MonoDomain *domain, int size, int alignment)
+{
+ gpointer res;
+
+ mono_domain_lock (domain);
+ res = mono_code_manager_reserve_align (domain->code_mp, size, alignment);
+ mono_domain_unlock (domain);
+
+ return res;
+}
+
+/*
+ * mono_domain_code_commit:
+ *
+ * LOCKING: Acquires the domain lock.
+ */
+void
+mono_domain_code_commit (MonoDomain *domain, void *data, int size, int newsize)
+{
+ mono_domain_lock (domain);
+ mono_code_manager_commit (domain->code_mp, data, size, newsize);
+ mono_domain_unlock (domain);
+}
+
+/*
+ * mono_domain_code_foreach:
+ * Iterate over the code thunks of the code manager of @domain.
+ *
+ * The @func callback MUST not take any locks. If it really needs to, it must respect
+ * the locking rules of the runtime: http://www.mono-project.com/Mono:Runtime:Documentation:ThreadSafety
+ * LOCKING: Acquires the domain lock.
+ */
+
+void
+mono_domain_code_foreach (MonoDomain *domain, MonoCodeManagerFunc func, void *user_data)
+{
+ mono_domain_lock (domain);
+ mono_code_manager_foreach (domain->code_mp, func, user_data);
+ mono_domain_unlock (domain);
+}
+
+
void
mono_context_set (MonoAppContext * new_context)
{
GMarkupParseContext *context;
char *text;
gsize len;
- struct stat buf;
const char *bundled_config;
char *config_filename;
} else {
config_filename = g_strconcat (exe_filename, ".config", NULL);
- if (stat (config_filename, &buf) != 0) {
- g_free (config_filename);
- return NULL;
- }
-
if (!g_file_get_contents (config_filename, &text, &len, NULL)) {
g_free (config_filename);
return NULL;