ICALL_TYPE(THREAD, "System.Threading.Thread", THREAD_1)
HANDLES(THREAD_1, "ClrState", ves_icall_System_Threading_Thread_ClrState, void, 2, (MonoInternalThread, guint32))
HANDLES(ITHREAD_2, "FreeInternal", ves_icall_System_Threading_InternalThread_Thread_free_internal, void, 1, (MonoInternalThread))
+HANDLES(THREAD_15, "GetCurrentOSThreadId", ves_icall_System_Threading_Thread_GetCurrentOSThreadId, guint64, 0, ())
HANDLES(THREAD_3, "GetState", ves_icall_System_Threading_Thread_GetState, guint32, 1, (MonoInternalThread))
HANDLES(THREAD_4, "InitInternal", ves_icall_System_Threading_Thread_InitInternal, void, 1, (MonoThreadObject))
HANDLES(THREAD_5, "InitializeCurrentThread", ves_icall_System_Threading_Thread_GetCurrentThread, MonoThreadObject, 0, ())
MONO_OBJECT_SETREF_INTERNAL (internal, internal_thread, internal);
}
+guint64
+ves_icall_System_Threading_Thread_GetCurrentOSThreadId (MonoError *error)
+{
+ return mono_native_thread_os_id_get ();
+}
+
#endif
return pthread_self () == 1;
}
+guint64
+mono_native_thread_os_id_get (void)
+{
+ pthread_t t = pthread_self ();
+ struct __pthrdsinfo ti;
+ int err, size = 0;
+ err = pthread_getthrds_np (&t, PTHRDSINFO_QUERY_TID, &ti, sizeof (struct __pthrdsinfo), NULL, &size);
+ return (guint64)ti.__pi_tid;
+}
+
#endif
#include <inttypes.h>
#include "glib.h"
#include <mono/utils/mono-threads.h>
+#include <sys/syscall.h>
static void
slow_get_thread_bounds (guint8 *current, guint8 **staddr, size_t *stsize)
slow_get_thread_bounds (current, staddr, stsize);
}
+guint64
+mono_native_thread_os_id_get (void)
+{
+ return (guint64)syscall (SYS_gettid);
+}
+
#endif
#include <mono/utils/mono-threads.h>
#include <pthread.h>
#include <pthread_np.h>
+#include <sys/thr.h>
void
mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize)
pthread_attr_destroy (&attr);
}
+guint64
+mono_native_thread_os_id_get (void)
+{
+ long tid;
+ thr_self (&tid);
+ return (guint64)tid;
+}
+
#endif
*stsize = ti.stack_end - ti.stack_base;
}
+guint64
+mono_native_thread_os_id_get (void)
+{
+ return (guint64)get_pthread_thread_id (pthread_self ());
+}
+
#endif
#include <mono/utils/mono-threads.h>
#include <pthread.h>
+#include <sys/syscall.h>
void
mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize)
}
+guint64
+mono_native_thread_os_id_get (void)
+{
+ return (guint64)syscall (SYS_gettid);
+}
+
#endif
{
return pthread_main_np () == 1;
}
+
+guint64
+mono_native_thread_os_id_get (void)
+{
+ uint64_t tid;
+ pthread_threadid_np (pthread_self (), &tid);
+ return tid;
+}
#endif
#include <mono/utils/mono-threads.h>
#include <pthread.h>
+#include <lwp.h>
void
mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize)
pthread_attr_destroy (&attr);
}
+guint64
+mono_native_thread_os_id_get (void)
+{
+ return (guint64)_lwp_self ();
+}
+
#endif
*stsize = ss.ss_size;
}
+guint64
+mono_native_thread_os_id_get (void)
+{
+ return (guint64)getthrid ();
+}
+
#endif
#endif
}
+guint64
+mono_native_thread_os_id_get (void)
+{
+#ifdef __EMSCRIPTEN_PTHREADS__
+ return (guint64)pthread_self ();
+#else
+ return 1;
+#endif
+}
+
MONO_API gboolean
mono_native_thread_create (MonoNativeThreadId *tid, gpointer func, gpointer arg)
{
return GetCurrentThreadId ();
}
+guint64
+mono_native_thread_os_id_get (void)
+{
+ return (guint64)GetCurrentThreadId ();
+}
+
gboolean
mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2)
{
MONO_API MonoNativeThreadId
mono_native_thread_id_get (void);
+/*
+ * This does _not_ return the same value as mono_native_thread_id_get, except on Windows.
+ * On POSIX, mono_native_thread_id_get returns the value from pthread_self, which is then
+ * passed around as an identifier to other pthread functions. However this function, where
+ * possible, returns the OS-unique thread id value, fetched in a platform-specific manner.
+ * It will not work with the various pthread functions, should never be used as a
+ * MonoNativeThreadId, and is intended solely to match the output of various diagonistic tools.
+ */
+guint64 mono_native_thread_os_id_get (void);
+
MONO_API gboolean
mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2);
internal static ulong CurrentOSThreadId {
get {
- throw new NotImplementedException ();
+ return GetCurrentOSThreadId ();
}
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
+ private extern static ulong GetCurrentOSThreadId ();
+
+ [MethodImplAttribute (MethodImplOptions.InternalCall)]
extern static void InitInternal (Thread thread);
[MethodImplAttribute(MethodImplOptions.InternalCall)]