*
* Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
* Copyright 2004-2009 Novell, Inc (http://www.novell.com)
+ * Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
*/
#include <config.h>
#include <mono/utils/mono-membar.h>
#include <mono/utils/mono-counters.h>
#include <mono/utils/hazard-pointer.h>
+#include <mono/utils/mono-tls.h>
#include <mono/metadata/object.h>
#include <mono/metadata/object-internals.h>
#include <mono/metadata/domain-internals.h>
* or the other (we used to do it because tls slots were GC-tracked,
* 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(HOST_WIN32)
-#define NO_TLS_SET_VALUE
-#endif
+static MonoNativeTlsKey appdomain_thread_id;
#ifdef MONO_HAVE_FAST_TLS
#define GET_APPDOMAIN() ((MonoDomain*)MONO_FAST_TLS_GET(tls_appdomain))
-#ifdef NO_TLS_SET_VALUE
-#define SET_APPDOMAIN(x) do { \
- MONO_FAST_TLS_SET (tls_appdomain,x); \
-} while (FALSE)
-#else
#define SET_APPDOMAIN(x) do { \
MONO_FAST_TLS_SET (tls_appdomain,x); \
- TlsSetValue (appdomain_thread_id, x); \
+ mono_native_tls_set_value (appdomain_thread_id, x); \
+ mono_gc_set_current_thread_appdomain (x); \
} while (FALSE)
-#endif
#else /* !MONO_HAVE_FAST_TLS */
-#define GET_APPDOMAIN() ((MonoDomain *)TlsGetValue (appdomain_thread_id))
-#define SET_APPDOMAIN(x) TlsSetValue (appdomain_thread_id, x);
+#define GET_APPDOMAIN() ((MonoDomain *)mono_native_tls_get_value (appdomain_thread_id))
+#define SET_APPDOMAIN(x) do { \
+ mono_native_tls_set_value (appdomain_thread_id, x); \
+ mono_gc_set_current_thread_appdomain (x); \
+ } while (FALSE)
#endif
{"v2.0.50727","2.0", { {2,0,0,0}, {8,0,0,0}, { 3, 5, 0, 0 } } },
{"v4.0.20506","4.0", { {4,0,0,0}, {10,0,0,0}, { 4, 0, 0, 0 } } },
{"v4.0.30128","4.0", { {4,0,0,0}, {10,0,0,0}, { 4, 0, 0, 0 } } },
- {"v4.0.30319","4.0", { {4,0,0,0}, {10,0,0,0}, { 4, 0, 0, 0 } } },
+ {"v4.0.30319","4.5", { {4,0,0,0}, {10,0,0,0}, { 4, 0, 0, 0 } } },
{"moonlight", "2.1", { {2,0,5,0}, {9,0,0,0}, { 3, 5, 0, 0 } } },
};
static MonoImage*
mono_jit_info_find_aot_module (guint8* addr);
-guint32
+MonoNativeTlsKey
mono_domain_get_tls_key (void)
{
return appdomain_thread_id;
domain->jit_info_free_queue = NULL;
domain->finalizable_objects_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
domain->track_resurrection_handles_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
+ domain->ftnptrs_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
InitializeCriticalSection (&domain->lock);
InitializeCriticalSection (&domain->assemblies_lock);
/* Avoid system error message boxes. */
SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
#endif
-#if defined(__ia64__) || defined(__ppc64__) || defined(__powerpc64__)
- domain->ftnptrs_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
-#endif
mono_perfcounters_init ();
mono_gc_base_init ();
MONO_FAST_TLS_INIT (tls_appdomain);
- appdomain_thread_id = TlsAlloc ();
+ mono_native_tls_alloc (&appdomain_thread_id, NULL);
InitializeCriticalSection (&appdomains_mutex);
mono_debug_cleanup ();
mono_metadata_cleanup ();
- TlsFree (appdomain_thread_id);
+ mono_native_tls_free (appdomain_thread_id);
DeleteCriticalSection (&appdomains_mutex);
- /*
- * This should be called last as TlsGetValue ()/TlsSetValue () can be called during
- * shutdown.
- */
#ifndef HOST_WIN32
_wapi_cleanup ();
#endif
g_hash_table_destroy (domain->generic_virtual_thunks);
domain->generic_virtual_thunks = NULL;
}
-#if defined(__ia64__) || defined(__ppc64__) || defined(__powerpc64__)
if (domain->ftnptrs_hash) {
g_hash_table_destroy (domain->ftnptrs_hash);
domain->ftnptrs_hash = NULL;
}
-#endif
DeleteCriticalSection (&domain->finalizable_objects_hash_lock);
DeleteCriticalSection (&domain->assemblies_lock);
if (next >= size) {
/* 'data' is allocated by alloc_fixed */
gpointer *new_array = mono_gc_alloc_fixed (sizeof (gpointer) * (size * 2), MONO_GC_ROOT_DESCR_FOR_FIXED (size * 2));
- memcpy (new_array, domain->static_data_array, sizeof (gpointer) * size);
+ mono_gc_memmove (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);
{
int n;
int max = G_N_ELEMENTS (supported_runtimes);
- gboolean do_partial_match;
int vlen;
if (!version)
return NULL;
- vlen = strlen (version);
- if (vlen >= 4 && version [1] - '0' >= 4)
- do_partial_match = TRUE;
- else
- do_partial_match = FALSE;
-
for (n=0; n<max; n++) {
- if (do_partial_match && strncmp (version, supported_runtimes[n].runtime_version, vlen) == 0)
- return &supported_runtimes[n];
if (strcmp (version, supported_runtimes[n].runtime_version) == 0)
return &supported_runtimes[n];
}
+
+ vlen = strlen (version);
+ if (vlen >= 4 && version [1] - '0' >= 4) {
+ for (n=0; n<max; n++) {
+ if (strncmp (version, supported_runtimes[n].runtime_version, 4) == 0)
+ return &supported_runtimes[n];
+ }
+ }
+
return NULL;
}