[dtrace] GC begin/end probes for SGen.
[mono.git] / mono / metadata / sgen-os-mach.c
index 6d31f415145d2c8e1f8278feb00199540121f250..c99debf9943963949dc2487155a95d352db3fc32 100644 (file)
 
 #include "config.h"
 #ifdef HAVE_SGEN_GC
+
+
 #include <glib.h>
-#include "metadata/gc-internal.h"
 #include "metadata/sgen-gc.h"
 #include "metadata/sgen-archdep.h"
 #include "metadata/object-internals.h"
+#include "metadata/gc-internal.h"
 
 #if defined(__MACH__)
 #include "utils/mach-support.h"
 
 #if defined(__MACH__) && MONO_MACH_ARCH_SUPPORTED
 gboolean
-mono_sgen_suspend_thread (SgenThreadInfo *info)
+sgen_resume_thread (SgenThreadInfo *info)
+{
+       return thread_resume (info->mach_port) == KERN_SUCCESS;
+}
+
+gboolean
+sgen_suspend_thread (SgenThreadInfo *info)
 {
        mach_msg_type_number_t num_state;
        thread_state_t state;
@@ -66,7 +74,8 @@ mono_sgen_suspend_thread (SgenThreadInfo *info)
        mono_mach_arch_thread_state_to_mcontext (state, mctx);
        ctx.uc_mcontext = mctx;
 
-       info->stopped_domain = mono_mach_arch_get_tls_value_from_thread ((pthread_t)info->id, mono_domain_get_tls_offset ());
+       info->stopped_domain = mono_mach_arch_get_tls_value_from_thread (
+               mono_thread_info_get_tid (info), mono_domain_get_tls_offset ());
        info->stopped_ip = (gpointer) mono_mach_arch_get_ip (state);
        stack_start = (char*) mono_mach_arch_get_sp (state) - REDZONE_SIZE;
        /* If stack_start is not within the limits, then don't set it in info and we will be restarted. */
@@ -86,36 +95,65 @@ mono_sgen_suspend_thread (SgenThreadInfo *info)
 
        /* Notify the JIT */
        if (mono_gc_get_gc_callbacks ()->thread_suspend_func)
-               mono_gc_get_gc_callbacks ()->thread_suspend_func (info->runtime_data, &ctx);
+               mono_gc_get_gc_callbacks ()->thread_suspend_func (info->runtime_data, &ctx, NULL);
+
        return TRUE;
 }
 
+void
+sgen_wait_for_suspend_ack (int count)
+{
+    /* mach thread_resume is synchronous so we dont need to wait for them */
+}
+
 /* LOCKING: assumes the GC lock is held */
 int
-mono_sgen_thread_handshake (int signum)
+sgen_thread_handshake (BOOL suspend)
 {
-       SgenThreadInfo *cur_thread = mono_sgen_thread_info_current ();
+       SgenThreadInfo *cur_thread = mono_thread_info_current ();
        kern_return_t ret;
-
        SgenThreadInfo *info;
 
        int count = 0;
 
-       FOREACH_THREAD (info) {
-               if (info == cur_thread || mono_sgen_is_worker_thread (info->id))
+       FOREACH_THREAD_SAFE (info) {
+               if (info->joined_stw == suspend)
                        continue;
+               info->joined_stw = suspend;
 
-               if (signum == suspend_signal_num) {
-                       if (!mono_sgen_suspend_thread (info))
+               if (info == cur_thread || sgen_is_worker_thread (mono_thread_info_get_tid (info)))
+                       continue;
+               if (info->gc_disabled)
+                       continue;
+
+               if (suspend) {
+                       g_assert (!info->doing_handshake);
+                       info->doing_handshake = TRUE;
+
+                       if (!sgen_suspend_thread (info))
                                continue;
                } else {
+                       g_assert (info->doing_handshake);
+                       info->doing_handshake = FALSE;
+
                        ret = thread_resume (info->mach_port);
                        if (ret != KERN_SUCCESS)
                                continue;
                }
                count ++;
-       } END_FOREACH_THREAD
+       } END_FOREACH_THREAD_SAFE
        return count;
 }
+
+void
+sgen_os_init (void)
+{
+}
+
+int
+mono_gc_get_suspend_signal (void)
+{
+       return -1;
+}
 #endif
 #endif