[project @ 1999-03-02 19:50:12 by sof]
[ghc-hetmet.git] / ghc / rts / Schedule.c
index d3af459..a5a2362 100644 (file)
@@ -1,5 +1,7 @@
 /* -----------------------------------------------------------------------------
- * $Id: Schedule.c,v 1.4 1999/01/13 17:25:44 simonm Exp $
+ * $Id: Schedule.c,v 1.12 1999/02/26 16:46:50 simonm Exp $
+ *
+ * (c) The GHC Team, 1998-1999
  *
  * Scheduler
  *
@@ -21,7 +23,6 @@
 #include "Printer.h"
 #include "Main.h"
 #include "Signals.h"
-#include "StablePtr.h"
 #include "Profiling.h"
 #include "Sanity.h"
 
@@ -92,6 +93,7 @@ createThread(nat stack_size)
   }
 
   tso = (StgTSO *)allocate(stack_size);
+  TICK_ALLOC_TSO(stack_size-sizeofW(StgTSO),0);
   
   initThread(tso, stack_size - TSO_STRUCT_SIZEW);
   return tso;
@@ -107,7 +109,8 @@ initThread(StgTSO *tso, nat stack_size)
 
   tso->splim        = (P_)&(tso->stack) + RESERVED_STACK_WORDS;
   tso->stack_size   = stack_size;
-  tso->max_stack_size = RtsFlags.GcFlags.maxStkSize - TSO_STRUCT_SIZEW;
+  tso->max_stack_size = round_to_mblocks(RtsFlags.GcFlags.maxStkSize) 
+                              - TSO_STRUCT_SIZEW;
   tso->sp           = (P_)&(tso->stack) + stack_size;
 
 #ifdef PROFILING
@@ -192,6 +195,7 @@ void deleteThread(StgTSO *tso)
       int words = (stgCast(StgPtr,su) - stgCast(StgPtr,sp)) - 1;
       nat i;
       StgAP_UPD* ap = stgCast(StgAP_UPD*,allocate(AP_sizeW(words)));
+      TICK_ALLOC_THK(words+1,0);
 
       /* First build an AP_UPD consisting of the stack chunk above the
        * current update frame, with the top word on the stack as the
@@ -245,6 +249,7 @@ void deleteThread(StgTSO *tso)
          
          /* now build o = FUN(catch,ap,handler) */
          o = stgCast(StgClosure*, allocate(sizeofW(StgClosure)+2));
+         TICK_ALLOC_THK(2,0);
          SET_HDR(o,&catch_info,su->header.prof.ccs /* ToDo */);
          payloadCPtr(o,0) = stgCast(StgClosure*,ap);
          payloadCPtr(o,1) = cf->handler;
@@ -270,6 +275,7 @@ void deleteThread(StgTSO *tso)
          
          /* now build o = FUN(seq,ap) */
           o = stgCast(StgClosure*, allocate(sizeofW(StgClosure)+1));
+         TICK_ALLOC_THK(1,0);
          SET_HDR(o,&seq_info,su->header.prof.ccs /* ToDo */);
          payloadCPtr(o,0) = stgCast(StgClosure*,ap);
          
@@ -396,7 +402,9 @@ SchedulerStatus schedule(StgTSO *main, StgClosure **ret_val)
     /* Be friendly to the storage manager: we're about to *run* this
      * thread, so we better make sure the TSO is mutable.
      */
-    recordMutable((StgMutClosure *)t);
+    if (t->mut_link == NULL) {
+      recordMutable((StgMutClosure *)t);
+    }
 
     /* Run the current thread */
     switch (t->whatNext) {
@@ -501,16 +509,17 @@ SchedulerStatus schedule(StgTSO *main, StgClosure **ret_val)
        * t->link is already set to END_TSO_QUEUE.
        */
       ASSERT(t->link == END_TSO_QUEUE);
-      if (run_queue_tl != END_TSO_QUEUE) {
+      if (run_queue_tl == END_TSO_QUEUE) {
+        run_queue_hd = run_queue_tl = t;
+      } else {
         ASSERT(get_itbl(run_queue_tl)->type == TSO);
        if (run_queue_hd == run_queue_tl) {
          run_queue_hd->link = t;
          run_queue_tl = t;
        } else {
          run_queue_tl->link = t;
+         run_queue_tl = t;
        }
-      } else {
-        run_queue_hd = run_queue_tl = t;
       }
       break;
 
@@ -603,8 +612,6 @@ static void GetRoots(void)
   for (i = 0; i < next_main_thread; i++) {
     main_threads[i] = (StgTSO *)MarkRoot((StgClosure *)main_threads[i]);
   }
-
-  markStablePtrTable();
 }
 
 /* -----------------------------------------------------------------------------
@@ -673,11 +680,13 @@ threadStackOverflow(StgTSO *tso)
   new_stack_size = stg_min(tso->stack_size * 2, tso->max_stack_size);
   new_tso_size   = (nat)BLOCK_ROUND_UP(new_stack_size * sizeof(W_) + 
                                       TSO_STRUCT_SIZE)/sizeof(W_);
+  new_tso_size = round_to_mblocks(new_tso_size);  /* Be MBLOCK-friendly */
   new_stack_size = new_tso_size - TSO_STRUCT_SIZEW;
 
   IF_DEBUG(scheduler, fprintf(stderr,"increasing stack size from %d words to %d.\n", tso->stack_size, new_stack_size));
 
   dest = (StgTSO *)allocate(new_tso_size);
+  TICK_ALLOC_TSO(new_tso_size-sizeofW(StgTSO),0);
 
   /* copy the TSO block and the old stack into the new area */
   memcpy(dest,tso,TSO_STRUCT_SIZE);