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