summaryrefslogtreecommitdiff
path: root/src/vm/threaddebugblockinginfo.cpp
blob: a77c69b457f447a4436863cfbffbe1bb6b66a95d (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
// ThreadDebugBlockingInfo.cpp
//

//
//
#include "common.h"
#include "threaddebugblockinginfo.h"

//Constructor
ThreadDebugBlockingInfo::ThreadDebugBlockingInfo()
{
    m_firstBlockingItem = NULL;
}

//Destructor
ThreadDebugBlockingInfo::~ThreadDebugBlockingInfo()
{
    WRAPPER_NO_CONTRACT;
    _ASSERTE(m_firstBlockingItem == NULL);
}

// Adds a new blocking item at the front of the list
// The caller is responsible for allocating the memory this points to and keeping it alive until
// after PopBlockingItem is called
#ifndef DACCESS_COMPILE
VOID ThreadDebugBlockingInfo::PushBlockingItem(DebugBlockingItem *pItem)
{
    LIMITED_METHOD_CONTRACT;

    _ASSERTE(pItem != NULL);
    pItem->pNext = m_firstBlockingItem;
    m_firstBlockingItem = pItem;
}
#endif //!DACCESS_COMPILE

// Removes the most recently added item (FIFO)
#ifndef DACCESS_COMPILE
VOID ThreadDebugBlockingInfo::PopBlockingItem()
{
    LIMITED_METHOD_CONTRACT;

    _ASSERTE(m_firstBlockingItem != NULL);
    m_firstBlockingItem = m_firstBlockingItem->pNext;
}
#endif //!DACCESS_COMPILE

// Calls the visitor function on each item in the stack from front to back
#ifdef DACCESS_COMPILE
VOID ThreadDebugBlockingInfo::VisitBlockingItems(DebugBlockingItemVisitor visitorFunc, VOID* pUserData)
{
    CONTRACTL
    {
        NOTHROW;
        GC_NOTRIGGER;
        MODE_ANY;
    }
    CONTRACTL_END;

    SUPPORTS_DAC;

    PTR_DebugBlockingItem pItem = m_firstBlockingItem;
    while(pItem != NULL)
    {
        visitorFunc(pItem, pUserData);
        pItem = pItem->pNext;
    }
}
#endif //DACCESS_COMPILE

// Holder constructor pushes a blocking item on the blocking info stack
#ifndef DACCESS_COMPILE
DebugBlockingItemHolder::DebugBlockingItemHolder(Thread *pThread, DebugBlockingItem *pItem) :
m_pThread(pThread)
{
    LIMITED_METHOD_CONTRACT;
    pThread->DebugBlockingInfo.PushBlockingItem(pItem);
}
#endif //DACCESS_COMPILE

// Holder destructor pops a blocking item off the blocking info stack
#ifndef DACCESS_COMPILE
DebugBlockingItemHolder::~DebugBlockingItemHolder()
{
    LIMITED_METHOD_CONTRACT;
    m_pThread->DebugBlockingInfo.PopBlockingItem();
}
#endif //DACCESS_COMPILE