2 * mono-threads-mach.c: Low-level threading, mach version
5 * Rodrigo Kumpera (kumpera@gmail.com)
14 #include <mono/utils/mach-support.h>
15 #include <mono/utils/mono-compiler.h>
16 #include <mono/utils/mono-semaphore.h>
17 #include <mono/utils/mono-threads.h>
18 #include <mono/utils/hazard-pointer.h>
19 #include <mono/metadata/gc-internal.h>
20 #include <mono/metadata/appdomain.h>
21 #include <mono/metadata/threads-types.h>
27 mono_threads_init_platform (void)
32 mono_threads_core_interrupt (MonoThreadInfo *info)
34 thread_abort (info->native_handle);
38 mono_threads_core_abort_syscall (MonoThreadInfo *info)
43 mono_threads_core_needs_abort_syscall (void)
49 mono_threads_core_suspend (MonoThreadInfo *info)
54 ret = thread_suspend (info->native_handle);
55 if (ret != KERN_SUCCESS)
57 return mono_threads_get_runtime_callbacks ()->
58 thread_state_init_from_handle (&info->suspend_state, mono_thread_info_get_tid (info), info->native_handle);
62 mono_threads_core_resume (MonoThreadInfo *info)
66 if (info->async_target) {
67 MonoContext tmp = info->suspend_state.ctx;
68 mach_msg_type_number_t num_state;
73 mono_threads_get_runtime_callbacks ()->setup_async_callback (&tmp, info->async_target, info->user_data);
74 info->async_target = info->user_data = NULL;
76 state = (thread_state_t) alloca (mono_mach_arch_get_thread_state_size ());
77 mctx = (mcontext_t) alloca (mono_mach_arch_get_mcontext_size ());
79 ret = mono_mach_arch_get_thread_state (info->native_handle, state, &num_state);
80 if (ret != KERN_SUCCESS)
83 mono_mach_arch_thread_state_to_mcontext (state, mctx);
84 uctx.uc_mcontext = mctx;
85 mono_monoctx_to_sigctx (&tmp, &uctx);
87 mono_mach_arch_mcontext_to_thread_state (mctx, state);
89 ret = mono_mach_arch_set_thread_state (info->native_handle, state, num_state);
90 if (ret != KERN_SUCCESS)
95 ret = thread_resume (info->native_handle);
96 return ret == KERN_SUCCESS;
100 mono_threads_platform_register (MonoThreadInfo *info)
102 info->native_handle = mach_thread_self ();
106 mono_threads_platform_free (MonoThreadInfo *info)
108 mach_port_deallocate (current_task (), info->native_handle);
112 mono_native_thread_id_get (void)
114 return pthread_self ();
118 mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2)
120 return pthread_equal (id1, id2);
124 * mono_native_thread_create:
126 * Low level thread creation function without any GC wrappers.
129 mono_native_thread_create (MonoNativeThreadId *tid, gpointer func, gpointer arg)
131 return pthread_create (tid, NULL, func, arg) == 0;