From 764f9cbd32ee16f86d405b58a69c4e252624668c Mon Sep 17 00:00:00 2001 From: Rodrigo Kumpera Date: Tue, 6 Dec 2011 09:12:48 -0200 Subject: [PATCH] Use mono-tls for the current domain. * domain.c: Use mono-tls for the current domain variable. Sgen depends on this so it has to be lock free and the io-layer version is not. Fixes bxc #2326 --- mono/metadata/domain.c | 17 +++++++++-------- mono/metadata/object-internals.h | 4 ++-- mono/metadata/sgen-os-mach.c | 2 +- mono/mini/mini-amd64.c | 2 +- mono/mini/mini-mips.c | 7 ++----- mono/mini/mini-ppc.c | 7 ++----- mono/mini/mini-x86.c | 2 +- 7 files changed, 18 insertions(+), 23 deletions(-) diff --git a/mono/metadata/domain.c b/mono/metadata/domain.c index 0c36dd53ec0..d425c597d6a 100644 --- a/mono/metadata/domain.c +++ b/mono/metadata/domain.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -44,7 +45,7 @@ * 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; +static MonoNativeTlsKey appdomain_thread_id; /* * Avoid calling TlsSetValue () if possible, since in the io-layer, it acquires @@ -67,14 +68,14 @@ static __thread MonoDomain * tls_appdomain MONO_TLS_FAST; #else #define SET_APPDOMAIN(x) do { \ tls_appdomain = x; \ - TlsSetValue (appdomain_thread_id, x); \ + mono_native_tls_set_value (appdomain_thread_id, x); \ } while (FALSE) #endif #else /* !HAVE_KW_THREAD */ -#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) mono_native_tls_set_value (appdomain_thread_id, x); #endif @@ -157,8 +158,8 @@ get_runtime_by_version (const char *version); static MonoImage* mono_jit_info_find_aot_module (guint8* addr); -guint32 -mono_domain_get_tls_key (void) +MonoNativeTlsKey +mono_domain_get_native_tls_key (void) { return appdomain_thread_id; } @@ -1301,7 +1302,7 @@ mono_init_internal (const char *filename, const char *exe_filename, const char * mono_gc_base_init (); - appdomain_thread_id = TlsAlloc (); + mono_native_tls_alloc (&appdomain_thread_id, NULL); InitializeCriticalSection (&appdomains_mutex); @@ -1766,7 +1767,7 @@ mono_cleanup (void) mono_debug_cleanup (); mono_metadata_cleanup (); - TlsFree (appdomain_thread_id); + mono_native_tls_free (appdomain_thread_id); DeleteCriticalSection (&appdomains_mutex); /* diff --git a/mono/metadata/object-internals.h b/mono/metadata/object-internals.h index 19fde8caaf7..27349a149e7 100644 --- a/mono/metadata/object-internals.h +++ b/mono/metadata/object-internals.h @@ -659,8 +659,8 @@ mono_thread_get_native_tls_key (void) MONO_INTERNAL; gint32 mono_thread_get_tls_offset (void) MONO_INTERNAL; -guint32 -mono_domain_get_tls_key (void) MONO_INTERNAL; +MonoNativeTlsKey +mono_domain_get_native_tls_key (void) MONO_INTERNAL; gint32 mono_domain_get_tls_offset (void) MONO_INTERNAL; diff --git a/mono/metadata/sgen-os-mach.c b/mono/metadata/sgen-os-mach.c index dc3d58c12c6..876810c4caf 100644 --- a/mono/metadata/sgen-os-mach.c +++ b/mono/metadata/sgen-os-mach.c @@ -66,7 +66,7 @@ mono_sgen_suspend_thread (SgenThreadInfo *info) mono_mach_arch_thread_state_to_mcontext (state, mctx); ctx.uc_mcontext = mctx; - info->stopped_domain = mono_mach_arch_get_tls_value_from_thread ((pthread_t)info->id, mono_pthread_key_for_tls (mono_domain_get_tls_key ())); + info->stopped_domain = mono_mach_arch_get_tls_value_from_thread ((pthread_t)info->id, mono_domain_get_native_tls_key ()); info->stopped_ip = (gpointer) mono_mach_arch_get_ip (state); stack_start = (char*) mono_mach_arch_get_sp (state) - REDZONE_SIZE; /* If stack_start is not within the limits, then don't set it in info and we will be restarted. */ diff --git a/mono/mini/mini-amd64.c b/mono/mini/mini-amd64.c index bae0eaecb88..40f0fe96608 100644 --- a/mono/mini/mini-amd64.c +++ b/mono/mini/mini-amd64.c @@ -7921,7 +7921,7 @@ mono_arch_setup_jit_tls_data (MonoJitTlsData *tls) * We need to init this multiple times, since when we are first called, the key might not * be initialized yet. */ - appdomain_tls_offset = mono_domain_get_tls_key (); + appdomain_tls_offset = mono_domain_get_native_tls_key (); lmf_tls_offset = mono_get_jit_tls_key (); lmf_addr_tls_offset = mono_get_jit_tls_key (); diff --git a/mono/mini/mini-mips.c b/mono/mini/mini-mips.c index 2c544c45a7d..4955916c00d 100644 --- a/mono/mini/mini-mips.c +++ b/mono/mini/mini-mips.c @@ -5448,12 +5448,9 @@ setup_tls_access (void) #endif } if (monodomain_key == -1) { - ptk = mono_domain_get_tls_key (); + ptk = mono_domain_get_native_tls_key (); if (ptk < 1024) { - ptk = mono_pthread_key_for_tls (ptk); - if (ptk < 1024) { - monodomain_key = ptk; - } + monodomain_key = ptk; } } if (lmf_pthread_key == -1) { diff --git a/mono/mini/mini-ppc.c b/mono/mini/mini-ppc.c index 90240f63e5b..64d04269c03 100644 --- a/mono/mini/mini-ppc.c +++ b/mono/mini/mini-ppc.c @@ -5717,12 +5717,9 @@ setup_tls_access (void) /* if not TLS_MODE_NPTL or local dynamic (as indicated by mono_domain_get_tls_offset returning -1) then use keyed access. */ if (monodomain_key == -1) { - ptk = mono_domain_get_tls_key (); + ptk = mono_domain_get_native_tls_key (); if (ptk < 1024) { - ptk = mono_pthread_key_for_tls (ptk); - if (ptk < 1024) { - monodomain_key = ptk; - } + monodomain_key = ptk; } } diff --git a/mono/mini/mini-x86.c b/mono/mini/mini-x86.c index d26bda0bb84..5621b7d7415 100644 --- a/mono/mini/mini-x86.c +++ b/mono/mini/mini-x86.c @@ -5512,7 +5512,7 @@ mono_arch_setup_jit_tls_data (MonoJitTlsData *tls) * We need to init this multiple times, since when we are first called, the key might not * be initialized yet. */ - appdomain_tls_offset = mono_domain_get_tls_key (); + appdomain_tls_offset = mono_domain_get_native_tls_key (); lmf_tls_offset = mono_get_jit_tls_key (); /* Only 64 tls entries can be accessed using inline code */ -- 2.11.4.GIT