1 /* -----------------------------------------------------------------------------
2 * $Id: Weak.c,v 1.8 1999/02/11 14:22:55 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
25 finalizeWeakPointersNow(void)
29 for (w = weak_ptr_list; w; w = w->link) {
30 IF_DEBUG(weak,fprintf(stderr,"Finalising weak pointer at %p -> %p\n", w, w->key));
31 w->header.info = &DEAD_WEAK_info;
32 if (w->finalizer != &NO_FINALIZER_closure) {
33 rts_evalIO(w->finalizer,NULL);
39 * scheduleFinalizers() is called on the list of weak pointers found
40 * to be dead after a garbage collection. It overwrites each object
41 * with DEAD_WEAK, and creates a new thread for the finalizer.
45 scheduleFinalizers(StgWeak *list)
49 for (w = list; w; w = w->link) {
50 IF_DEBUG(weak,fprintf(stderr,"Finalising weak pointer at %p -> %p\n", w, w->key));
51 if (w->finalizer != &NO_FINALIZER_closure) {
53 createGenThread(RtsFlags.GcFlags.initialStkSize, w->finalizer);
55 createIOThread(RtsFlags.GcFlags.initialStkSize, w->finalizer);
58 w->header.info = &DEAD_WEAK_info;
67 last_w = &weak_ptr_list;
68 for (w = weak_ptr_list; w; w = w->link) {
69 w = (StgWeak *)MarkRoot((StgClosure *)w);