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);
#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
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;
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,
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);
#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
typedef struct
{
- guint32 initializing_tid;
+ MonoNativeThreadId initializing_tid;
guint32 waiting_count;
gboolean done;
mono_mutex_t initialization_section;
gchar *full_name;
MonoDomain *domain = vtable->domain;
TypeInitializationLock *lock;
- guint32 tid;
+ MonoNativeThreadId tid;
int do_initialization = 0;
MonoDomain *last_domain = NULL;
return NULL;
}
- tid = GetCurrentThreadId ();
+ tid = mono_native_thread_id_get ();
mono_type_initialization_lock ();
/* double check... */
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;
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 */
}
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) {
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
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 ();
}
{
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);
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;
}
{
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;
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;
}
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);
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);
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
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)
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 --;
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);
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;
}
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;
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
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);
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
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 */
* 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
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
* 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);
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;
}
MonoInternalThread *thread;
MonoThread *current_thread;
HANDLE thread_handle;
- gsize tid;
+ MonoNativeThreadId tid;
if ((thread = mono_thread_internal_current ())) {
if (domain != mono_domain_get ())
}
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 ();
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));
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);
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;
}
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);
}
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.
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;
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);
}
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)
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;
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;
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);
}
/**
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;
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;
/* 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;
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
* 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);
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);
}
}
{
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 };
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.
*/
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) {
/*
* 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;
}
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 ?
{
int err;
- g_assert (debugger_thread_id == GetCurrentThreadId ());
+ g_assert (is_debugger_thread ());
mono_loader_lock ();
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 ?
int err;
DebuggerTlsData *tls;
- g_assert (debugger_thread_id == GetCurrentThreadId ());
+ g_assert (is_debugger_thread ());
mono_loader_lock ();
DebuggerTlsData *tls;
int err;
- g_assert (debugger_thread_id != GetCurrentThreadId ());
+ g_assert (!is_debugger_thread ());
if (mono_loader_lock_is_owned_by_self ()) {
/*
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) {
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 */
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);
}
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;
}
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:
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) {
* 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 ();
}
}
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);
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 */
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.
/*
* 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;
}
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;
}
}
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;
}
}
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;
}
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) {
// 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
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);
// 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.
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);
MonoThreadUnwindState orig_restore_state;
guint8 *orig_ip;
- if (GetCurrentThreadId () == debugger_thread_id)
+ if (is_debugger_thread ())
return;
orig_ip = MONO_CONTEXT_GET_IP (ctx);
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;
!(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;
}
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;
}
* 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 ();
}
/* 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));
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);
}
} 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);
}
}
- 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;
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);
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:
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 ());
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);
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);
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;
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));
*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;
}
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);*/
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 */
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;
}
#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
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);