Merge pull request #900 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mono / utils / mono-threads-posix.c
index 527ef5a119e0ff254e9ffcc4a187ba9a759fda3e..36bab7c9be76f3bc9af44efda4c15d052ac4569b 100644 (file)
@@ -18,7 +18,6 @@
 #include <mono/utils/mono-semaphore.h>
 #include <mono/utils/mono-threads.h>
 #include <mono/utils/mono-tls.h>
-#include <mono/utils/gc_wrapper.h>
 #include <mono/utils/mono-mmap.h>
 #include <mono/metadata/threads-types.h>
 
@@ -69,13 +68,9 @@ inner_start_thread (void *arg)
        }
        start_info->handle = handle;
 
-       if (!(flags & CREATE_NO_DETACH)) {
-               res = mono_gc_pthread_detach (pthread_self ());
-               g_assert (!res);
-       }
-
        info = mono_thread_info_attach (&result);
        info->runtime_thread = TRUE;
+       info->handle = handle;
 
        if (flags & CREATE_SUSPENDED) {
                info->create_suspended = TRUE;
@@ -97,19 +92,19 @@ inner_start_thread (void *arg)
        result = start_func (t_arg);
 
        /*
-       g_assert (!mono_domain_get ());
-       mono_thread_info_dettach ();
+       mono_thread_info_detach ();
        */
 
 #if defined(__native_client__)
        nacl_shutdown_gc_thread();
 #endif
 
-       wapi_thread_set_exit_code (GPOINTER_TO_UINT (result), handle);
-
-       // FIXME: Why is this needed ?
-       mono_gc_pthread_exit (NULL);
+       wapi_thread_handle_set_exited (handle, GPOINTER_TO_UINT (result));
+       /* This is needed by mono_threads_core_unregister () which is called later */
+       info->handle = NULL;
 
+       g_assert (mono_threads_get_callbacks ()->thread_exit);
+       mono_threads_get_callbacks ()->thread_exit (NULL);
        g_assert_not_reached ();
        return result;
 }
@@ -290,6 +285,51 @@ mono_threads_core_get_stack_bounds (guint8 **staddr, size_t *stsize)
 #endif
 }
 
+gboolean
+mono_threads_core_yield (void)
+{
+       return sched_yield () == 0;
+}
+
+void
+mono_threads_core_exit (int exit_code)
+{
+       MonoThreadInfo *current = mono_thread_info_current ();
+
+#if defined(__native_client__)
+       nacl_shutdown_gc_thread();
+#endif
+
+       wapi_thread_handle_set_exited (current->handle, exit_code);
+
+       g_assert (mono_threads_get_callbacks ()->thread_exit);
+       mono_threads_get_callbacks ()->thread_exit (NULL);
+}
+
+void
+mono_threads_core_unregister (MonoThreadInfo *info)
+{
+       if (info->handle) {
+               wapi_thread_handle_set_exited (info->handle, 0);
+               info->handle = NULL;
+       }
+}
+
+HANDLE
+mono_threads_core_open_handle (void)
+{
+       MonoThreadInfo *info;
+
+       info = mono_thread_info_current ();
+       g_assert (info);
+
+       if (!info->handle)
+               info->handle = wapi_create_thread_handle ();
+       else
+               wapi_ref_thread_handle (info->handle);
+       return info->handle;
+}
+
 #if !defined (__MACH__)
 
 #if !defined(__native_client__)