1 /* -----------------------------------------------------------------------------
2 * $Id: Weak.c,v 1.3 1999/01/13 17:25:49 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\n", w));
29 w->header.info = &DEAD_WEAK_info;
30 rts_evalIO(w->finaliser,NULL);
35 * scheduleFinalisers() is called on the list of weak pointers found
36 * to be dead after a garbage collection. It overwrites each object
37 * with DEAD_WEAK, and creates a new thread for the finaliser.
41 scheduleFinalisers(StgWeak *list)
45 for (w = list; w; w = w->link) {
46 IF_DEBUG(weak,fprintf(stderr,"Finalising weak pointer at %p\n", w));
48 createGenThread(RtsFlags.GcFlags.initialStkSize, w->finaliser);
50 createIOThread(RtsFlags.GcFlags.initialStkSize, w->finaliser);
52 w->header.info = &DEAD_WEAK_info;
54 /* need to fill the slop with zeros if we're sanity checking */
56 nat dw_size = sizeW_fromITBL(get_itbl(w));
57 memset((P_)w + dw_size, 0, (sizeofW(StgWeak) - dw_size) * sizeof(W_));
67 last_w = &weak_ptr_list;
68 for (w = weak_ptr_list; w; w = w->link) {
69 w = (StgWeak *)MarkRoot((StgClosure *)w);