1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | // ThreadDebugBlockingInfo.h |
5 | // |
6 | |
7 | // |
8 | // |
9 | // Threads.h was getting so bloated that it seemed time to refactor a little. Rather than shove in yet another |
10 | // 50 lines of random definitions of things which happened to be per-thread I separated it out here. |
11 | #ifndef __ThreadBlockingInfo__ |
12 | #define __ThreadBlockingInfo__ |
13 | #include "mscoree.h" |
14 | |
15 | // Different ways thread can block that the debugger will expose |
16 | enum DebugBlockingItemType |
17 | { |
18 | DebugBlock_MonitorCriticalSection, |
19 | DebugBlock_MonitorEvent, |
20 | }; |
21 | |
22 | typedef DPTR(struct DebugBlockingItem) PTR_DebugBlockingItem; |
23 | |
24 | // Represents something a thread blocked on that is exposed via the debugger |
25 | struct DebugBlockingItem |
26 | { |
27 | // right now we only do monitor locks but this could be |
28 | // expanded to other pieces of data if we want to expose |
29 | // other things that we block on |
30 | PTR_AwareLock pMonitor; |
31 | // The app domain of the object we are blocking on |
32 | PTR_AppDomain pAppDomain; |
33 | // Indicates how the thread is blocked on the item |
34 | DebugBlockingItemType type; |
35 | // blocking timeout in milliseconds or INFINTE for no timeout |
36 | DWORD dwTimeout; |
37 | // next pointer for a linked list of these items |
38 | PTR_DebugBlockingItem pNext; |
39 | }; |
40 | |
41 | // A visitor function used when enumerating DebuggableBlockingItems |
42 | typedef VOID (*DebugBlockingItemVisitor)(PTR_DebugBlockingItem item, VOID* pUserData); |
43 | |
44 | // Maintains a stack of DebugBlockingItems that a thread is currently waiting on |
45 | // It is a stack rather than a single item because we wait interruptibly. During the interruptible |
46 | // wait we can run more code for an APC or to handle a windows message that could again block on another lock |
47 | class ThreadDebugBlockingInfo |
48 | { |
49 | private: |
50 | // head of the linked list which is our stack |
51 | PTR_DebugBlockingItem m_firstBlockingItem; |
52 | |
53 | public: |
54 | ThreadDebugBlockingInfo(); |
55 | ~ThreadDebugBlockingInfo(); |
56 | |
57 | #ifndef DACCESS_COMPILE |
58 | // Adds a new blocking item at the front of the list |
59 | VOID PushBlockingItem(DebugBlockingItem *pItem); |
60 | // Removes the most recently added item (FIFO) |
61 | VOID PopBlockingItem(); |
62 | #else |
63 | // Calls the visitor function on each item in the stack from front to back |
64 | VOID VisitBlockingItems(DebugBlockingItemVisitor vistorFunc, VOID* pUserData); |
65 | #endif //DACCESS_COMPILE |
66 | }; |
67 | |
68 | #ifndef DACCESS_COMPILE |
69 | class DebugBlockingItemHolder |
70 | { |
71 | private: |
72 | Thread *m_pThread; |
73 | |
74 | public: |
75 | DebugBlockingItemHolder(Thread *pThread, DebugBlockingItem *pItem); |
76 | ~DebugBlockingItemHolder(); |
77 | }; |
78 | #endif //!DACCESS_COMPILE |
79 | |
80 | #endif // __ThreadBlockingInfo__ |
81 | |