libgo: Adjust deadlock avoidance.
authorIan Lance Taylor <ian@gcc.gnu.org>
Sat, 22 Jan 2011 02:15:01 +0000 (02:15 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Sat, 22 Jan 2011 02:15:01 +0000 (02:15 +0000)
From-SVN: r169120

libgo/runtime/go-go.c

index 7c5f40de5efeb0e1869419ae0ab74b69fd5aba52..31462685afbb7722723e67e744ff7cec323ed871 100644 (file)
@@ -297,6 +297,15 @@ gc_stop_handler (int sig __attribute__ ((unused)))
 {
   struct M *pm = m;
 
+  if (__sync_bool_compare_and_swap (&pm->holds_finlock, 1, 1))
+    {
+      /* We can't interrupt the thread while it holds the finalizer
+        lock.  Otherwise we can get into a deadlock when mark calls
+        runtime_walkfintab.  */
+      __sync_bool_compare_and_swap (&pm->gcing_for_finlock, 0, 1);
+      return;
+    }
+
   if (__sync_bool_compare_and_swap (&pm->mallocing, 1, 1))
     {
       /* m->mallocing was already non-zero.  We can't interrupt the
@@ -315,15 +324,6 @@ gc_stop_handler (int sig __attribute__ ((unused)))
       return;
     }
 
-  if (__sync_bool_compare_and_swap (&pm->holds_finlock, 1, 1))
-    {
-      /* Similarly, we can't interrupt the thread while it holds the
-        finalizer lock.  Otherwise we can get into a deadlock when
-        mark calls runtime_walkfintab.  */
-      __sync_bool_compare_and_swap (&pm->gcing_for_finlock, 0, 1);
-      return;
-    }
-
   stop_for_gc ();
 }