X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FWeak.c;h=ea52d906822bf0a4a35e19f70b920c56e3ff3994;hb=3ddfe34ba0b8b1c0721841c73d0c671e43a600ac;hp=8fe2575b08090534081eedff0b1ca39647198ac1;hpb=011886e400278f3654eefe542b5ea2a4fd7875f1;p=ghc-hetmet.git diff --git a/ghc/rts/Weak.c b/ghc/rts/Weak.c index 8fe2575..ea52d90 100644 --- a/ghc/rts/Weak.c +++ b/ghc/rts/Weak.c @@ -1,12 +1,15 @@ /* ----------------------------------------------------------------------------- - * $Id: Weak.c,v 1.6 1999/02/02 14:17:45 simonm Exp $ + * $Id: Weak.c,v 1.13 2000/02/25 17:35:11 sewardj Exp $ * - * Weak pointers / finalisers + * (c) The GHC Team, 1998-1999 + * + * Weak pointers / finalizers * * ---------------------------------------------------------------------------*/ #include "Rts.h" #include "RtsAPI.h" +#include "SchedAPI.h" #include "RtsFlags.h" #include "Weak.h" #include "Storage.h" @@ -14,59 +17,55 @@ StgWeak *weak_ptr_list; /* - * finaliseWeakPointersNow() is called just before the system is shut - * down. It runs the finaliser for each weak pointer still in the + * 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 -finaliseWeakPointersNow(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->finaliser != &NO_FINALISER_closure) { - rts_evalIO(w->finaliser,NULL); + if (w->finalizer != &NO_FINALIZER_closure) { + rts_evalIO(w->finalizer,NULL); } } } /* - * scheduleFinalisers() is called on the list of weak pointers found + * 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 finaliser. + * 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 -scheduleFinalisers(StgWeak *list) +scheduleFinalizers(StgWeak *list) { StgWeak *w; + StgTSO *t; for (w = list; w; w = w->link) { IF_DEBUG(weak,fprintf(stderr,"Finalising weak pointer at %p -> %p\n", w, w->key)); - if (w->finaliser != &NO_FINALISER_closure) { -#ifdef INTERPRETER - createGenThread(RtsFlags.GcFlags.initialStkSize, w->finaliser); -#else - createIOThread(RtsFlags.GcFlags.initialStkSize, w->finaliser); -#endif + if (w->finalizer != &NO_FINALIZER_closure) { + t = createIOThread(RtsFlags.GcFlags.initialStkSize, w->finalizer); + scheduleThread(t); } 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); - } -} -