[project @ 2002-11-06 13:10:46 by simonpj]
[ghc-hetmet.git] / ghc / rts / Schedule.c
index 468a596..17c7e74 100644 (file)
@@ -1,5 +1,5 @@
 /* ---------------------------------------------------------------------------
- * $Id: Schedule.c,v 1.152 2002/08/16 13:29:07 simonmar Exp $
+ * $Id: Schedule.c,v 1.157 2002/10/22 11:01:19 simonmar Exp $
  *
  * (c) The GHC Team, 1998-2000
  *
@@ -1657,10 +1657,11 @@ static void unblockThread(StgTSO *tso);
  * instances of Eq/Ord for ThreadIds.
  * ------------------------------------------------------------------------ */
 
-int cmp_thread(const StgTSO *tso1, const StgTSO *tso2) 
+int
+cmp_thread(StgPtr tso1, StgPtr tso2) 
 { 
-  StgThreadID id1 = tso1->id; 
-  StgThreadID id2 = tso2->id;
+  StgThreadID id1 = ((StgTSO *)tso1)->id; 
+  StgThreadID id2 = ((StgTSO *)tso2)->id;
  
   if (id1 < id2) return (-1);
   if (id1 > id2) return 1;
@@ -1672,13 +1673,15 @@ int cmp_thread(const StgTSO *tso1, const StgTSO *tso2)
  *
  * This is used in the implementation of Show for ThreadIds.
  * ------------------------------------------------------------------------ */
-int rts_getThreadId(const StgTSO *tso) 
+int
+rts_getThreadId(StgPtr tso) 
 {
-  return tso->id;
+  return ((StgTSO *)tso)->id;
 }
 
 #ifdef DEBUG
-void labelThread(StgTSO *tso, char *label)
+void
+labelThread(StgPtr tso, char *label)
 {
   int len;
   void *buf;
@@ -2472,6 +2475,30 @@ GetRoots(evac_fn evac)
 #if defined(PAR) || defined(GRAN)
   markSparkQueue(evac);
 #endif
+
+#ifndef mingw32_TARGET_OS
+  // mark the signal handlers (signals should be already blocked)
+  markSignalHandlers(evac);
+#endif
+
+  // main threads which have completed need to be retained until they
+  // are dealt with in the main scheduler loop.  They won't be
+  // retained any other way: the GC will drop them from the
+  // all_threads list, so we have to be careful to treat them as roots
+  // here.
+  { 
+      StgMainThread *m;
+      for (m = main_threads; m != NULL; m = m->link) {
+         switch (m->tso->what_next) {
+         case ThreadComplete:
+         case ThreadKilled:
+             evac((StgClosure **)&m->tso);
+             break;
+         default:
+             break;
+         }
+      }
+  }
 }
 
 /* -----------------------------------------------------------------------------
@@ -3258,7 +3285,6 @@ raiseAsync(StgTSO *tso, StgClosure *exception)
   /* Remove it from any blocking queues */
   unblockThread(tso);
 
-  IF_DEBUG(scheduler, sched_belch("raising exception in thread %ld.", tso->id));
   /* The stack freezing code assumes there's a closure pointer on
    * the top of the stack.  This isn't always the case with compiled
    * code, so we have to push a dummy closure on the top which just