[project @ 1999-06-25 09:17:58 by simonmar]
[ghc-hetmet.git] / ghc / rts / Schedule.c
index 6e80db9..064f1e6 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Schedule.c,v 1.17 1999/03/17 09:50:08 simonm Exp $
+ * $Id: Schedule.c,v 1.22 1999/06/25 09:17:58 simonmar Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
@@ -515,13 +515,19 @@ threadStackOverflow(StgTSO *tso)
   StgTSO *dest;
 
   if (tso->stack_size >= tso->max_stack_size) {
-    /* ToDo: just kill this thread? */
-#ifdef DEBUG
+#if 0
     /* If we're debugging, just print out the top of the stack */
     printStackChunk(tso->sp, stg_min(tso->stack+tso->stack_size, 
                                     tso->sp+64));
 #endif
-    stackOverflow(tso->max_stack_size);
+#ifdef INTERPRETER
+    fprintf(stderr, "fatal: stack overflow in Hugs; aborting\n" );
+    exit(1);
+#else
+    /* Send this thread the StackOverflow exception */
+    raiseAsync(tso, (StgClosure *)&stackOverflow_closure);
+#endif
+    return tso;
   }
 
   /* Try to double the current stack size.  If that takes us over the
@@ -640,9 +646,10 @@ unblockThread(StgTSO *tso)
          if (mvar->tail == tso) {
            mvar->tail = last_tso;
          }
-         break;
+         goto done;
        }
       }
+      barf("unblockThread (MVAR): TSO not found");
     }
 
   case BLACKHOLE_BQ:
@@ -654,17 +661,20 @@ unblockThread(StgTSO *tso)
           last = &t->link, t = t->link) {
        if (t == tso) {
          *last = tso->link;
-         break;
+         goto done;
        }
       }
+      barf("unblockThread (BLACKHOLE): TSO not found");
     }
 
   default:
     barf("unblockThread");
   }
 
+ done:
   tso->link = END_TSO_QUEUE;
   tso->blocked_on = NULL;
+  PUSH_ON_RUN_QUEUE(tso);
 }
 
 /* -----------------------------------------------------------------------------
@@ -745,7 +755,7 @@ raiseAsync(StgTSO *tso, StgClosure *exception)
        * handler in this frame.
        */
       ap = (StgAP_UPD *)allocate(sizeofW(StgPAP) + 1);
-      TICK_ALLOC_THK(2,0);
+      TICK_ALLOC_UPD_PAP(2,0);
       SET_HDR(ap,&PAP_info,cf->header.prof.ccs);
              
       ap->n_args = 1;
@@ -761,10 +771,6 @@ raiseAsync(StgTSO *tso, StgClosure *exception)
       tso->su = cf->link;
       tso->sp = sp;
       tso->whatNext = ThreadEnterGHC;
-      /* wake up the thread */
-      if (tso->link == END_TSO_QUEUE) {
-       PUSH_ON_RUN_QUEUE(tso);
-      }
       return;
     }
 
@@ -773,7 +779,6 @@ raiseAsync(StgTSO *tso, StgClosure *exception)
      * fun field.
      */
     ap = (StgAP_UPD *)allocate(AP_sizeW(words));
-    TICK_ALLOC_THK(words+1,0);
     
     ASSERT(words >= 0);
     
@@ -789,6 +794,7 @@ raiseAsync(StgTSO *tso, StgClosure *exception)
     case UPDATE_FRAME:
       {
        SET_HDR(ap,&AP_UPD_info,su->header.prof.ccs /* ToDo */); 
+       TICK_ALLOC_UP_THK(words+1,0);
        
        IF_DEBUG(scheduler,
                 fprintf(stderr,  "Updating ");
@@ -817,10 +823,11 @@ raiseAsync(StgTSO *tso, StgClosure *exception)
         * layout's the same.
         */
        SET_HDR(ap,&PAP_info,su->header.prof.ccs /* ToDo */);
+       TICK_ALLOC_UPD_PAP(words+1,0);
        
        /* now build o = FUN(catch,ap,handler) */
        o = (StgClosure *)allocate(sizeofW(StgClosure)+2);
-       TICK_ALLOC_THK(2,0);
+       TICK_ALLOC_FUN(2,0);
        SET_HDR(o,&catch_info,su->header.prof.ccs /* ToDo */);
        o->payload[0] = (StgClosure *)ap;
        o->payload[1] = cf->handler;
@@ -843,10 +850,11 @@ raiseAsync(StgTSO *tso, StgClosure *exception)
        StgClosure* o;
        
        SET_HDR(ap,&PAP_info,su->header.prof.ccs /* ToDo */);
+       TICK_ALLOC_UPD_PAP(words+1,0);
        
        /* now build o = FUN(seq,ap) */
        o = (StgClosure *)allocate(sizeofW(StgClosure)+1);
-       TICK_ALLOC_THK(1,0);
+       TICK_ALLOC_SE_THK(1,0);
        SET_HDR(o,&seq_info,su->header.prof.ccs /* ToDo */);
        payloadCPtr(o,0) = (StgClosure *)ap;