1 /* -----------------------------------------------------------------------------
2 * $Id: Weak.c,v 1.6 1999/02/02 14:17:45 simonm Exp $
4 * Weak pointers / finalisers
6 * ---------------------------------------------------------------------------*/
14 StgWeak *weak_ptr_list;
17 * finaliseWeakPointersNow() is called just before the system is shut
18 * down. It runs the finaliser for each weak pointer still in the
23 finaliseWeakPointersNow(void)
27 for (w = weak_ptr_list; w; w = w->link) {
28 IF_DEBUG(weak,fprintf(stderr,"Finalising weak pointer at %p -> %p\n", w, w->key));
29 w->header.info = &DEAD_WEAK_info;
30 if (w->finaliser != &NO_FINALISER_closure) {
31 rts_evalIO(w->finaliser,NULL);
37 * scheduleFinalisers() is called on the list of weak pointers found
38 * to be dead after a garbage collection. It overwrites each object
39 * with DEAD_WEAK, and creates a new thread for the finaliser.
43 scheduleFinalisers(StgWeak *list)
47 for (w = list; w; w = w->link) {
48 IF_DEBUG(weak,fprintf(stderr,"Finalising weak pointer at %p -> %p\n", w, w->key));
49 if (w->finaliser != &NO_FINALISER_closure) {
51 createGenThread(RtsFlags.GcFlags.initialStkSize, w->finaliser);
53 createIOThread(RtsFlags.GcFlags.initialStkSize, w->finaliser);
56 w->header.info = &DEAD_WEAK_info;
65 last_w = &weak_ptr_list;
66 for (w = weak_ptr_list; w; w = w->link) {
67 w = (StgWeak *)MarkRoot((StgClosure *)w);