Merge pull request #2338 from BogdanovKirill/httpwritefix3
[mono.git] / mono / utils / mono-threads-mach.c
index 14db1cc9550ab00c2e32ffda88c5f60ee64ec32d..6f2ddfa78af52357be210b50a2a43c3a73526b52 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <mono/utils/mach-support.h>
 #include <mono/utils/mono-compiler.h>
-#include <mono/utils/mono-semaphore.h>
 #include <mono/utils/mono-threads.h>
 #include <mono/utils/hazard-pointer.h>
 
@@ -31,43 +30,28 @@ mono_threads_init_platform (void)
        mono_threads_init_dead_letter ();
 }
 
-void
-mono_threads_core_interrupt (MonoThreadInfo *info)
+#if defined(HOST_WATCHOS) || defined(HOST_TVOS)
+
+gboolean
+mono_threads_core_begin_async_suspend (MonoThreadInfo *info, gboolean interrupt_kernel)
 {
-       thread_abort (info->native_handle);
+       g_assert_not_reached ();
 }
 
-void
-mono_threads_core_abort_syscall (MonoThreadInfo *info)
+gboolean
+mono_threads_core_check_suspend_result (MonoThreadInfo *info)
 {
-       kern_return_t ret;
-
-       ret = thread_suspend (info->native_handle);
-       if (ret != KERN_SUCCESS)
-               return;
-
-       ret = thread_abort_safely (info->native_handle);
-
-       /*
-        * We are doing thread_abort when thread_abort_safely returns KERN_SUCCESS because
-        * for some reason accept is not interrupted by thread_abort_safely.
-        * The risk of aborting non-atomic operations while calling thread_abort should not
-        * exist because by the time thread_abort_safely returns KERN_SUCCESS the target
-        * thread should have return from the kernel and should be waiting for thread_resume
-        * to resume the user code.
-        */
-       if (ret == KERN_SUCCESS)
-               ret = thread_abort (info->native_handle);
-
-       g_assert (thread_resume (info->native_handle) == KERN_SUCCESS);
+       g_assert_not_reached ();
 }
 
 gboolean
-mono_threads_core_needs_abort_syscall (void)
+mono_threads_core_begin_async_resume (MonoThreadInfo *info)
 {
-       return TRUE;
+       g_assert_not_reached ();
 }
 
+#else /* defined(HOST_WATCHOS) || defined(HOST_TVOS) */
+
 gboolean
 mono_threads_core_begin_async_suspend (MonoThreadInfo *info, gboolean interrupt_kernel)
 {
@@ -122,7 +106,8 @@ mono_threads_core_begin_async_resume (MonoThreadInfo *info)
                mcontext_t mctx;
 
                mono_threads_get_runtime_callbacks ()->setup_async_callback (&tmp, info->async_target, info->user_data);
-               info->async_target = info->user_data = NULL;
+               info->user_data = NULL;
+               info->async_target = (void (*)(void *)) info->user_data;
 
                state = (thread_state_t) alloca (mono_mach_arch_get_thread_state_size ());
                mctx = (mcontext_t) alloca (mono_mach_arch_get_mcontext_size ());
@@ -132,11 +117,7 @@ mono_threads_core_begin_async_resume (MonoThreadInfo *info)
                        return FALSE;
 
                mono_mach_arch_thread_state_to_mcontext (state, mctx);
-#ifdef TARGET_ARM64
-               g_assert_not_reached ();
-#else
                uctx.uc_mcontext = mctx;
-#endif
                mono_monoctx_to_sigctx (&tmp, &uctx);
 
                mono_mach_arch_mcontext_to_thread_state (mctx, state);
@@ -152,10 +133,18 @@ mono_threads_core_begin_async_resume (MonoThreadInfo *info)
        return ret == KERN_SUCCESS;
 }
 
+#endif /* defined(HOST_WATCHOS) || defined(HOST_TVOS) */
+
 void
 mono_threads_platform_register (MonoThreadInfo *info)
 {
+       char thread_name [64];
+
        info->native_handle = mach_thread_self ();
+
+       snprintf (thread_name, sizeof (thread_name), "tid_%x", (int) info->native_handle);
+       pthread_setname_np (thread_name);
+
        mono_threads_install_dead_letter ();
 }