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.
12 MethodTable * g_pFreeObjectMethodTable;
16 gc_alloc_context g_global_alloc_context;
18 bool CLREventStatic::CreateManualEventNoThrow(bool bInitialState)
20 m_hEvent = CreateEventW(NULL, TRUE, bInitialState, NULL);
21 m_fInitialized = true;
26 bool CLREventStatic::CreateAutoEventNoThrow(bool bInitialState)
28 m_hEvent = CreateEventW(NULL, FALSE, bInitialState, NULL);
29 m_fInitialized = true;
34 bool CLREventStatic::CreateOSManualEventNoThrow(bool bInitialState)
36 m_hEvent = CreateEventW(NULL, TRUE, bInitialState, NULL);
37 m_fInitialized = true;
42 bool CLREventStatic::CreateOSAutoEventNoThrow(bool bInitialState)
44 m_hEvent = CreateEventW(NULL, FALSE, bInitialState, NULL);
45 m_fInitialized = true;
50 void CLREventStatic::CloseEvent()
52 if (m_fInitialized && m_hEvent != INVALID_HANDLE_VALUE)
54 CloseHandle(m_hEvent);
55 m_hEvent = INVALID_HANDLE_VALUE;
59 bool CLREventStatic::IsValid() const
61 return m_fInitialized && m_hEvent != INVALID_HANDLE_VALUE;
64 bool CLREventStatic::Set()
68 return !!SetEvent(m_hEvent);
71 bool CLREventStatic::Reset()
75 return !!ResetEvent(m_hEvent);
78 uint32_t CLREventStatic::Wait(uint32_t dwMilliseconds, bool bAlertable)
80 DWORD result = WAIT_FAILED;
84 bool disablePreemptive = false;
85 Thread * pCurThread = GetThread();
87 if (NULL != pCurThread)
89 disablePreemptive = GCToEEInterface::EnablePreemptiveGC();
92 result = WaitForSingleObjectEx(m_hEvent, dwMilliseconds, bAlertable);
94 if (disablePreemptive)
96 GCToEEInterface::DisablePreemptiveGC();
103 __declspec(thread) Thread * pCurrentThread;
107 return pCurrentThread;
110 Thread * g_pThreadList = NULL;
112 Thread * ThreadStore::GetThreadList(Thread * pThread)
115 return g_pThreadList;
117 return pThread->m_pNext;
120 void ThreadStore::AttachCurrentThread()
124 Thread * pThread = new Thread();
125 pThread->GetAllocContext()->init();
126 pCurrentThread = pThread;
128 pThread->m_pNext = g_pThreadList;
129 g_pThreadList = pThread;
132 void GCToEEInterface::SuspendEE(SUSPEND_REASON reason)
134 g_theGCHeap->SetGCInProgress(true);
139 void GCToEEInterface::RestartEE(bool bFinishedGC)
143 g_theGCHeap->SetGCInProgress(false);
146 void GCToEEInterface::GcScanRoots(promote_func* fn, int condemned, int max_gen, ScanContext* sc)
148 // TODO: Implement - Scan stack roots on given thread
151 void GCToEEInterface::GcStartWork(int condemned, int max_gen)
155 void GCToEEInterface::AfterGcScanRoots(int condemned, int max_gen, ScanContext* sc)
159 void GCToEEInterface::GcBeforeBGCSweepWork()
163 void GCToEEInterface::GcDone(int condemned)
167 bool GCToEEInterface::RefCountedHandleCallbacks(Object * pObject)
172 bool GCToEEInterface::IsPreemptiveGCDisabled()
174 Thread* pThread = ::GetThread();
175 return pThread->PreemptiveGCDisabled();
178 bool GCToEEInterface::EnablePreemptiveGC()
180 bool bToggleGC = false;
181 Thread* pThread = ::GetThread();
185 bToggleGC = !!pThread->PreemptiveGCDisabled();
188 pThread->EnablePreemptiveGC();
195 void GCToEEInterface::DisablePreemptiveGC()
197 Thread* pThread = ::GetThread();
198 pThread->DisablePreemptiveGC();
201 Thread* GCToEEInterface::GetThread()
203 return ::GetThread();
206 gc_alloc_context * GCToEEInterface::GetAllocContext()
208 Thread* pThread = ::GetThread();
209 return pThread->GetAllocContext();
212 void GCToEEInterface::GcEnumAllocContexts (enum_alloc_context_func* fn, void* param)
214 Thread * pThread = NULL;
215 while ((pThread = ThreadStore::GetThreadList(pThread)) != NULL)
217 fn(pThread->GetAllocContext(), param);
221 void GCToEEInterface::SyncBlockCacheWeakPtrScan(HANDLESCANPROC /*scanProc*/, uintptr_t /*lp1*/, uintptr_t /*lp2*/)
225 void GCToEEInterface::SyncBlockCacheDemote(int /*max_gen*/)
229 void GCToEEInterface::SyncBlockCachePromotionsGranted(int /*max_gen*/)
233 void GCToEEInterface::DiagGCStart(int gen, bool isInduced)
237 void GCToEEInterface::DiagUpdateGenerationBounds()
241 void GCToEEInterface::DiagGCEnd(size_t index, int gen, int reason, bool fConcurrent)
245 void GCToEEInterface::DiagWalkFReachableObjects(void* gcContext)
249 void GCToEEInterface::DiagWalkSurvivors(void* gcContext)
253 void GCToEEInterface::DiagWalkLOHSurvivors(void* gcContext)
257 void GCToEEInterface::DiagWalkBGCSurvivors(void* gcContext)
261 void GCToEEInterface::StompWriteBarrier(WriteBarrierParameters* args)
265 void GCToEEInterface::EnableFinalization(bool foundFinalizers)
267 // Signal to finalizer thread that there are objects to finalize
268 // TODO: Implement for finalization
271 void GCToEEInterface::HandleFatalError(unsigned int exitCode)
276 bool GCToEEInterface::ShouldFinalizeObjectForUnload(AppDomain* pDomain, Object* obj)
281 bool GCToEEInterface::ForceFullGCToBeBlocking()
286 bool GCToEEInterface::EagerFinalized(Object* obj)
288 // The sample does not finalize anything eagerly.
292 bool GCToEEInterface::GetBooleanConfigValue(const char* key, bool* value)
297 bool GCToEEInterface::GetIntConfigValue(const char* key, int64_t* value)
302 bool GCToEEInterface::GetStringConfigValue(const char* key, const char** value)
307 void GCToEEInterface::FreeStringConfigValue(const char *value)
312 bool GCToEEInterface::IsGCThread()
317 bool GCToEEInterface::WasCurrentThreadCreatedByGC()
322 MethodTable* GCToEEInterface::GetFreeObjectMethodTable()
324 return g_pFreeObjectMethodTable;
327 bool GCToEEInterface::CreateThread(void (*threadStart)(void*), void* arg, bool is_suspendable, const char* name)
332 void GCToEEInterface::WalkAsyncPinnedForPromotion(Object* object, ScanContext* sc, promote_func* callback)
336 void GCToEEInterface::WalkAsyncPinned(Object* object, void* context, void (*callback)(Object*, Object*, void*))