RTS tidyup sweep, first phase
[ghc-hetmet.git] / rts / sm / GCUtils.h
1 /* ----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team 1998-2008
4  *
5  * Generational garbage collector: utilities
6  *
7  * Documentation on the architecture of the Garbage Collector can be
8  * found in the online commentary:
9  * 
10  *   http://hackage.haskell.org/trac/ghc/wiki/Commentary/Rts/Storage/GC
11  *
12  * --------------------------------------------------------------------------*/
13
14 #ifndef SM_GCUTILS_H
15 #define SM_GCUTILS_H
16
17 bdescr *allocBlock_sync(void);
18 void    freeChain_sync(bdescr *bd);
19
20 void    push_scanned_block   (bdescr *bd, step_workspace *ws);
21 StgPtr  todo_block_full      (nat size, step_workspace *ws);
22 StgPtr  alloc_todo_block     (step_workspace *ws, nat size);
23
24 bdescr *grab_local_todo_block  (step_workspace *ws);
25 #if defined(THREADED_RTS)
26 bdescr *steal_todo_block       (nat s);
27 #endif
28
29 // Returns true if a block is partially full.  This predicate is used to try
30 // to re-use partial blocks wherever possible, and to reduce wastage.
31 // We might need to tweak the actual value.
32 INLINE_HEADER rtsBool
33 isPartiallyFull(bdescr *bd)
34 {
35     return (bd->free + WORK_UNIT_WORDS < bd->start + BLOCK_SIZE_W);
36 }
37
38
39 #if DEBUG
40 void printMutableList (generation *gen);
41 #endif
42
43 // Version of recordMutableGen for use during GC.  This uses the
44 // mutable lists attached to the current gc_thread structure, which
45 // are the same as the mutable lists on the Capability.
46 INLINE_HEADER void
47 recordMutableGen_GC (StgClosure *p, nat gen_no)
48 {
49     bdescr *bd;
50
51     bd = gct->mut_lists[gen_no];
52     if (bd->free >= bd->start + BLOCK_SIZE_W) {
53         bdescr *new_bd;
54         new_bd = allocBlock_sync();
55         new_bd->link = bd;
56         bd = new_bd;
57         gct->mut_lists[gen_no] = bd;
58     }
59     *bd->free++ = (StgWord)p;
60 }
61
62 #endif /* SM_GCUTILS_H */