From 2d1d36336dbce3bee52459d7006773fefcdd7720 Mon Sep 17 00:00:00 2001 From: Rodrigo Kumpera Date: Tue, 12 Apr 2011 20:48:00 -0300 Subject: [PATCH] Move posix only code to a separate file. --- mono/utils/Makefile.am | 1 + mono/utils/mono-threads-posix.c | 75 +++++++++++++++++++++++++++++++++++++++++ mono/utils/mono-threads.c | 71 -------------------------------------- 3 files changed, 76 insertions(+), 71 deletions(-) create mode 100644 mono/utils/mono-threads-posix.c diff --git a/mono/utils/Makefile.am b/mono/utils/Makefile.am index 0b81c6ed99a..9a2d57d13e5 100644 --- a/mono/utils/Makefile.am +++ b/mono/utils/Makefile.am @@ -87,6 +87,7 @@ monoutils_sources = \ mono-linked-list-set.c \ mono-linked-list-set.h \ mono-threads.c \ + mono-threads-posix.c \ mono-threads.h arch_sources = diff --git a/mono/utils/mono-threads-posix.c b/mono/utils/mono-threads-posix.c new file mode 100644 index 00000000000..26f3ba6a36b --- /dev/null +++ b/mono/utils/mono-threads-posix.c @@ -0,0 +1,75 @@ +/* + * mono-threads-posix.c: Low-level threading, posix version + * + * Author: + * Rodrigo Kumpera (kumpera@gmail.com) + * + * (C) 2011 Novell, Inc + */ + +#include + +#include +#include +#include +#include + +#include + +#if defined(_POSIX_VERSION) + +typedef struct { + void *(*start_routine)(void*); + void *arg; + int flags; + MonoSemType registered; +} ThreadStartInfo; + + +static void* +inner_start_thread (void *arg) +{ + ThreadStartInfo *start_info = arg; + void *t_arg = start_info->arg; + int post_result; + void *(*start_func)(void*) = start_info->start_routine; + void *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; +} + +int +mono_threads_pthread_create (pthread_t *new_thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) +{ + ThreadStartInfo *start_info; + int result; + + start_info = g_malloc0 (sizeof (ThreadStartInfo)); + if (!start_info) + return ENOMEM; + MONO_SEM_INIT (&(start_info->registered), 0); + start_info->arg = arg; + start_info->start_routine = start_routine; + + result = pthread_create (new_thread, attr, inner_start_thread, start_info); + if (result == 0) { + 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.c b/mono/utils/mono-threads.c index 0320b517e2c..519be4f68dd 100644 --- a/mono/utils/mono-threads.c +++ b/mono/utils/mono-threads.c @@ -17,27 +17,9 @@ #include -#ifdef HOST_WIN32 -#define mono_native_thread_start LPTHREAD_START_ROUTINE -#define native_thread_ret_type guint32 - -#else - -typedef void *(*mono_native_thread_start)(void*); -#define native_thread_ret_type void* - -#endif - #define THREADS_DEBUG(...) //#define THREADS_DEBUG(...) g_message(__VA_ARGS__) -typedef struct { - mono_native_thread_start start_routine; - void *arg; - int flags; - MonoSemType registered; -} ThreadStartInfo; - static int thread_info_size; static MonoThreadInfoCallbacks threads_callbacks; static MonoNativeTlsKey thread_info_key; @@ -133,31 +115,6 @@ unregister_thread (void *arg) mono_thread_small_id_free (small_id); } -static native_thread_ret_type WINAPI -inner_start_thread (void *arg) -{ - ThreadStartInfo *start_info = arg; - MonoThreadInfo* info; - void *t_arg = start_info->arg; - int post_result; - mono_native_thread_start start_func = start_info->start_routine; - native_thread_ret_type result; - - info = g_malloc0 (thread_info_size); - THREADS_DEBUG ("inner start %p\n", info); - - register_thread (info, &post_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; -} - MonoThreadInfo* mono_thread_info_current (void) { @@ -212,31 +169,3 @@ mono_threads_init (MonoThreadInfoCallbacks *callbacks, size_t info_size) g_assert (res); g_assert (sizeof (MonoNativeThreadId) == sizeof (uintptr_t)); } - -#if !defined(HOST_WIN32) - -int -mono_threads_pthread_create (pthread_t *new_thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) -{ - ThreadStartInfo *start_info; - int result; - - start_info = g_malloc0 (sizeof (ThreadStartInfo)); - if (!start_info) - return ENOMEM; - MONO_SEM_INIT (&(start_info->registered), 0); - start_info->arg = arg; - start_info->start_routine = start_routine; - - result = pthread_create (new_thread, attr, inner_start_thread, start_info); - if (result == 0) { - 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 /* !defined(HOST_WIN32) */ -- 2.11.4.GIT