Skip to content

Instantly share code, notes, and snippets.

@schani
Created October 3, 2011 13:47
Show Gist options
  • Select an option

  • Save schani/1259136 to your computer and use it in GitHub Desktop.

Select an option

Save schani/1259136 to your computer and use it in GitHub Desktop.
diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c
index 422dff8..a8dbcb7 100644
--- a/mono/metadata/threads.c
+++ b/mono/metadata/threads.c
@@ -651,7 +651,8 @@ gpointer mono_create_thread (WapiSecurityAttributes *security,
#ifdef HOST_WIN32
DWORD real_tid;
- res = CreateThread (security, stacksize, start, param, create, &real_tid);
+ g_print ("CreateThread is %p\n", mono_threads_CreateThread);
+ res = mono_threads_CreateThread (security, stacksize, start, param, create, &real_tid);
if (tid)
*tid = real_tid;
#else
diff --git a/mono/utils/mono-threads-windows.c b/mono/utils/mono-threads-windows.c
index 3e153a7..a132c85 100644
--- a/mono/utils/mono-threads-windows.c
+++ b/mono/utils/mono-threads-windows.c
@@ -53,4 +53,57 @@ mono_threads_platform_free (MonoThreadInfo *info)
{
}
+typedef struct {
+ LPTHREAD_START_ROUTINE start_routine;
+ void *arg;
+ MonoSemType registered;
+} ThreadStartInfo;
+
+static DWORD WINAPI
+inner_start_thread (LPVOID arg)
+{
+ ThreadStartInfo *start_info = arg;
+ void *t_arg = start_info->arg;
+ int post_result;
+ LPTHREAD_START_ROUTINE start_func = start_info->start_routine;
+ DWORD result;
+
+ mono_thread_info_attach (&result);
+
+ post_result = MONO_SEM_POST (&(start_info->registered));
+ g_assert (!post_result);
+
+ result = start_func (t_arg);
+ g_assert (!mono_domain_get ());
+
+ return result;
+}
+
+HANDLE
+mono_threads_CreateThread (LPSECURITY_ATTRIBUTES attributes, SIZE_T stack_size, LPTHREAD_START_ROUTINE start_routine,
+ LPVOID arg, DWORD creation_flags, LPDWORD thread_id)
+{
+ ThreadStartInfo *start_info;
+ HANDLE result;
+
+ g_print ("creating thread\n");
+
+ start_info = g_malloc0 (sizeof (ThreadStartInfo));
+ if (!start_info)
+ return NULL;
+ MONO_SEM_INIT (&(start_info->registered), 0);
+ start_info->arg = arg;
+ start_info->start_routine = start_routine;
+
+ result = CreateThread (attributes, stack_size, inner_start_thread, start_info, creation_flags, thread_id);
+ if (result) {
+ while (MONO_SEM_WAIT (&(start_info->registered)) != 0) {
+ /*if (EINTR != errno) ABORT("sem_wait failed"); */
+ }
+ }
+ MONO_SEM_DESTROY (&(start_info->registered));
+ g_free (start_info);
+ return result;
+}
+
#endif
diff --git a/mono/utils/mono-threads.h b/mono/utils/mono-threads.h
index 252bca1..77ecd71 100644
--- a/mono/utils/mono-threads.h
+++ b/mono/utils/mono-threads.h
@@ -29,6 +29,9 @@ typedef HANDLE MonoNativeThreadHandle;
#define mono_native_thread_id_get GetCurrentThreadId
#define mono_native_thread_id_equals(a,b) ((a) == ((b))
+HANDLE mono_threads_CreateThread (LPSECURITY_ATTRIBUTES attributes, SIZE_T stack_size, LPTHREAD_START_ROUTINE start_routine,
+ LPVOID arg, DWORD creation_flags, LPDWORD thread_id) MONO_INTERNAL;
+
#else
#include <pthread.h>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment