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