Merge pull request #444 from knocte/xbuild_improvements
[mono.git] / libgc / pthread_stop_world.c
index b1f98099d1e79e60937a2edebd00630d55df6216..e6ac64b62a8ee24f5a94a1e3040f9e6ae4d6197b 100644 (file)
@@ -290,6 +290,10 @@ static void pthread_push_all_stacks()
                (unsigned long) lo, (unsigned long) hi);
         #endif
        if (0 == lo) ABORT("GC_push_all_stacks: sp not set!\n");
+       if (p->altstack && lo >= p->altstack && lo <= p->altstack + p->altstack_size)
+               hi = p->altstack + p->altstack_size;
+       /* FIXME: Need to scan the normal stack too, but how ? */
+
 #       ifdef STACK_GROWS_UP
          /* We got them backwards! */
           GC_push_all_stack(hi, lo);
@@ -461,6 +465,7 @@ static void pthread_stop_world()
 #else /* NACL */
     GC_thread p;
     int i;
+    int num_sleeps = 0;
 
     #if DEBUG_THREADS
     GC_printf1("pthread_stop_world: num_threads %d\n", nacl_num_gc_threads - 1);
@@ -470,6 +475,7 @@ static void pthread_stop_world()
     
     while (1) {
        #define NACL_PARK_WAIT_NANOSECONDS 100000
+        #define NANOS_PER_SECOND 1000000000
         int num_threads_parked = 0;
         struct timespec ts;
         int num_used = 0;
@@ -491,6 +497,10 @@ static void pthread_stop_world()
         GC_printf1("sleeping waiting for %d threads to park...\n", nacl_num_gc_threads - num_threads_parked - 1);
         #endif
         nanosleep(&ts, 0);
+        if (++num_sleeps > NANOS_PER_SECOND / NACL_PARK_WAIT_NANOSECONDS) {
+            GC_printf1("GC appears stalled waiting for %d threads to park...\n", nacl_num_gc_threads - num_threads_parked - 1);
+            num_sleeps = 0;
+        }
     }
 
 #endif /* NACL */
@@ -674,10 +684,14 @@ static void pthread_start_world()
       GC_printf0("World started\n");
     #endif
 #else /* NACL */
+    if (GC_notify_event)
+        GC_notify_event (GC_EVENT_PRE_START_WORLD);
 #   if DEBUG_THREADS
     GC_printf0("World starting\n");
 #   endif
     nacl_park_threads_now = 0;
+    if (GC_notify_event)
+        GC_notify_event (GC_EVENT_POST_START_WORLD);
 #endif /* NACL */
 }