Refactoring and tidy up
[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 #include "BeginPrivate.h"
18
19 #include "GCTDecl.h"
20
21 bdescr *allocBlock_sync(void);
22 void    freeChain_sync(bdescr *bd);
23
24 void    push_scanned_block   (bdescr *bd, gen_workspace *ws);
25 StgPtr  todo_block_full      (nat size, gen_workspace *ws);
26 StgPtr  alloc_todo_block     (gen_workspace *ws, nat size);
27
28 bdescr *grab_local_todo_block  (gen_workspace *ws);
29 #if defined(THREADED_RTS)
30 bdescr *steal_todo_block       (nat s);
31 #endif
32
33 // Returns true if a block is partially full.  This predicate is used to try
34 // to re-use partial blocks wherever possible, and to reduce wastage.
35 // We might need to tweak the actual value.
36 INLINE_HEADER rtsBool
37 isPartiallyFull(bdescr *bd)
38 {
39     return (bd->free + WORK_UNIT_WORDS < bd->start + BLOCK_SIZE_W);
40 }
41
42
43 #if DEBUG
44 void printMutableList (bdescr *bd);
45 #endif
46
47 // Version of recordMutableGen for use during GC.  This uses the
48 // mutable lists attached to the current gc_thread structure, which
49 // are the same as the mutable lists on the Capability.
50 INLINE_HEADER void
51 recordMutableGen_GC (StgClosure *p, nat gen_no)
52 {
53     bdescr *bd;
54
55     bd = gct->mut_lists[gen_no];
56     if (bd->free >= bd->start + BLOCK_SIZE_W) {
57         bdescr *new_bd;
58         new_bd = allocBlock_sync();
59         new_bd->link = bd;
60         bd = new_bd;
61         gct->mut_lists[gen_no] = bd;
62     }
63     *bd->free++ = (StgWord)p;
64 }
65
66 #include "EndPrivate.h"
67
68 #endif /* SM_GCUTILS_H */