1 /* -----------------------------------------------------------------------------
2 * $Id: Weak.c,v 1.10 1999/02/26 13:36:14 simonm Exp $
4 * (c) The GHC Team, 1998-1999
6 * Weak pointers / finalizers
8 * ---------------------------------------------------------------------------*/
16 StgWeak *weak_ptr_list;
19 * finalizeWeakPointersNow() is called just before the system is shut
20 * down. It runs the finalizer for each weak pointer still in the
23 * Careful here - rts_evalIO might cause a garbage collection, which
24 * might change weak_ptr_list. Must re-load weak_ptr_list each time
29 finalizeWeakPointersNow(void)
33 while ((w = weak_ptr_list)) {
34 weak_ptr_list = w->link;
35 IF_DEBUG(weak,fprintf(stderr,"Finalising weak pointer at %p -> %p\n", w, w->key));
36 w->header.info = &DEAD_WEAK_info;
37 if (w->finalizer != &NO_FINALIZER_closure) {
38 rts_evalIO(w->finalizer,NULL);
44 * scheduleFinalizers() is called on the list of weak pointers found
45 * to be dead after a garbage collection. It overwrites each object
46 * with DEAD_WEAK, and creates a new thread for the finalizer.
48 * This function is called just after GC. The weak pointers on the
49 * argument list are those whose keys were found to be not reachable,
50 * however the value and finalizer fields have by now been marked live.
51 * The weak pointer object itself may not be alive - i.e. we may be
52 * looking at either an object in from-space or one in to-space. It
53 * doesn't really matter either way.
57 scheduleFinalizers(StgWeak *list)
61 for (w = list; w; w = w->link) {
62 IF_DEBUG(weak,fprintf(stderr,"Finalising weak pointer at %p -> %p\n", w, w->key));
63 if (w->finalizer != &NO_FINALIZER_closure) {
65 createGenThread(RtsFlags.GcFlags.initialStkSize, w->finalizer);
67 createIOThread(RtsFlags.GcFlags.initialStkSize, w->finalizer);
70 w->header.info = &DEAD_WEAK_info;