summaryrefslogtreecommitdiff
path: root/rts/sm/MarkStack.h
blob: 881e2b0b178691d33b5da19fb99c05a434bb8bc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* -----------------------------------------------------------------------------
 *
 * (c) The GHC Team 1998-2009
 *
 * Operations on the mark stack
 * 
 * Documentation on the architecture of the Garbage Collector can be
 * found in the online commentary:
 *
 *   http://ghc.haskell.org/trac/ghc/wiki/Commentary/Rts/Storage/GC
 *
 * ---------------------------------------------------------------------------*/

#ifndef SM_MARKSTACK_H
#define SM_MARKSTACK_H

#include "BeginPrivate.h"
#include "GCUtils.h"

INLINE_HEADER void
push_mark_stack(StgPtr p)
{
    bdescr *bd;

    *mark_sp++ = (StgWord)p;

    if (((W_)mark_sp & BLOCK_MASK) == 0)
    {
        if (mark_stack_bd->u.back != NULL)
        {
            mark_stack_bd = mark_stack_bd->u.back;
        }
        else
        {
            bd = allocBlock_sync();
            bd->link = mark_stack_bd;
            bd->u.back = NULL;
            mark_stack_bd->u.back = bd; // double-link the new block on
            mark_stack_top_bd = bd;
            mark_stack_bd = bd;
        }
        mark_sp     = mark_stack_bd->start;
    }
}

INLINE_HEADER StgPtr
pop_mark_stack(void)
{
    if (((W_)mark_sp & BLOCK_MASK) == 0)
    {
        if (mark_stack_bd->link == NULL)
        {
            return NULL;
        } 
        else
        {
            mark_stack_bd = mark_stack_bd->link;
            mark_sp       = mark_stack_bd->start + BLOCK_SIZE_W;
        }
    }
    return (StgPtr)*--mark_sp;
}

INLINE_HEADER bool
mark_stack_empty(void)
{
    return (((W_)mark_sp & BLOCK_MASK) == 0 && mark_stack_bd->link == NULL);
}

#include "EndPrivate.h"

#endif /* SM_MARKSTACK_H */