[io-layer] Remove GetCurrentThreadId
authorLudovic Henry <ludovic.henry@xamarin.com>
Thu, 9 Jul 2015 19:18:07 +0000 (16:18 -0300)
committerRodrigo Kumpera <kumpera@gmail.com>
Thu, 15 Oct 2015 20:45:25 +0000 (16:45 -0400)
15 files changed:
mono/io-layer/threads.h
mono/io-layer/wapi-remap.h
mono/io-layer/wthreads.c
mono/metadata/appdomain.c
mono/metadata/lock-tracer.c
mono/metadata/object.c
mono/metadata/threadpool-ms.c
mono/metadata/threads.c
mono/mini/debugger-agent.c
mono/mini/mini-exceptions.c
mono/mini/mini-gc.c
mono/mini/tasklets.c
mono/mini/tasklets.h
mono/mini/trace.c
mono/utils/mono-threads.h

index a756a40fb64a7f42dd96e4b70bcda5252afd34eb..19453cb02c1692ecd2ad50090cc5f255548297f8 100644 (file)
@@ -26,7 +26,6 @@ G_BEGIN_DECLS
 
 typedef guint32 (*WapiThreadStart)(gpointer);
 
-extern gsize GetCurrentThreadId(void); /* NB return is 32bit in MS API */
 extern void Sleep(guint32 ms);
 extern guint32 SleepEx(guint32 ms, gboolean alertable);
 
index 123755888b590792818522f1d80016c2525a74e9..0523fead9a5c65ffbfa7c60b87cb2e322f047b02 100644 (file)
@@ -89,7 +89,6 @@
 #define WSARecv wapi_WSARecv 
 #define WSASend wapi_WSASend 
 #define GetSystemInfo wapi_GetSystemInfo
-#define GetCurrentThreadId wapi_GetCurrentThreadId
 #define Sleep wapi_Sleep
 #define SleepEx wapi_SleepEx
 #define QueryPerformanceCounter wapi_QueryPerformanceCounter
index 781e3318f276ec37fd24cc39e700f13c10c746ee..bad4a15409a3761f5e509969c7b8def7d5602610 100644 (file)
@@ -199,26 +199,6 @@ wapi_get_current_thread_handle (void)
        return get_current_thread_handle ();
 }
 
-/**
- * GetCurrentThreadId:
- *
- * Looks up the thread ID of the current thread.  This ID can be
- * passed to OpenThread() to create a new handle on this thread.
- *
- * Return value: the thread ID.  NB this is defined as DWORD (ie 32
- * bit) in the MS API, but we need to cope with 64 bit IDs for s390x
- * and amd64.  This doesn't really break the API, it just embraces and
- * extends it on 64bit platforms :)
- */
-gsize
-GetCurrentThreadId (void)
-{
-       MonoNativeThreadId id;
-
-       id = mono_native_thread_id_get ();
-       return MONO_NATIVE_THREAD_ID_TO_UINT (id);
-}
-
 static mono_lazy_init_t sleepex_init = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED;
 static mono_mutex_t sleepex_mutex;
 static mono_cond_t sleepex_cond;
index b015e748b0a9310c6499ad7177071d1edf20f99e..9bbbc1ebc588b3141f9a64560af4e8c6b08f30eb 100644 (file)
@@ -2405,7 +2405,7 @@ mono_domain_try_unload (MonoDomain *domain, MonoObject **exc)
        MonoDomain *caller_domain = mono_domain_get ();
        char *name;
 
-       /* printf ("UNLOAD STARTING FOR %s (%p) IN THREAD 0x%x.\n", domain->friendly_name, domain, GetCurrentThreadId ()); */
+       /* printf ("UNLOAD STARTING FOR %s (%p) IN THREAD 0x%x.\n", domain->friendly_name, domain, mono_native_thread_id_get ()); */
 
        /* Atomically change our state to UNLOADING */
        prev_state = InterlockedCompareExchange ((gint32*)&domain->state,
index e0e6ac96a61053d69735feb81d1cbb5e378e5041..ab39f393b58a42346754d3fb1e90b8d759c7e240 100644 (file)
@@ -122,7 +122,7 @@ add_record (RecordType record_kind, RuntimeLocks kind, gpointer lock)
                frames [i] = (gpointer)((size_t)frames[i] - base_address);
 
        /*We only dump 5 frames, which should be more than enough to most analysis.*/
-       msg = g_strdup_printf ("%x,%d,%d,%p,%p,%p,%p,%p,%p\n", (guint32)GetCurrentThreadId (), record_kind, kind, lock, frames [1], frames [2], frames [3], frames [4], frames [5]);
+       msg = g_strdup_printf ("%x,%d,%d,%p,%p,%p,%p,%p,%p\n", (guint32)mono_native_thread_id_get (), record_kind, kind, lock, frames [1], frames [2], frames [3], frames [4], frames [5]);
        fwrite (msg, strlen (msg), 1, trace_file);
        fflush (trace_file);
        g_free (msg);
index 3838d06e3b641ca6cb05dce6d4d8b695348b1244..c3f24008d657afe73f286b1f76629d11d3b005dd 100644 (file)
@@ -43,6 +43,7 @@
 #include <mono/utils/mono-error-internals.h>
 #include <mono/utils/mono-memory-model.h>
 #include <mono/utils/checked-build.h>
+#include <mono/utils/mono-threads.h>
 #include "cominterop.h"
 
 static void
@@ -104,7 +105,7 @@ Note it doesn't say anything about domains - only threads.
 
 typedef struct
 {
-       guint32 initializing_tid;
+       MonoNativeThreadId initializing_tid;
        guint32 waiting_count;
        gboolean done;
        mono_mutex_t initialization_section;
@@ -286,7 +287,7 @@ mono_runtime_class_init_full (MonoVTable *vtable, gboolean raise_exception)
        gchar *full_name;
        MonoDomain *domain = vtable->domain;
        TypeInitializationLock *lock;
-       guint32 tid;
+       MonoNativeThreadId tid;
        int do_initialization = 0;
        MonoDomain *last_domain = NULL;
 
@@ -325,7 +326,7 @@ mono_runtime_class_init_full (MonoVTable *vtable, gboolean raise_exception)
                return NULL;
        }
 
-       tid = GetCurrentThreadId ();
+       tid = mono_native_thread_id_get ();
 
        mono_type_initialization_lock ();
        /* double check... */
@@ -369,14 +370,14 @@ mono_runtime_class_init_full (MonoVTable *vtable, gboolean raise_exception)
                gpointer blocked;
                TypeInitializationLock *pending_lock;
 
-               if (lock->initializing_tid == tid || lock->done) {
+               if (mono_native_thread_id_equals (lock->initializing_tid, tid) || lock->done) {
                        mono_type_initialization_unlock ();
                        return NULL;
                }
                /* see if the thread doing the initialization is already blocked on this thread */
-               blocked = GUINT_TO_POINTER (lock->initializing_tid);
+               blocked = GUINT_TO_POINTER (MONO_NATIVE_THREAD_ID_TO_UINT (lock->initializing_tid));
                while ((pending_lock = (TypeInitializationLock*) g_hash_table_lookup (blocked_thread_hash, blocked))) {
-                       if (pending_lock->initializing_tid == tid) {
+                       if (mono_native_thread_id_equals (pending_lock->initializing_tid, tid)) {
                                if (!pending_lock->done) {
                                        mono_type_initialization_unlock ();
                                        return NULL;
@@ -387,7 +388,7 @@ mono_runtime_class_init_full (MonoVTable *vtable, gboolean raise_exception)
                                        break;
                                }
                        }
-                       blocked = GUINT_TO_POINTER (pending_lock->initializing_tid);
+                       blocked = GUINT_TO_POINTER (MONO_NATIVE_THREAD_ID_TO_UINT (pending_lock->initializing_tid));
                }
                ++lock->waiting_count;
                /* record the fact that we are waiting on the initializing thread */
@@ -435,7 +436,7 @@ mono_runtime_class_init_full (MonoVTable *vtable, gboolean raise_exception)
        }
 
        mono_type_initialization_lock ();
-       if (lock->initializing_tid != tid)
+       if (!mono_native_thread_id_equals (lock->initializing_tid, tid))
                g_hash_table_remove (blocked_thread_hash, GUINT_TO_POINTER (tid));
        --lock->waiting_count;
        if (lock->waiting_count == 0) {
@@ -465,7 +466,7 @@ gboolean release_type_locks (gpointer key, gpointer value, gpointer user)
        MonoVTable *vtable = (MonoVTable*)key;
 
        TypeInitializationLock *lock = (TypeInitializationLock*) value;
-       if (lock->initializing_tid == GPOINTER_TO_UINT (user) && !lock->done) {
+       if (mono_native_thread_id_equals (lock->initializing_tid, MONO_UINT_TO_NATIVE_THREAD_ID (GPOINTER_TO_UINT (user))) && !lock->done) {
                lock->done = TRUE;
                /* 
                 * Have to set this since it cannot be set by the normal code in 
@@ -490,7 +491,7 @@ mono_release_type_locks (MonoInternalThread *thread)
        MONO_REQ_GC_UNSAFE_MODE;
 
        mono_type_initialization_lock ();
-       g_hash_table_foreach_remove (type_initialization_hash, release_type_locks, (gpointer)(gsize)(thread->tid));
+       g_hash_table_foreach_remove (type_initialization_hash, release_type_locks, GUINT_TO_POINTER (thread->tid));
        mono_type_initialization_unlock ();
 }
 
index 05c88bea0d4ae55b13e2a5979db1f2387e7fba28..a41b30e9f25f392e59d0ba1013d64590ad031f54 100644 (file)
@@ -497,7 +497,7 @@ worker_park (void)
 {
        gboolean timeout = FALSE;
 
-       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] current worker parking", GetCurrentThreadId ());
+       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] current worker parking", mono_native_thread_id_get ());
 
        mono_gc_set_skip_thread (TRUE);
 
@@ -540,7 +540,7 @@ done:
 
        mono_gc_set_skip_thread (FALSE);
 
-       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] current worker unparking, timeout? %s", GetCurrentThreadId (), timeout ? "yes" : "no");
+       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] current worker unparking, timeout? %s", mono_native_thread_id_get (), timeout ? "yes" : "no");
 
        return timeout;
 }
@@ -550,7 +550,7 @@ worker_try_unpark (void)
 {
        gboolean res = FALSE;
 
-       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] try unpark worker", GetCurrentThreadId ());
+       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] try unpark worker", mono_native_thread_id_get ());
 
        MONO_PREPARE_BLOCKING;
 
@@ -563,7 +563,7 @@ worker_try_unpark (void)
 
        MONO_FINISH_BLOCKING;
 
-       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] try unpark worker, success? %s", GetCurrentThreadId (), res ? "yes" : "no");
+       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] try unpark worker, success? %s", mono_native_thread_id_get (), res ? "yes" : "no");
 
        return res;
 }
@@ -585,7 +585,7 @@ worker_thread (gpointer data)
        ThreadPoolCounter counter;
        gboolean retire = FALSE;
 
-       mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_THREADPOOL, "[%p] worker starting", GetCurrentThreadId ());
+       mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_THREADPOOL, "[%p] worker starting", mono_native_thread_id_get ());
 
        g_assert (threadpool);
 
@@ -643,7 +643,7 @@ worker_thread (gpointer data)
                g_assert (tpdomain->outstanding_request >= 0);
 
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] worker running in domain %p",
-                       GetCurrentThreadId (), tpdomain->domain, tpdomain->outstanding_request);
+                       mono_native_thread_id_get (), tpdomain->domain, tpdomain->outstanding_request);
 
                g_assert (tpdomain->domain);
                g_assert (tpdomain->domain->threadpool_jobs >= 0);
@@ -698,7 +698,7 @@ worker_thread (gpointer data)
                counter._.active --;
        });
 
-       mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_THREADPOOL, "[%p] worker finishing", GetCurrentThreadId ());
+       mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_THREADPOOL, "[%p] worker finishing", mono_native_thread_id_get ());
 }
 
 static gboolean
@@ -707,7 +707,7 @@ worker_try_create (void)
        ThreadPoolCounter counter;
        MonoInternalThread *thread;
 
-       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] try create worker", GetCurrentThreadId ());
+       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] try create worker", mono_native_thread_id_get ());
 
        COUNTER_ATOMIC (counter, {
                if (counter._.working >= counter._.max_working)
@@ -718,11 +718,11 @@ worker_try_create (void)
 
        if ((thread = mono_thread_create_internal (mono_get_root_domain (), worker_thread, NULL, TRUE, 0)) != NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] try create worker, created %p",
-                       GetCurrentThreadId (), thread->tid);
+                       mono_native_thread_id_get (), thread->tid);
                return TRUE;
        }
 
-       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] try create worker, failed", GetCurrentThreadId ());
+       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] try create worker, failed", mono_native_thread_id_get ());
 
        COUNTER_ATOMIC (counter, {
                counter._.working --;
@@ -758,7 +758,7 @@ worker_request (MonoDomain *domain)
        tpdomain->outstanding_request ++;
 
        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] request worker, domain = %p, outstanding_request = %d",
-               GetCurrentThreadId (), tpdomain->domain, tpdomain->outstanding_request);
+               mono_native_thread_id_get (), tpdomain->domain, tpdomain->outstanding_request);
 
        mono_mutex_unlock (&threadpool->domains_lock);
 
@@ -768,16 +768,16 @@ worker_request (MonoDomain *domain)
        monitor_ensure_running ();
 
        if (worker_try_unpark ()) {
-               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] request worker, unparked", GetCurrentThreadId ());
+               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] request worker, unparked", mono_native_thread_id_get ());
                return TRUE;
        }
 
        if (worker_try_create ()) {
-               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] request worker, created", GetCurrentThreadId ());
+               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] request worker, created", mono_native_thread_id_get ());
                return TRUE;
        }
 
-       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] request worker, failed", GetCurrentThreadId ());
+       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] request worker, failed", mono_native_thread_id_get ());
        return FALSE;
 }
 
@@ -847,7 +847,7 @@ monitor_thread (void)
 
        mono_cpu_usage (threadpool->cpu_usage_state);
 
-       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] monitor thread, started", GetCurrentThreadId ());
+       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] monitor thread, started", mono_native_thread_id_get ());
 
        do {
                MonoInternalThread *thread;
@@ -910,19 +910,19 @@ monitor_thread (void)
                                        break;
 
                                if (worker_try_unpark ()) {
-                                       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] monitor thread, unparked", GetCurrentThreadId ());
+                                       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] monitor thread, unparked", mono_native_thread_id_get ());
                                        break;
                                }
 
                                if (worker_try_create ()) {
-                                       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] monitor thread, created", GetCurrentThreadId ());
+                                       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] monitor thread, created", mono_native_thread_id_get ());
                                        break;
                                }
                        }
                }
        } while (monitor_should_keep_running ());
 
-       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] monitor thread, finished", GetCurrentThreadId ());
+       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] monitor thread, finished", mono_native_thread_id_get ());
 }
 
 static void
@@ -958,7 +958,7 @@ hill_climbing_change_thread_count (gint16 new_thread_count, ThreadPoolHeuristicS
 
        hc = &threadpool->heuristic_hill_climbing;
 
-       mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_THREADPOOL, "[%p] hill climbing, change max number of threads %d", GetCurrentThreadId (), new_thread_count);
+       mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_THREADPOOL, "[%p] hill climbing, change max number of threads %d", mono_native_thread_id_get (), new_thread_count);
 
        hc->last_thread_count = new_thread_count;
        hc->current_sample_interval = rand_next (&hc->random_interval_generator, hc->sample_interval_low, hc->sample_interval_high);
index 1c8dc155535f3e9887cfa2140a9a8978a18b9b07..e285f8e69b72436f52b0a5a1787b3b603b4938ca 100644 (file)
@@ -632,7 +632,7 @@ static guint32 WINAPI start_wrapper_internal(void *data)
        MonoObject *start_delegate = start_info->delegate;
        MonoDomain *domain = start_info->obj->obj.vtable->domain;
 
-       THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Start wrapper", __func__, GetCurrentThreadId ()));
+       THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Start wrapper", __func__, mono_native_thread_id_get ()));
 
        /* We can be sure start_info->obj->tid and
         * start_info->obj->handle have been set, because the thread
@@ -676,9 +676,9 @@ static guint32 WINAPI start_wrapper_internal(void *data)
        mono_thread_new_init (tid, &tid, start_func);
        internal->stack_ptr = &tid;
 
-       LIBGC_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT",%d) Setting thread stack to %p", __func__, GetCurrentThreadId (), getpid (), thread->stack_ptr));
+       LIBGC_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT",%d) Setting thread stack to %p", __func__, mono_native_thread_id_get (), getpid (), thread->stack_ptr));
 
-       THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Setting current_object_key to %p", __func__, GetCurrentThreadId (), internal));
+       THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Setting current_object_key to %p", __func__, mono_native_thread_id_get (), internal));
 
        /* On 2.0 profile (and higher), set explicitly since state might have been
           Unknown */
@@ -727,7 +727,7 @@ static guint32 WINAPI start_wrapper_internal(void *data)
         * call thread_cleanup() on this thread's behalf.
         */
 
-       THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Start wrapper terminating", __func__, GetCurrentThreadId ()));
+       THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Start wrapper terminating", __func__, mono_native_thread_id_get ()));
 
        /* Do any cleanup needed for apartment state. This
         * cannot be done in thread_cleanup since thread_cleanup could be 
@@ -840,7 +840,7 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, StartInfo *star
        if (threadpool_thread)
                mono_thread_set_state (internal, ThreadState_Background);
 
-       THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Launching thread %p (%"G_GSIZE_FORMAT")", __func__, GetCurrentThreadId (), internal, (gsize)internal->tid));
+       THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Launching thread %p (%"G_GSIZE_FORMAT")", __func__, mono_native_thread_id_get (), internal, (gsize)internal->tid));
 
        /* Only store the handle when the thread is about to be
         * launched, to avoid the main thread deadlocking while trying
@@ -860,7 +860,7 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, StartInfo *star
                 * to look up the data believing the thread has
                 * started
                 */
-               THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") waiting for thread %p (%"G_GSIZE_FORMAT") to start", __func__, GetCurrentThreadId (), internal, (gsize)internal->tid));
+               THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") waiting for thread %p (%"G_GSIZE_FORMAT") to start", __func__, mono_native_thread_id_get (), internal, (gsize)internal->tid));
 
                MONO_PREPARE_BLOCKING;
                WaitForSingleObjectEx (internal->start_notify, INFINITE, FALSE);
@@ -870,7 +870,7 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, StartInfo *star
                internal->start_notify = NULL;
        }
 
-       THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Done launching thread %p (%"G_GSIZE_FORMAT")", __func__, GetCurrentThreadId (), internal, (gsize)internal->tid));
+       THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Done launching thread %p (%"G_GSIZE_FORMAT")", __func__, mono_native_thread_id_get (), internal, (gsize)internal->tid));
 
        return TRUE;
 }
@@ -944,7 +944,7 @@ mono_thread_attach_full (MonoDomain *domain, gboolean force_attach)
        MonoInternalThread *thread;
        MonoThread *current_thread;
        HANDLE thread_handle;
-       gsize tid;
+       MonoNativeThreadId tid;
 
        if ((thread = mono_thread_internal_current ())) {
                if (domain != mono_domain_get ())
@@ -954,7 +954,7 @@ mono_thread_attach_full (MonoDomain *domain, gboolean force_attach)
        }
 
        if (!mono_gc_register_thread (&domain)) {
-               g_error ("Thread %"G_GSIZE_FORMAT" calling into managed code is not registered with the GC. On UNIX, this can be fixed by #include-ing <gc.h> before <pthread.h> in the file containing the thread creation code.", GetCurrentThreadId ());
+               g_error ("Thread %"G_GSIZE_FORMAT" calling into managed code is not registered with the GC. On UNIX, this can be fixed by #include-ing <gc.h> before <pthread.h> in the file containing the thread creation code.", mono_native_thread_id_get ());
        }
 
        thread = create_internal_thread ();
@@ -962,10 +962,10 @@ mono_thread_attach_full (MonoDomain *domain, gboolean force_attach)
        thread_handle = mono_thread_info_open_handle ();
        g_assert (thread_handle);
 
-       tid=GetCurrentThreadId ();
+       tid=mono_native_thread_id_get ();
 
        thread->handle = thread_handle;
-       thread->tid = tid;
+       thread->tid = MONO_NATIVE_THREAD_ID_TO_UINT (tid);
        thread->stack_ptr = &tid;
 
        THREAD_DEBUG (g_message ("%s: Attached thread ID %"G_GSIZE_FORMAT" (handle %p)", __func__, tid, thread_handle));
@@ -983,7 +983,7 @@ mono_thread_attach_full (MonoDomain *domain, gboolean force_attach)
                        Sleep (10000);
        }
 
-       THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Setting current_object_key to %p", __func__, GetCurrentThreadId (), thread));
+       THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Setting current_object_key to %p", __func__, mono_native_thread_id_get (), thread));
 
        SET_CURRENT_OBJECT (thread);
        mono_domain_set (domain, TRUE);
@@ -1002,13 +1002,13 @@ mono_thread_attach_full (MonoDomain *domain, gboolean force_attach)
                mono_thread_info_get_stack_bounds (&staddr, &stsize);
 
                if (staddr == NULL)
-                       mono_thread_attach_cb (tid, &tid);
+                       mono_thread_attach_cb (MONO_NATIVE_THREAD_ID_TO_UINT (tid), &tid);
                else
-                       mono_thread_attach_cb (tid, staddr + stsize);
+                       mono_thread_attach_cb (MONO_NATIVE_THREAD_ID_TO_UINT (tid), staddr + stsize);
        }
 
        // FIXME: Need a separate callback
-       mono_profiler_thread_start (tid);
+       mono_profiler_thread_start (MONO_NATIVE_THREAD_ID_TO_UINT (tid));
 
        return current_thread;
 }
@@ -1487,10 +1487,10 @@ gboolean ves_icall_System_Threading_WaitHandle_WaitAll_internal(MonoArray *mono_
        g_free(handles);
 
        if(ret==WAIT_FAILED) {
-               THREAD_WAIT_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Wait failed", __func__, GetCurrentThreadId ()));
+               THREAD_WAIT_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Wait failed", __func__, mono_native_thread_id_get ()));
                return(FALSE);
        } else if(ret==WAIT_TIMEOUT) {
-               THREAD_WAIT_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Wait timed out", __func__, GetCurrentThreadId ()));
+               THREAD_WAIT_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Wait timed out", __func__, mono_native_thread_id_get ()));
                return(FALSE);
        }
        
@@ -1529,7 +1529,7 @@ gint32 ves_icall_System_Threading_WaitHandle_WaitAny_internal(MonoArray *mono_ha
 
        mono_thread_clr_state (thread, ThreadState_WaitSleepJoin);
 
-       THREAD_WAIT_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") returning %d", __func__, GetCurrentThreadId (), ret));
+       THREAD_WAIT_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") returning %d", __func__, mono_native_thread_id_get (), ret));
 
        /*
         * These need to be here.  See MSDN dos on WaitForMultipleObjects.
@@ -1551,7 +1551,7 @@ gboolean ves_icall_System_Threading_WaitHandle_WaitOne_internal(MonoObject *this
        guint32 ret;
        MonoInternalThread *thread = mono_thread_internal_current ();
 
-       THREAD_WAIT_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") waiting for %p, %d ms", __func__, GetCurrentThreadId (), handle, ms));
+       THREAD_WAIT_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") waiting for %p, %d ms", __func__, mono_native_thread_id_get (), handle, ms));
        
        if(ms== -1) {
                ms=INFINITE;
@@ -1566,10 +1566,10 @@ gboolean ves_icall_System_Threading_WaitHandle_WaitOne_internal(MonoObject *this
        mono_thread_clr_state (thread, ThreadState_WaitSleepJoin);
        
        if(ret==WAIT_FAILED) {
-               THREAD_WAIT_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Wait failed", __func__, GetCurrentThreadId ()));
+               THREAD_WAIT_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Wait failed", __func__, mono_native_thread_id_get ()));
                return(FALSE);
        } else if(ret==WAIT_TIMEOUT) {
-               THREAD_WAIT_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Wait timed out", __func__, GetCurrentThreadId ()));
+               THREAD_WAIT_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Wait timed out", __func__, mono_native_thread_id_get ()));
                return(FALSE);
        }
        
@@ -2076,7 +2076,7 @@ ves_icall_System_Threading_Thread_Abort (MonoInternalThread *thread, MonoObject
 
        UNLOCK_THREAD (thread);
 
-       THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Abort requested for %p (%"G_GSIZE_FORMAT")", __func__, GetCurrentThreadId (), thread, (gsize)thread->tid));
+       THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Abort requested for %p (%"G_GSIZE_FORMAT")", __func__, mono_native_thread_id_get (), thread, (gsize)thread->tid));
 
        /* During shutdown, we can't wait for other threads */
        if (!shutting_down)
@@ -2848,7 +2848,7 @@ static gboolean
 remove_and_abort_threads (gpointer key, gpointer value, gpointer user)
 {
        struct wait_data *wait=(struct wait_data *)user;
-       gsize self = GetCurrentThreadId ();
+       MonoNativeThreadId self = mono_native_thread_id_get ();
        MonoInternalThread *thread = value;
        HANDLE handle;
 
@@ -2856,9 +2856,10 @@ remove_and_abort_threads (gpointer key, gpointer value, gpointer user)
                return FALSE;
 
        /* The finalizer thread is not a background thread */
-       if (thread->tid != self && (thread->state & ThreadState_Background) != 0 &&
-               !(thread->flags & MONO_THREAD_FLAG_DONT_MANAGE)) {
-       
+       if (!mono_native_thread_id_equals (thread_get_tid (thread), self)
+            && (thread->state & ThreadState_Background) != 0
+            && (thread->flags & MONO_THREAD_FLAG_DONT_MANAGE) == 0
+       ) {
                handle = mono_threads_open_thread_handle (thread->handle, thread_get_tid (thread));
                if (handle == NULL)
                        return FALSE;
@@ -2873,7 +2874,8 @@ remove_and_abort_threads (gpointer key, gpointer value, gpointer user)
                return TRUE;
        }
 
-       return (thread->tid != self && !mono_gc_is_finalizer_internal_thread (thread)); 
+       return !mono_native_thread_id_equals (thread_get_tid (thread), self)
+               && !mono_gc_is_finalizer_internal_thread (thread);
 }
 
 /** 
@@ -3039,7 +3041,7 @@ void mono_thread_suspend_all_other_threads (void)
        struct wait_data wait_data;
        struct wait_data *wait = &wait_data;
        int i;
-       gsize self = GetCurrentThreadId ();
+       MonoNativeThreadId self = mono_native_thread_id_get ();
        guint32 eventidx = 0;
        gboolean starting, finished;
 
@@ -3081,7 +3083,10 @@ void mono_thread_suspend_all_other_threads (void)
                for (i = 0; i < wait->num; ++i) {
                        MonoInternalThread *thread = wait->threads [i];
 
-                       if ((thread->tid == self) || mono_gc_is_finalizer_internal_thread (thread) || (thread->flags & MONO_THREAD_FLAG_DONT_MANAGE)) {
+                       if (mono_native_thread_id_equals (thread_get_tid (thread), self)
+                            || mono_gc_is_finalizer_internal_thread (thread)
+                            || (thread->flags & MONO_THREAD_FLAG_DONT_MANAGE)
+                       ) {
                                //CloseHandle (wait->handles [i]);
                                wait->threads [i] = NULL; /* ignore this thread in next loop */
                                continue;
index a305cdb6e743c0cf5764d07bd4fb62ba1155f7c2..990ee09e107f394773e825d8f1711094b5a871f3 100644 (file)
@@ -662,7 +662,7 @@ static MonoGHashTable *tid_to_thread;
 /* Protected by the loader lock */
 static MonoGHashTable *tid_to_thread_obj;
 
-static gsize debugger_thread_id;
+static MonoNativeThreadId debugger_thread_id;
 
 static HANDLE debugger_thread_handle;
 
@@ -811,7 +811,7 @@ register_socket_transport (void);
 static inline gboolean
 is_debugger_thread (void)
 {
-       return GetCurrentThreadId () == debugger_thread_id;
+       return mono_native_thread_id_equals (mono_native_thread_id_get (), debugger_thread_id);
 }
 
 static int
@@ -1602,7 +1602,7 @@ stop_debugger_thread (void)
         * If we continue with the shutdown without waiting for it, then the client might
         * not receive an answer to its last command like a resume.
         */
-       if (GetCurrentThreadId () != debugger_thread_id) {
+       if (!is_debugger_thread ()) {
                do {
                        MONO_TRY_BLOCKING;
                        mono_mutex_lock (&debugger_thread_exited_mutex);
@@ -2392,10 +2392,10 @@ buffer_add_typeid (Buffer *buf, MonoDomain *domain, MonoClass *klass)
                char *s;
 
                s = mono_type_full_name (&klass->byval_arg);
-               if (GetCurrentThreadId () == debugger_thread_id)
+               if (is_debugger_thread ())
                        DEBUG_PRINTF (2, "[dbg]   send class [%s]\n", s);
                else
-                       DEBUG_PRINTF (2, "[%p]   send class [%s]\n", (gpointer)GetCurrentThreadId (), s);
+                       DEBUG_PRINTF (2, "[%p]   send class [%s]\n", (gpointer)mono_native_thread_id_get (), s);
                g_free (s);
        }
 }
@@ -2668,12 +2668,12 @@ notify_thread (gpointer key, gpointer value, gpointer user_data)
 {
        MonoInternalThread *thread = key;
        DebuggerTlsData *tls = value;
-       gsize tid = thread->tid;
+       MonoNativeThreadId tid = MONO_UINT_TO_NATIVE_THREAD_ID (thread->tid);
 
-       if (GetCurrentThreadId () == tid || tls->terminated)
+       if (mono_native_thread_id_equals (mono_native_thread_id_get (), tid) || tls->terminated)
                return;
 
-       DEBUG_PRINTF (1, "[%p] Interrupting %p...\n", (gpointer)GetCurrentThreadId (), (gpointer)tid);
+       DEBUG_PRINTF (1, "[%p] Interrupting %p...\n", (gpointer)mono_native_thread_id_get (), (gpointer)tid);
 
        /* This is _not_ equivalent to ves_icall_System_Threading_Thread_Abort () */
        InterruptData interrupt_data = { 0 };
@@ -2681,7 +2681,7 @@ notify_thread (gpointer key, gpointer value, gpointer user_data)
 
        mono_thread_info_safe_suspend_and_run ((MonoNativeThreadId)(gpointer)(gsize)thread->tid, FALSE, debugger_interrupt_critical, &interrupt_data);
        if (!interrupt_data.valid_info) {
-               DEBUG_PRINTF (1, "[%p] mono_thread_info_suspend_sync () failed for %p...\n", (gpointer)GetCurrentThreadId (), (gpointer)tid);
+               DEBUG_PRINTF (1, "[%p] mono_thread_info_suspend_sync () failed for %p...\n", (gpointer)mono_native_thread_id_get (), (gpointer)tid);
                /* 
                 * Attached thread which died without detaching.
                 */
@@ -2705,14 +2705,14 @@ process_suspend (DebuggerTlsData *tls, MonoContext *ctx)
                return;
        }
 
-       if (debugger_thread_id == GetCurrentThreadId ())
+       if (is_debugger_thread ())
                return;
 
        /* Prevent races with mono_debugger_agent_thread_interrupt () */
        if (suspend_count - tls->resume_count > 0)
                tls->suspending = TRUE;
 
-       DEBUG_PRINTF (1, "[%p] Received single step event for suspending.\n", (gpointer)GetCurrentThreadId ());
+       DEBUG_PRINTF (1, "[%p] Received single step event for suspending.\n", (gpointer)mono_native_thread_id_get ());
 
        if (suspend_count - tls->resume_count == 0) {
                /* 
@@ -2720,7 +2720,7 @@ process_suspend (DebuggerTlsData *tls, MonoContext *ctx)
                 * suspending is still active.
                 * FIXME: This slows down single threaded invokes.
                 */
-               DEBUG_PRINTF (1, "[%p] Ignored during single threaded invoke.\n", (gpointer)GetCurrentThreadId ());
+               DEBUG_PRINTF (1, "[%p] Ignored during single threaded invoke.\n", (gpointer)mono_native_thread_id_get ());
                return;
        }
 
@@ -2753,7 +2753,7 @@ suspend_vm (void)
 
        suspend_count ++;
 
-       DEBUG_PRINTF (1, "[%p] Suspending vm...\n", (gpointer)GetCurrentThreadId ());
+       DEBUG_PRINTF (1, "[%p] Suspending vm...\n", (gpointer)mono_native_thread_id_get ());
 
        if (suspend_count == 1) {
                // FIXME: Is it safe to call this inside the lock ?
@@ -2783,7 +2783,7 @@ resume_vm (void)
 {
        int err;
 
-       g_assert (debugger_thread_id == GetCurrentThreadId ());
+       g_assert (is_debugger_thread ());
 
        mono_loader_lock ();
 
@@ -2794,7 +2794,7 @@ resume_vm (void)
        g_assert (suspend_count > 0);
        suspend_count --;
 
-       DEBUG_PRINTF (1, "[%p] Resuming vm, suspend count=%d...\n", (gpointer)GetCurrentThreadId (), suspend_count);
+       DEBUG_PRINTF (1, "[%p] Resuming vm, suspend count=%d...\n", (gpointer)mono_native_thread_id_get (), suspend_count);
 
        if (suspend_count == 0) {
                // FIXME: Is it safe to call this inside the lock ?
@@ -2826,7 +2826,7 @@ resume_thread (MonoInternalThread *thread)
        int err;
        DebuggerTlsData *tls;
 
-       g_assert (debugger_thread_id == GetCurrentThreadId ());
+       g_assert (is_debugger_thread ());
 
        mono_loader_lock ();
 
@@ -2897,7 +2897,7 @@ suspend_current (void)
        DebuggerTlsData *tls;
        int err;
 
-       g_assert (debugger_thread_id != GetCurrentThreadId ());
+       g_assert (!is_debugger_thread ());
 
        if (mono_loader_lock_is_owned_by_self ()) {
                /*
@@ -2922,7 +2922,7 @@ suspend_current (void)
                MONO_SEM_POST (&suspend_sem);
        }
 
-       DEBUG_PRINTF (1, "[%p] Suspended.\n", (gpointer)GetCurrentThreadId ());
+       DEBUG_PRINTF (1, "[%p] Suspended.\n", (gpointer)mono_native_thread_id_get ());
 
        MONO_TRY_BLOCKING;
        while (suspend_count - tls->resume_count > 0) {
@@ -2938,7 +2938,7 @@ suspend_current (void)
 
        mono_mutex_unlock (&suspend_mutex);
 
-       DEBUG_PRINTF (1, "[%p] Resumed.\n", (gpointer)GetCurrentThreadId ());
+       DEBUG_PRINTF (1, "[%p] Resumed.\n", (gpointer)mono_native_thread_id_get ());
 
        if (tls->pending_invoke) {
                /* Save the original context */
@@ -3253,7 +3253,7 @@ emit_appdomain_load (gpointer key, gpointer value, gpointer user_data)
 static void
 emit_thread_start (gpointer key, gpointer value, gpointer user_data)
 {
-       if (GPOINTER_TO_INT (key) != debugger_thread_id)
+       if (!mono_native_thread_id_equals (MONO_UINT_TO_NATIVE_THREAD_ID (GPOINTER_TO_UINT (key)), debugger_thread_id))
                process_profiler_event (EVENT_KIND_THREAD_START, value);
 }
 
@@ -3610,14 +3610,14 @@ process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx
 
                if (agent_config.defer) {
                        /* Make sure the thread id is always set when doing deferred debugging */
-                       if (debugger_thread_id == GetCurrentThreadId ()) {
+                       if (is_debugger_thread ()) {
                                /* Don't suspend on events from the debugger thread */
                                suspend_policy = SUSPEND_POLICY_NONE;
                                thread = mono_thread_get_main ();
                        }
                        else thread = mono_thread_current ();
                } else {
-                       if (debugger_thread_id == GetCurrentThreadId () && event != EVENT_KIND_VM_DEATH)
+                       if (is_debugger_thread () && event != EVENT_KIND_VM_DEATH)
                                // FIXME: Send these with a NULL thread, don't suspend the current thread
                                return;
                }
@@ -3754,7 +3754,7 @@ process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx
                vm_start_event_sent = TRUE;
        }
 
-       DEBUG_PRINTF (1, "[%p] Sent %d events %s(%d), suspend=%d.\n", (gpointer)GetCurrentThreadId (), nevents, event_to_string (event), ecount, suspend_policy);
+       DEBUG_PRINTF (1, "[%p] Sent %d events %s(%d), suspend=%d.\n", (gpointer)mono_native_thread_id_get (), nevents, event_to_string (event), ecount, suspend_policy);
 
        switch (suspend_policy) {
        case SUSPEND_POLICY_NONE:
@@ -3812,13 +3812,13 @@ thread_startup (MonoProfiler *prof, uintptr_t tid)
        MonoInternalThread *old_thread;
        DebuggerTlsData *tls;
 
-       if (tid == debugger_thread_id)
+       if (mono_native_thread_id_equals (MONO_UINT_TO_NATIVE_THREAD_ID (tid), debugger_thread_id))
                return;
 
-       g_assert (thread->tid == tid);
+       g_assert (mono_native_thread_id_equals (MONO_UINT_TO_NATIVE_THREAD_ID (tid), MONO_UINT_TO_NATIVE_THREAD_ID (thread->tid)));
 
        mono_loader_lock ();
-       old_thread = mono_g_hash_table_lookup (tid_to_thread, (gpointer)tid);
+       old_thread = mono_g_hash_table_lookup (tid_to_thread, GUINT_TO_POINTER (tid));
        mono_loader_unlock ();
        if (old_thread) {
                if (thread == old_thread) {
@@ -3826,18 +3826,18 @@ thread_startup (MonoProfiler *prof, uintptr_t tid)
                         * For some reason, thread_startup () might be called for the same thread
                         * multiple times (attach ?).
                         */
-                       DEBUG_PRINTF (1, "[%p] thread_start () called multiple times for %p, ignored.\n", (gpointer)tid, (gpointer)tid);
+                       DEBUG_PRINTF (1, "[%p] thread_start () called multiple times for %p, ignored.\n", GUINT_TO_POINTER (tid), GUINT_TO_POINTER (tid));
                        return;
                } else {
                        /*
                         * thread_end () might not be called for some threads, and the tid could
                         * get reused.
                         */
-                       DEBUG_PRINTF (1, "[%p] Removing stale data for tid %p.\n", (gpointer)tid, (gpointer)tid);
+                       DEBUG_PRINTF (1, "[%p] Removing stale data for tid %p.\n", GUINT_TO_POINTER (tid), GUINT_TO_POINTER (tid));
                        mono_loader_lock ();
                        mono_g_hash_table_remove (thread_to_tls, old_thread);
-                       mono_g_hash_table_remove (tid_to_thread, (gpointer)tid);
-                       mono_g_hash_table_remove (tid_to_thread_obj, (gpointer)tid);
+                       mono_g_hash_table_remove (tid_to_thread, GUINT_TO_POINTER (tid));
+                       mono_g_hash_table_remove (tid_to_thread_obj, GUINT_TO_POINTER (tid));
                        mono_loader_unlock ();
                }
        }
@@ -3855,7 +3855,7 @@ thread_startup (MonoProfiler *prof, uintptr_t tid)
        mono_loader_lock ();
        mono_g_hash_table_insert (thread_to_tls, thread, tls);
        mono_g_hash_table_insert (tid_to_thread, (gpointer)tid, thread);
-       mono_g_hash_table_insert (tid_to_thread_obj, (gpointer)tid, mono_thread_current ());
+       mono_g_hash_table_insert (tid_to_thread_obj, GUINT_TO_POINTER (tid), mono_thread_current ());
        mono_loader_unlock ();
 
        process_profiler_event (EVENT_KIND_THREAD_START, thread);
@@ -3873,9 +3873,9 @@ thread_end (MonoProfiler *prof, uintptr_t tid)
        DebuggerTlsData *tls = NULL;
 
        mono_loader_lock ();
-       thread = mono_g_hash_table_lookup (tid_to_thread, (gpointer)tid);
+       thread = mono_g_hash_table_lookup (tid_to_thread, GUINT_TO_POINTER (tid));
        if (thread) {
-               mono_g_hash_table_remove (tid_to_thread_obj, (gpointer)tid);
+               mono_g_hash_table_remove (tid_to_thread_obj, GUINT_TO_POINTER (tid));
                tls = mono_g_hash_table_lookup (thread_to_tls, thread);
                if (tls) {
                        /* FIXME: Maybe we need to free this instead, but some code can't handle that */
@@ -3891,7 +3891,9 @@ thread_end (MonoProfiler *prof, uintptr_t tid)
        if (thread) {
                DEBUG_PRINTF (1, "[%p] Thread terminated, obj=%p, tls=%p.\n", (gpointer)tid, thread, tls);
 
-               if (GetCurrentThreadId () == tid && !mono_native_tls_get_value (debugger_tls_id)) {
+               if (mono_native_thread_id_equals (mono_native_thread_id_get (), MONO_UINT_TO_NATIVE_THREAD_ID (tid))
+                    && !mono_native_tls_get_value (debugger_tls_id)
+               ) {
                        /*
                         * This can happen on darwin since we deregister threads using pthread dtors.
                         * process_profiler_event () and the code it calls cannot handle a null TLS value.
@@ -4528,7 +4530,7 @@ ss_update (SingleStepReq *req, MonoJitInfo *ji, SeqPoint *sp, DebuggerTlsData *t
                /*
                 * These seq points are inserted by the JIT after calls, step over needs to skip them.
                 */
-               DEBUG_PRINTF (1, "[%p] Seq point at nonempty stack %x while stepping over, continuing single stepping.\n", (gpointer)GetCurrentThreadId (), sp->il_offset);
+               DEBUG_PRINTF (1, "[%p] Seq point at nonempty stack %x while stepping over, continuing single stepping.\n", (gpointer)mono_native_thread_id_get (), sp->il_offset);
                return FALSE;
        }
 
@@ -4538,7 +4540,7 @@ ss_update (SingleStepReq *req, MonoJitInfo *ji, SeqPoint *sp, DebuggerTlsData *t
                compute_frame_info (tls->thread, tls);
                if (req->nframes && tls->frame_count && tls->frame_count > req->nframes) {
                        /* Hit the breakpoint in a recursive call */
-                       DEBUG_PRINTF (1, "[%p] Breakpoint at lower frame while stepping over, continuing single stepping.\n", (gpointer)GetCurrentThreadId ());
+                       DEBUG_PRINTF (1, "[%p] Breakpoint at lower frame while stepping over, continuing single stepping.\n", (gpointer)mono_native_thread_id_get ());
                        return FALSE;
                }
        }
@@ -4549,7 +4551,7 @@ ss_update (SingleStepReq *req, MonoJitInfo *ji, SeqPoint *sp, DebuggerTlsData *t
                        mono_thread_state_init_from_monoctx (&tls->context, ctx);
                compute_frame_info (tls->thread, tls);
                if (ss_req->start_method == method && req->nframes && tls->frame_count == req->nframes) {//Check also frame count(could be recursion)
-                       DEBUG_PRINTF (1, "[%p] Seq point at nonempty stack %x while stepping in, continuing single stepping.\n", (gpointer)GetCurrentThreadId (), sp->il_offset);
+                       DEBUG_PRINTF (1, "[%p] Seq point at nonempty stack %x while stepping in, continuing single stepping.\n", (gpointer)mono_native_thread_id_get (), sp->il_offset);
                        return FALSE;
                }
        }
@@ -4565,11 +4567,11 @@ ss_update (SingleStepReq *req, MonoJitInfo *ji, SeqPoint *sp, DebuggerTlsData *t
                loc = mono_debug_symfile_lookup_location (minfo, sp->il_offset);
 
        if (!loc) {
-               DEBUG_PRINTF (1, "[%p] No line number info for il offset %x, continuing single stepping.\n", (gpointer)GetCurrentThreadId (), sp->il_offset);
+               DEBUG_PRINTF (1, "[%p] No line number info for il offset %x, continuing single stepping.\n", (gpointer)mono_native_thread_id_get (), sp->il_offset);
                ss_req->last_method = method;
                hit = FALSE;
        } else if (loc && method == ss_req->last_method && loc->row == ss_req->last_line) {
-               DEBUG_PRINTF (1, "[%p] Same source line (%d), continuing single stepping.\n", (gpointer)GetCurrentThreadId (), loc->row);
+               DEBUG_PRINTF (1, "[%p] Same source line (%d), continuing single stepping.\n", (gpointer)mono_native_thread_id_get (), loc->row);
                hit = FALSE;
        }
                                
@@ -4642,7 +4644,7 @@ process_breakpoint_inner (DebuggerTlsData *tls, gboolean from_signal)
 
        g_assert (found_sp);
 
-       DEBUG_PRINTF (1, "[%p] Breakpoint hit, method=%s, ip=%p, [il=0x%x,native=0x%x].\n", (gpointer)GetCurrentThreadId (), method->name, ip, sp.il_offset, native_offset);
+       DEBUG_PRINTF (1, "[%p] Breakpoint hit, method=%s, ip=%p, [il=0x%x,native=0x%x].\n", (gpointer)mono_native_thread_id_get (), method->name, ip, sp.il_offset, native_offset);
 
        bp = NULL;
        for (i = 0; i < breakpoints->len; ++i) {
@@ -4749,7 +4751,7 @@ resume_from_signal_handler (void *sigctx, void *func)
        // FIXME: This might not work on an altstack ?
        tls = mono_native_tls_get_value (debugger_tls_id);
        if (!tls)
-               fprintf (stderr, "Thread %p is not attached to the JIT.\n", (gpointer)GetCurrentThreadId ());
+               fprintf (stderr, "Thread %p is not attached to the JIT.\n", (gpointer)mono_native_thread_id_get ());
        g_assert (tls);
 
        // FIXME: MonoContext usually doesn't include the fp registers, so these are 
@@ -4870,7 +4872,7 @@ process_single_step_inner (DebuggerTlsData *tls, gboolean from_signal)
        if (log_level > 0) {
                ji = mini_jit_info_table_find (mono_domain_get (), (char*)ip, &domain);
 
-               DEBUG_PRINTF (1, "[%p] Single step event (depth=%s) at %s (%p)[0x%x], sp %p, last sp %p\n", (gpointer)GetCurrentThreadId (), ss_depth_to_string (ss_req->depth), mono_method_full_name (jinfo_get_method (ji), TRUE), MONO_CONTEXT_GET_IP (ctx), (int)((guint8*)MONO_CONTEXT_GET_IP (ctx) - (guint8*)ji->code_start), MONO_CONTEXT_GET_SP (ctx), ss_req->last_sp);
+               DEBUG_PRINTF (1, "[%p] Single step event (depth=%s) at %s (%p)[0x%x], sp %p, last sp %p\n", (gpointer)mono_native_thread_id_get (), ss_depth_to_string (ss_req->depth), mono_method_full_name (jinfo_get_method (ji), TRUE), MONO_CONTEXT_GET_IP (ctx), (int)((guint8*)MONO_CONTEXT_GET_IP (ctx) - (guint8*)ji->code_start), MONO_CONTEXT_GET_SP (ctx), ss_req->last_sp);
        }
 
        ji = mini_jit_info_table_find (mono_domain_get (), (char*)ip, &domain);
@@ -4946,7 +4948,7 @@ mono_debugger_agent_single_step_event (void *sigctx)
        // be as fast as possible. Move the relevant code from process_single_step_inner ()
        // here
 
-       if (GetCurrentThreadId () == debugger_thread_id) {
+       if (is_debugger_thread ()) {
                /* 
                 * This could happen despite our best effors when the runtime calls 
                 * assembly/type resolve hooks.
@@ -4969,7 +4971,7 @@ debugger_agent_single_step_from_context (MonoContext *ctx)
        DebuggerTlsData *tls;
        MonoThreadUnwindState orig_restore_state;
 
-       if (GetCurrentThreadId () == debugger_thread_id)
+       if (is_debugger_thread ())
                return;
 
        tls = mono_native_tls_get_value (debugger_tls_id);
@@ -4993,7 +4995,7 @@ debugger_agent_breakpoint_from_context (MonoContext *ctx)
        MonoThreadUnwindState orig_restore_state;
        guint8 *orig_ip;
 
-       if (GetCurrentThreadId () == debugger_thread_id)
+       if (is_debugger_thread ())
                return;
 
        orig_ip = MONO_CONTEXT_GET_IP (ctx);
@@ -5883,7 +5885,7 @@ decode_vtype (MonoType *t, MonoDomain *domain, guint8 *addr, guint8 *buf, guint8
        if (t && klass != mono_class_from_mono_type (t)) {
                char *name = mono_type_full_name (t);
                char *name2 = mono_type_full_name (&klass->byval_arg);
-               DEBUG_PRINTF (1, "[%p] Expected value of type %s, got %s.\n", (gpointer)GetCurrentThreadId (), name, name2);
+               DEBUG_PRINTF (1, "[%p] Expected value of type %s, got %s.\n", (gpointer)mono_native_thread_id_get (), name, name2);
                g_free (name);
                g_free (name2);
                return ERR_INVALID_ARGUMENT;
@@ -5919,7 +5921,7 @@ decode_value_internal (MonoType *t, int type, MonoDomain *domain, guint8 *addr,
                !(t->type == MONO_TYPE_GENERICINST && type == MONO_TYPE_VALUETYPE) &&
                !(t->type == MONO_TYPE_VALUETYPE && type == MONO_TYPE_OBJECT)) {
                char *name = mono_type_full_name (t);
-               DEBUG_PRINTF (1, "[%p] Expected value of type %s, got 0x%0x.\n", (gpointer)GetCurrentThreadId (), name, type);
+               DEBUG_PRINTF (1, "[%p] Expected value of type %s, got 0x%0x.\n", (gpointer)mono_native_thread_id_get (), name, type);
                g_free (name);
                return ERR_INVALID_ARGUMENT;
        }
@@ -6063,7 +6065,7 @@ decode_value_internal (MonoType *t, int type, MonoDomain *domain, guint8 *addr,
                                g_free (vtype_buf);
                        } else {
                                char *name = mono_type_full_name (t);
-                               DEBUG_PRINTF (1, "[%p] Expected value of type %s, got 0x%0x.\n", (gpointer)GetCurrentThreadId (), name, type);
+                               DEBUG_PRINTF (1, "[%p] Expected value of type %s, got 0x%0x.\n", (gpointer)mono_native_thread_id_get (), name, type);
                                g_free (name);
                                return ERR_INVALID_ARGUMENT;
                        }
@@ -6476,7 +6478,7 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8
                 * Invoke this method directly, currently only Environment.Exit () is supported.
                 */
                this_arg = NULL;
-               DEBUG_PRINTF (1, "[%p] Invoking method '%s' on receiver '%s'.\n", (gpointer)GetCurrentThreadId (), mono_method_full_name (invoke->method, TRUE), this_arg ? this_arg->vtable->klass->name : "<null>");
+               DEBUG_PRINTF (1, "[%p] Invoking method '%s' on receiver '%s'.\n", (gpointer)mono_native_thread_id_get (), mono_method_full_name (invoke->method, TRUE), this_arg ? this_arg->vtable->klass->name : "<null>");
                mono_runtime_invoke (invoke->method, NULL, invoke->args, &exc);
                g_assert_not_reached ();
        }
@@ -6494,7 +6496,7 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8
                /* Should be null */
                int type = decode_byte (p, &p, end);
                if (type != VALUE_TYPE_ID_NULL) {
-                       DEBUG_PRINTF (1, "[%p] Error: Static vtype method invoked with this argument.\n", (gpointer)GetCurrentThreadId ());
+                       DEBUG_PRINTF (1, "[%p] Error: Static vtype method invoked with this argument.\n", (gpointer)mono_native_thread_id_get ());
                        return ERR_INVALID_ARGUMENT;
                }
                memset (this_buf, 0, mono_class_instance_size (m->klass));
@@ -6524,7 +6526,7 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8
 
        if (MONO_CLASS_IS_INTERFACE (m->klass)) {
                if (!this_arg) {
-                       DEBUG_PRINTF (1, "[%p] Error: Interface method invoked without this argument.\n", (gpointer)GetCurrentThreadId ());
+                       DEBUG_PRINTF (1, "[%p] Error: Interface method invoked without this argument.\n", (gpointer)mono_native_thread_id_get ());
                        return ERR_INVALID_ARGUMENT;
                }
                m = mono_object_get_virtual_method (this_arg, m);
@@ -6535,7 +6537,7 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8
                }
        } else if ((m->flags & METHOD_ATTRIBUTE_VIRTUAL) && !m->klass->valuetype && invoke->flags & INVOKE_FLAG_VIRTUAL) {
                if (!this_arg) {
-                       DEBUG_PRINTF (1, "[%p] Error: invoke with INVOKE_FLAG_VIRTUAL flag set without this argument.\n", (gpointer)GetCurrentThreadId ());
+                       DEBUG_PRINTF (1, "[%p] Error: invoke with INVOKE_FLAG_VIRTUAL flag set without this argument.\n", (gpointer)mono_native_thread_id_get ());
                        return ERR_INVALID_ARGUMENT;
                }
                m = mono_object_get_virtual_method (this_arg, m);
@@ -6545,7 +6547,7 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8
                }
        }
 
-       DEBUG_PRINTF (1, "[%p] Invoking method '%s' on receiver '%s'.\n", (gpointer)GetCurrentThreadId (), mono_method_full_name (m, TRUE), this_arg ? this_arg->vtable->klass->name : "<null>");
+       DEBUG_PRINTF (1, "[%p] Invoking method '%s' on receiver '%s'.\n", (gpointer)mono_native_thread_id_get (), mono_method_full_name (m, TRUE), this_arg ? this_arg->vtable->klass->name : "<null>");
 
        if (this_arg && this_arg->vtable->domain != domain)
                NOT_IMPLEMENTED;
@@ -6627,7 +6629,7 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8
        else
                res = mono_runtime_invoke (m, this_arg, args, &exc);
        mono_stopwatch_stop (&watch);
-       DEBUG_PRINTF (1, "[%p] Invoke result: %p, exc: %s, time: %ld ms.\n", (gpointer)GetCurrentThreadId (), res, exc ? exc->vtable->klass->name : NULL, (long)mono_stopwatch_elapsed_ms (&watch));
+       DEBUG_PRINTF (1, "[%p] Invoke result: %p, exc: %s, time: %ld ms.\n", (gpointer)mono_native_thread_id_get (), res, exc ? exc->vtable->klass->name : NULL, (long)mono_stopwatch_elapsed_ms (&watch));
        if (exc) {
                buffer_add_byte (buf, 0);
                buffer_add_value (buf, &mono_defaults.object_class->byval_arg, &exc, domain);
@@ -6774,7 +6776,7 @@ invoke_method (void)
                tls->resume_count -= invoke->suspend_count;
        }
 
-       DEBUG_PRINTF (1, "[%p] Invoke finished (%d), resume_count = %d.\n", (gpointer)GetCurrentThreadId (), err, tls->resume_count);
+       DEBUG_PRINTF (1, "[%p] Invoke finished (%d), resume_count = %d.\n", (gpointer)mono_native_thread_id_get (), err, tls->resume_count);
 
        /*
         * Take the loader lock to avoid race conditions with CMD_VM_ABORT_INVOKE:
@@ -9583,9 +9585,9 @@ debugger_thread (void *arg)
        gboolean no_reply;
        gboolean attach_failed = FALSE;
 
-       DEBUG_PRINTF (1, "[dbg] Agent thread started, pid=%p\n", (gpointer)GetCurrentThreadId ());
+       DEBUG_PRINTF (1, "[dbg] Agent thread started, pid=%p\n", (gpointer)mono_native_thread_id_get ());
 
-       debugger_thread_id = GetCurrentThreadId ();
+       debugger_thread_id = mono_native_thread_id_get ();
 
        mono_jit_thread_attach (mono_get_root_domain ());
 
index 5019fe169ce9984a0e3a1d52c9b5ac2370702b2a..df318df5b12372b860bcca29228a8b49b54a93fa 100644 (file)
@@ -1524,7 +1524,7 @@ mono_handle_exception_internal (MonoContext *ctx, gpointer obj, gboolean resume,
                        if (msg == NULL) {
                                msg = message ? mono_string_to_utf8 ((MonoString *) message) : g_strdup ("(System.Exception.Message property not available)");
                        }
-                       g_print ("[%p:] EXCEPTION handling: %s.%s: %s\n", (void*)GetCurrentThreadId (), mono_object_class (obj)->name_space, mono_object_class (obj)->name, msg);
+                       g_print ("[%p:] EXCEPTION handling: %s.%s: %s\n", (void*)mono_native_thread_id_get (), mono_object_class (obj)->name_space, mono_object_class (obj)->name, msg);
                        g_free (msg);
                        if (mono_ex && mono_trace_eval_exception (mono_object_class (mono_ex)))
                                mono_print_thread_dump_from_ctx (ctx);
index 27a36204ca0c354e2448695293162924744d88c8..c01d3e74968ac783ccf060fbeb9e2027ca94323a 100644 (file)
@@ -597,7 +597,7 @@ thread_attach_func (void)
        TlsData *tls;
 
        tls = g_new0 (TlsData, 1);
-       tls->tid = GetCurrentThreadId ();
+       tls->tid = mono_native_thread_id_get ();
        tls->info = mono_thread_info_current ();
        stats.tlsdata_size += sizeof (TlsData);
 
@@ -622,7 +622,7 @@ thread_suspend_func (gpointer user_data, void *sigctx, MonoContext *ctx)
                return;
        }
 
-       if (tls->tid != GetCurrentThreadId ()) {
+       if (tls->tid != mono_native_thread_id_get ()) {
                /* Happens on osx because threads are not suspended using signals */
 #ifndef TARGET_WIN32
                gboolean res;
index 9abca97a1b9fd3b11e34748588cd4188cc2d85f9..e406f413205050453886872ba66ae0f40b5483c7 100644 (file)
@@ -50,7 +50,7 @@ continuation_mark_frame (MonoContinuation *cont)
        jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
        lmf = mono_get_lmf();
        cont->domain = mono_domain_get ();
-       cont->thread_id = GetCurrentThreadId ();
+       cont->thread_id = mono_native_thread_id_get ();
 
        /* get to the frame that called Mark () */
        memset (&rji, 0, sizeof (rji));
@@ -82,7 +82,7 @@ continuation_store (MonoContinuation *cont, int state, MonoException **e)
                *e =  mono_get_exception_argument ("cont", "Continuation not initialized");
                return 0;
        }
-       if (cont->domain != mono_domain_get () || cont->thread_id != GetCurrentThreadId ()) {
+       if (cont->domain != mono_domain_get () || !mono_native_thread_id_equals (cont->thread_id, mono_native_thread_id_get ())) {
                *e = mono_get_exception_argument ("cont", "Continuation from another thread or domain");
                return 0;
        }
@@ -124,7 +124,7 @@ continuation_restore (MonoContinuation *cont, int state)
 
        if (!cont->domain || !cont->return_sp)
                return mono_get_exception_argument ("cont", "Continuation not initialized");
-       if (cont->domain != mono_domain_get () || cont->thread_id != GetCurrentThreadId ())
+       if (cont->domain != mono_domain_get () || !mono_native_thread_id_equals (cont->thread_id, mono_native_thread_id_get ()))
                return mono_get_exception_argument ("cont", "Continuation from another thread or domain");
 
        /*g_print ("restore: %p, state: %d\n", cont, state);*/
index 025a8d2db5a4335503ded53572a5f4989c60fe83..615f20a4b9b9a1067ae941b0702b87d748aab880 100644 (file)
@@ -6,7 +6,7 @@
 typedef struct {
        MonoLMF *lmf;
        gpointer top_sp;
-       gsize thread_id;
+       MonoNativeThreadId thread_id;
        MonoDomain *domain;
 
        /* the instruction pointer and stack to return to on Restore */
index abd79479169cf069619ed65c68f3b33858550e4b..d6aba0d8e0e67411ab6089de62046e4f589ea8e7 100644 (file)
@@ -357,7 +357,7 @@ static void indent (int diff) {
                indent_level += diff;
        if (start_time == 0)
                start_time = mono_100ns_ticks ();
-       printf ("[%p: %.5f %d] ", (void*)GetCurrentThreadId (), seconds_since_start (), indent_level);
+       printf ("[%p: %.5f %d] ", (void*)mono_native_thread_id_get (), seconds_since_start (), indent_level);
        if (diff > 0)
                indent_level += diff;
 }
index 6201915ae2345620174551a32318dd9ea5b64df8..a002173cf31997bace2e2fc8f914c79cfda534b6 100644 (file)
@@ -328,8 +328,17 @@ Snapshot iteration.
 #define FOREACH_THREAD_SAFE(thread) MONO_LLS_FOREACH_FILTERED_SAFE (mono_thread_info_list_head (), thread, mono_threads_filter_tools_threads, THREAD_INFO_TYPE*)
 #define END_FOREACH_THREAD_SAFE MONO_LLS_END_FOREACH_SAFE
 
-#define mono_thread_info_get_tid(info) ((MonoNativeThreadId)((MonoThreadInfo*)info)->node.key)
-#define mono_thread_info_set_tid(info, val) do { ((MonoThreadInfo*)(info))->node.key = (uintptr_t)(val); } while (0)
+static inline MonoNativeThreadId
+mono_thread_info_get_tid (THREAD_INFO_TYPE *info)
+{
+       return MONO_UINT_TO_NATIVE_THREAD_ID (((MonoThreadInfo*) info)->node.key);
+}
+
+static inline void
+mono_thread_info_set_tid (THREAD_INFO_TYPE *info, MonoNativeThreadId tid)
+{
+       ((MonoThreadInfo*) info)->node.key = (uintptr_t) MONO_NATIVE_THREAD_ID_TO_UINT (tid);
+}
 
 /*
  * @thread_info_size is sizeof (GcThreadInfo), a struct the GC defines to make it possible to have
@@ -546,9 +555,11 @@ void mono_threads_core_set_name (MonoNativeThreadId tid, const char *name);
 void mono_threads_core_begin_global_suspend (void);
 void mono_threads_core_end_global_suspend (void);
 
-MonoNativeThreadId mono_native_thread_id_get (void);
+MonoNativeThreadId
+mono_native_thread_id_get (void);
 
-gboolean mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2);
+gboolean
+mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2);
 
 gboolean
 mono_native_thread_create (MonoNativeThreadId *tid, gpointer func, gpointer arg);