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.
8 #include "syncclean.hpp"
9 #include "virtualcallstub.h"
10 #include "threadsuspend.h"
12 VolatilePtr<Bucket> SyncClean::m_HashMap = NULL;
13 VolatilePtr<EEHashEntry*> SyncClean::m_EEHashTable;
15 void SyncClean::Terminate()
25 void SyncClean::AddHashMap (Bucket *bucket)
34 BEGIN_GETTHREAD_ALLOWED
35 _ASSERTE (GetThread() == NULL || GetThread()->PreemptiveGCDisabled());
38 Bucket * pTempBucket = NULL;
41 pTempBucket = (Bucket *)m_HashMap;
42 NextObsolete (bucket) = pTempBucket;
44 while (FastInterlockCompareExchangePointer(m_HashMap.GetPointer(), bucket, pTempBucket) != pTempBucket);
47 void SyncClean::AddEEHashTable (EEHashEntry** entry)
56 BEGIN_GETTHREAD_ALLOWED
57 _ASSERTE (GetThread() == NULL || GetThread()->PreemptiveGCDisabled());
60 EEHashEntry ** pTempHashEntry = NULL;
63 pTempHashEntry = (EEHashEntry**)m_EEHashTable;
64 entry[-1] = (EEHashEntry *)pTempHashEntry;
66 while (FastInterlockCompareExchangePointer(m_EEHashTable.GetPointer(), entry, pTempHashEntry) != pTempHashEntry);
69 void SyncClean::CleanUp ()
71 LIMITED_METHOD_CONTRACT;
73 // Only GC thread can call this.
74 _ASSERTE (g_fProcessDetach ||
75 IsGCSpecialThread() ||
76 (GCHeapUtilities::IsGCInProgress() && GetThread() == ThreadSuspend::GetSuspensionThread()));
79 Bucket * pTempBucket = FastInterlockExchangePointer(m_HashMap.GetPointer(), NULL);
83 Bucket* pNextBucket = NextObsolete (pTempBucket);
84 delete [] pTempBucket;
85 pTempBucket = pNextBucket;
91 EEHashEntry ** pTempHashEntry = FastInterlockExchangePointer(m_EEHashTable.GetPointer(), NULL);
93 while (pTempHashEntry) {
94 EEHashEntry **pNextHashEntry = (EEHashEntry **)pTempHashEntry[-1];
96 delete [] pTempHashEntry;
97 pTempHashEntry = pNextHashEntry;
101 // Give others we want to reclaim during the GC sync point a chance to do it
102 VirtualCallStubManager::ReclaimAll();