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_safely (info->native_handle);
38 mono_threads_core_suspend (MonoThreadInfo *info)
43 ret = thread_suspend (info->native_handle);
44 if (ret != KERN_SUCCESS)
46 return mono_threads_get_runtime_callbacks ()->
47 thread_state_init_from_handle (&info->suspend_state, mono_thread_info_get_tid (info), info->native_handle);
51 mono_threads_core_resume (MonoThreadInfo *info)
55 if (info->async_target) {
56 MonoContext tmp = info->suspend_state.ctx;
57 mach_msg_type_number_t num_state;
62 mono_threads_get_runtime_callbacks ()->setup_async_callback (&tmp, info->async_target, info->user_data);
63 info->async_target = info->user_data = NULL;
65 state = (thread_state_t) alloca (mono_mach_arch_get_thread_state_size ());
66 mctx = (mcontext_t) alloca (mono_mach_arch_get_mcontext_size ());
68 ret = mono_mach_arch_get_thread_state (info->native_handle, state, &num_state);
69 if (ret != KERN_SUCCESS)
72 mono_mach_arch_thread_state_to_mcontext (state, mctx);
73 uctx.uc_mcontext = mctx;
74 mono_monoctx_to_sigctx (&tmp, &uctx);
76 mono_mach_arch_mcontext_to_thread_state (mctx, state);
78 ret = mono_mach_arch_set_thread_state (info->native_handle, state, num_state);
79 if (ret != KERN_SUCCESS)
84 ret = thread_resume (info->native_handle);
85 return ret == KERN_SUCCESS;
89 mono_threads_platform_register (MonoThreadInfo *info)
91 info->native_handle = mach_thread_self ();
95 mono_threads_platform_free (MonoThreadInfo *info)
97 mach_port_deallocate (current_task (), info->native_handle);
101 mono_native_thread_id_get (void)
103 return pthread_self ();
107 mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2)
109 return pthread_equal (id1, id2);
113 * mono_native_thread_create:
115 * Low level thread creation function without any GC wrappers.
118 mono_native_thread_create (MonoNativeThreadId *tid, gpointer func, gpointer arg)
120 return pthread_create (tid, NULL, func, arg) == 0;