Merge pull request #1691 from esdrubal/exitevent
[mono.git] / mono / metadata / sgen-os-mach.c
index cfef862bccebfa4c74758c7dbd72a1b0031e64d7..403d04c3d9a56f95560c27f08f8b55e2d0a0bdd9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * sgen-os-mach.c: Simple generational GC.
+ * sgen-os-mach.c: Mach-OS support.
  *
  * Author:
  *     Paolo Molaro (lupus@ximian.com)
@@ -7,25 +7,20 @@
  *     Geoff Norton (gnorton@novell.com)
  *
  * Copyright 2010 Novell, Inc (http://www.novell.com)
+ * Copyright (C) 2012 Xamarin Inc
  *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- * 
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License 2.0 as published by the Free Software Foundation;
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License 2.0 along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include "config.h"
@@ -36,6 +31,7 @@
 #include "metadata/sgen-gc.h"
 #include "metadata/sgen-archdep.h"
 #include "metadata/sgen-protocol.h"
+#include "metadata/sgen-thread-pool.h"
 #include "metadata/object-internals.h"
 #include "metadata/gc-internal.h"
 
@@ -75,8 +71,7 @@ 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 (
-               mono_thread_info_get_tid (info), mono_domain_get_tls_key ());
+       info->stopped_domain = mono_thread_info_tls_get (info, TLS_KEY_DOMAIN);
        info->stopped_ip = (gpointer) mono_mach_arch_get_ip (state);
        info->stack_start = NULL;
        stack_start = (char*) mono_mach_arch_get_sp (state) - REDZONE_SIZE;
@@ -97,7 +92,7 @@ sgen_suspend_thread (SgenThreadInfo *info)
        if (mono_gc_get_gc_callbacks ()->thread_suspend_func)
                mono_gc_get_gc_callbacks ()->thread_suspend_func (info->runtime_data, &ctx, NULL);
 
-       SGEN_LOG (2, "thread %p stopped at %p stack_start=%p", (void*)info->info.native_handle, info->stopped_ip, info->stack_start);
+       SGEN_LOG (2, "thread %p stopped at %p stack_start=%p", (void*)(gsize)info->info.native_handle, info->stopped_ip, info->stack_start);
 
        binary_protocol_thread_suspend ((gpointer)mono_thread_info_get_tid (info), info->stopped_ip);
 
@@ -120,26 +115,19 @@ sgen_thread_handshake (BOOL suspend)
 
        int count = 0;
 
+       cur_thread->suspend_done = TRUE;
        FOREACH_THREAD_SAFE (info) {
-               if (info->joined_stw == suspend)
+               if (info == cur_thread || sgen_thread_pool_is_thread_pool_thread (mono_thread_info_get_tid (info)))
                        continue;
-               info->joined_stw = suspend;
 
-               if (info == cur_thread || sgen_is_worker_thread (mono_thread_info_get_tid (info)))
-                       continue;
+               info->suspend_done = FALSE;
                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->info.native_handle);
                        if (ret != KERN_SUCCESS)
                                continue;
@@ -159,5 +147,11 @@ mono_gc_get_suspend_signal (void)
 {
        return -1;
 }
+
+int
+mono_gc_get_restart_signal (void)
+{
+       return -1;
+}
 #endif
 #endif