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 // ===========================================================================
6 #ifndef _FINALIZER_THREAD_H_
7 #define _FINALIZER_THREAD_H_
11 static BOOL fQuitFinalizer;
13 #if defined(__linux__) && defined(FEATURE_EVENT_TRACE)
14 static ULONGLONG LastHeapDumpTime;
17 static CLREvent *hEventFinalizer;
18 static CLREvent *hEventFinalizerDone;
19 static CLREvent *hEventFinalizerToShutDown;
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
24 // See code:SVR::WaitForFinalizerEvent#MHandleTypeValues for more info
27 kLowMemoryNotification = 0,
32 static HANDLE MHandles[kHandleCount];
34 static void WaitForFinalizerEvent (CLREvent *event);
36 static void DoOneFinalization(Object* fobj, Thread* pThread);
38 static void FinalizeAllObjects(int bitToCheck);
41 static Thread* GetFinalizerThread()
43 LIMITED_METHOD_CONTRACT;
44 _ASSERTE(g_pFinalizerThread != 0);
45 return g_pFinalizerThread;
48 static BOOL IsCurrentThreadFinalizer();
50 static void EnableFinalization();
52 static BOOL HaveExtraWorkForFinalizer();
54 static void RaiseShutdownEvents()
57 fQuitFinalizer = TRUE;
60 // Do not wait for FinalizerThread if the current one is FinalizerThread.
61 if (GetThread() != GetFinalizerThread())
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);
69 static void FinalizerThreadWait(DWORD timeout = INFINITE);
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);
76 static VOID FinalizerThreadWorker(void *args);
77 static DWORD WINAPI FinalizerThreadStart(void *args);
79 static void FinalizerThreadCreate();
82 #endif // _FINALIZER_THREAD_H_