From a96b9dd61494d7f1ae22523301f283e11da65f85 Mon Sep 17 00:00:00 2001 From: Rodrigo Kumpera Date: Tue, 6 Dec 2011 00:57:01 -0200 Subject: [PATCH] Move current thread to use mono-tls. --- mono/metadata/object-internals.h | 5 +++-- mono/metadata/threads.c | 17 +++++++++-------- mono/mini/mini-mips.c | 11 +++-------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/mono/metadata/object-internals.h b/mono/metadata/object-internals.h index c359ef9d48f..19fde8caaf7 100644 --- a/mono/metadata/object-internals.h +++ b/mono/metadata/object-internals.h @@ -10,6 +10,7 @@ #include #include "mono/utils/mono-compiler.h" #include "mono/utils/mono-error.h" +#include "mono/utils/mono-tls.h" /* * We should find a better place for this stuff. We can't put it in mono-compiler.h, @@ -652,8 +653,8 @@ mono_type_initialization_cleanup (void) MONO_INTERNAL; int mono_thread_kill (MonoInternalThread *thread, int signal) MONO_INTERNAL; -guint32 -mono_thread_get_tls_key (void) MONO_INTERNAL; +MonoNativeTlsKey +mono_thread_get_native_tls_key (void) MONO_INTERNAL; gint32 mono_thread_get_tls_offset (void) MONO_INTERNAL; diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index 117433cef42..1da846619d5 100644 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -43,6 +43,7 @@ #include #include #include +#include #include @@ -151,7 +152,7 @@ static MonoGHashTable *threads_starting_up = NULL; static MonoGHashTable *thread_start_args = NULL; /* The TLS key that holds the MonoObject assigned to each thread */ -static guint32 current_object_key = -1; +static MonoNativeTlsKey current_object_key; #ifdef HAVE_KW_THREAD /* we need to use both the Tls* functions and __thread because @@ -160,12 +161,12 @@ static guint32 current_object_key = -1; static __thread MonoInternalThread * tls_current_object MONO_TLS_FAST; #define SET_CURRENT_OBJECT(x) do { \ tls_current_object = x; \ - TlsSetValue (current_object_key, x); \ + mono_native_tls_set_value (current_object_key, x); \ } while (FALSE) #define GET_CURRENT_OBJECT() tls_current_object #else -#define SET_CURRENT_OBJECT(x) TlsSetValue (current_object_key, x) -#define GET_CURRENT_OBJECT() (MonoThread*) TlsGetValue (current_object_key) +#define SET_CURRENT_OBJECT(x) mono_native_tls_set_value (current_object_key, x) +#define GET_CURRENT_OBJECT() (MonoThread*) mono_native_tls_get_value (current_object_key) #endif /* function called at thread start */ @@ -237,8 +238,8 @@ get_next_managed_thread_id (void) return InterlockedIncrement (&managed_thread_id_counter); } -guint32 -mono_thread_get_tls_key (void) +MonoNativeTlsKey +mono_thread_get_native_tls_key (void) { return current_object_key; } @@ -2649,7 +2650,7 @@ void mono_thread_init (MonoThreadStartCB start_cb, mono_init_static_data_info (&thread_static_info); mono_init_static_data_info (&context_static_info); - current_object_key=TlsAlloc(); + mono_native_tls_alloc (¤t_object_key, NULL); THREAD_DEBUG (g_message ("%s: Allocated current_object_key %d", __func__, current_object_key)); mono_thread_start_cb = start_cb; @@ -2699,7 +2700,7 @@ void mono_thread_cleanup (void) g_array_free (delayed_free_table, TRUE); delayed_free_table = NULL; - TlsFree (current_object_key); + mono_native_tls_free (current_object_key); } void diff --git a/mono/mini/mini-mips.c b/mono/mini/mini-mips.c index 932f2ec621c..2c544c45a7d 100644 --- a/mono/mini/mini-mips.c +++ b/mono/mini/mini-mips.c @@ -5468,15 +5468,10 @@ setup_tls_access (void) } } if (monothread_key == -1) { - ptk = mono_thread_get_tls_key (); + ptk = mono_thread_get_native_tls_key (); if (ptk < 1024) { - ptk = mono_pthread_key_for_tls (ptk); - if (ptk < 1024) { - monothread_key = ptk; - /*g_print ("thread inited: %d\n", ptk);*/ - } - } else { - /*g_print ("thread not inited yet %d\n", ptk);*/ + monothread_key = ptk; + /*g_print ("thread inited: %d\n", ptk);*/ } } } -- 2.11.4.GIT