[project @ 2005-03-04 14:24:51 by simonmar]
[ghc-hetmet.git] / ghc / rts / Weak.c
index bc5cb2b..012acc9 100644 (file)
@@ -1,5 +1,4 @@
 /* -----------------------------------------------------------------------------
- * $Id: Weak.c,v 1.28 2003/03/17 14:47:48 simonmar Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
 #include "PosixSource.h"
 #define COMPILING_RTS_MAIN
 #include "Rts.h"
+#include "RtsUtils.h"
 #include "SchedAPI.h"
 #include "RtsFlags.h"
 #include "Weak.h"
 #include "Storage.h"
+#include "Schedule.h"
 #include "Prelude.h"
 #include "RtsAPI.h"
 
 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;
-  
-#if defined(RTS_SUPPORTS_THREADS)
-  rts_lock();
-#endif
-  while ((w = weak_ptr_list)) {
-    weak_ptr_list = w->link;
-    if (w->header.info != &stg_DEAD_WEAK_info) {
-       w->header.info = &stg_DEAD_WEAK_info;
-       IF_DEBUG(weak,fprintf(stderr,"Finalising weak pointer at %p -> %p\n", w, w->key));
-       if (w->finalizer != &stg_NO_FINALIZER_closure) {
-#if defined(RTS_SUPPORTS_THREADS)
-           rts_evalIO(w->finalizer,NULL);
-           rts_unlock();
-           rts_lock();
-#else
-           rts_mainLazyIO(w->finalizer,NULL);
-#endif
-       }
-    }
-  }
-#if defined(RTS_SUPPORTS_THREADS)
-  rts_unlock();
-#endif
-} 
-
-/*
  * 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 to run the pending finalizers.
@@ -108,7 +70,7 @@ scheduleFinalizers(StgWeak *list)
     // No finalizers to run?
     if (n == 0) return;
 
-    IF_DEBUG(weak,fprintf(stderr,"weak: batching %d finalizers\n", n));
+    IF_DEBUG(weak,debugBelch("weak: batching %d finalizers\n", n));
 
     arr = (StgMutArrPtrs *)allocate(sizeofW(StgMutArrPtrs) + n);
     TICK_ALLOC_PRIM(sizeofW(StgMutArrPtrs), n, 0);