[Tizen] Unify dnetmemoryenumlib terms to match the codebase (#291)
[platform/upstream/coreclr.git] / src / vm / finalizerthread.h
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 // ===========================================================================
5
6 #ifndef _FINALIZER_THREAD_H_
7 #define _FINALIZER_THREAD_H_
8
9 class FinalizerThread
10 {
11     static BOOL fQuitFinalizer;
12
13 #if defined(__linux__) && defined(FEATURE_EVENT_TRACE)
14     static ULONGLONG LastHeapDumpTime;
15 #endif
16
17     static CLREvent *hEventFinalizer;
18     static CLREvent *hEventFinalizerDone;
19     static CLREvent *hEventFinalizerToShutDown;
20
21     // Note: This enum makes it easier to read much of the code that deals with the
22     // array of events that the finalizer thread waits on.  However, the ordering
23     // is important.
24     // See code:SVR::WaitForFinalizerEvent#MHandleTypeValues for more info
25     enum MHandleType
26     {
27         kLowMemoryNotification  = 0,
28         kFinalizer              = 1,
29         kHandleCount,
30     };
31
32     static HANDLE MHandles[kHandleCount];
33
34     static void WaitForFinalizerEvent (CLREvent *event);
35
36     static void DoOneFinalization(Object* fobj, Thread* pThread);
37
38     static void FinalizeAllObjects(int bitToCheck);
39
40 public:
41     static Thread* GetFinalizerThread() 
42     {
43         LIMITED_METHOD_CONTRACT;
44         _ASSERTE(g_pFinalizerThread != 0);
45         return g_pFinalizerThread;
46     }
47
48     static BOOL IsCurrentThreadFinalizer();
49
50     static void EnableFinalization();
51
52     static BOOL HaveExtraWorkForFinalizer();
53
54     static void RaiseShutdownEvents()
55     {
56         WRAPPER_NO_CONTRACT;
57         fQuitFinalizer = TRUE;
58         EnableFinalization();
59
60         // Do not wait for FinalizerThread if the current one is FinalizerThread.
61         if (GetThread() != GetFinalizerThread())
62         {
63             // This wait must be alertable to handle cases where the current
64             // thread's context is needed (i.e. RCW cleanup)
65             hEventFinalizerToShutDown->Wait(INFINITE, /*alertable*/ TRUE);
66         }
67     }
68
69     static void FinalizerThreadWait(DWORD timeout = INFINITE);
70
71     // We wake up a wait for finaliation for two reasons:
72     // if fFinalizer=TRUE, we have finished finalization.
73     // if fFinalizer=FALSE, the timeout for finalization is changed, and AD unload helper thread is notified.
74     static void SignalFinalizationDone(BOOL fFinalizer);
75
76     static VOID FinalizerThreadWorker(void *args);
77     static DWORD WINAPI FinalizerThreadStart(void *args);
78
79     static void FinalizerThreadCreate();
80 };
81
82 #endif // _FINALIZER_THREAD_H_