881e2b0b178691d33b5da19fb99c05a434bb8bc6
[ghc.git] / rts / sm / MarkStack.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team 1998-2009
4 *
5 * Operations on the mark stack
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_MARKSTACK_H
15 #define SM_MARKSTACK_H
16
17 #include "BeginPrivate.h"
18 #include "GCUtils.h"
19
20 INLINE_HEADER void
21 push_mark_stack(StgPtr p)
22 {
23 bdescr *bd;
24
25 *mark_sp++ = (StgWord)p;
26
27 if (((W_)mark_sp & BLOCK_MASK) == 0)
28 {
29 if (mark_stack_bd->u.back != NULL)
30 {
31 mark_stack_bd = mark_stack_bd->u.back;
32 }
33 else
34 {
35 bd = allocBlock_sync();
36 bd->link = mark_stack_bd;
37 bd->u.back = NULL;
38 mark_stack_bd->u.back = bd; // double-link the new block on
39 mark_stack_top_bd = bd;
40 mark_stack_bd = bd;
41 }
42 mark_sp = mark_stack_bd->start;
43 }
44 }
45
46 INLINE_HEADER StgPtr
47 pop_mark_stack(void)
48 {
49 if (((W_)mark_sp & BLOCK_MASK) == 0)
50 {
51 if (mark_stack_bd->link == NULL)
52 {
53 return NULL;
54 }
55 else
56 {
57 mark_stack_bd = mark_stack_bd->link;
58 mark_sp = mark_stack_bd->start + BLOCK_SIZE_W;
59 }
60 }
61 return (StgPtr)*--mark_sp;
62 }
63
64 INLINE_HEADER bool
65 mark_stack_empty(void)
66 {
67 return (((W_)mark_sp & BLOCK_MASK) == 0 && mark_stack_bd->link == NULL);
68 }
69
70 #include "EndPrivate.h"
71
72 #endif /* SM_MARKSTACK_H */