[project @ 1999-03-17 16:25:07 by sewardj]
[ghc-hetmet.git] / ghc / rts / Weak.c
index 854fcf9..6032519 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Weak.c,v 1.8 1999/02/11 14:22:55 simonm Exp $
+ * $Id: Weak.c,v 1.10 1999/02/26 13:36:14 simonm Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
@@ -19,14 +19,19 @@ StgWeak *weak_ptr_list;
  * finalizeWeakPointersNow() is called just before the system is shut
  * down.  It runs the finalizer for each weak pointer still in the
  * system.
+ *
+ * Careful here - rts_evalIO might cause a garbage collection, which
+ * might change weak_ptr_list.  Must re-load weak_ptr_list each time
+ * around the loop.
  */
 
 void
 finalizeWeakPointersNow(void)
 {
   StgWeak *w;
-
-  for (w = weak_ptr_list; w; w = w->link) {
+  
+  while ((w = weak_ptr_list)) {
+    weak_ptr_list = w->link;
     IF_DEBUG(weak,fprintf(stderr,"Finalising weak pointer at %p -> %p\n", w, w->key));
     w->header.info = &DEAD_WEAK_info;
     if (w->finalizer != &NO_FINALIZER_closure) {
@@ -39,6 +44,13 @@ finalizeWeakPointersNow(void)
  * scheduleFinalizers() is called on the list of weak pointers found
  * to be dead after a garbage collection.  It overwrites each object
  * with DEAD_WEAK, and creates a new thread for the finalizer.
+ *
+ * This function is called just after GC.  The weak pointers on the
+ * argument list are those whose keys were found to be not reachable,
+ * however the value and finalizer fields have by now been marked live.
+ * The weak pointer object itself may not be alive - i.e. we may be
+ * looking at either an object in from-space or one in to-space.  It
+ * doesn't really matter either way.
  */
 
 void
@@ -58,17 +70,3 @@ scheduleFinalizers(StgWeak *list)
     w->header.info = &DEAD_WEAK_info;
   }
 }
-
-void
-markWeakList(void)
-{
-  StgWeak *w, **last_w;
-
-  last_w = &weak_ptr_list;
-  for (w = weak_ptr_list; w; w = w->link) {
-    w = (StgWeak *)MarkRoot((StgClosure *)w);
-    *last_w = w;
-    last_w = &(w->link);
-  }
-}
-