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