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