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 /*============================================================
10 ** Header: RCWRefCache.h
13 ** Purpose: Defines RCWRefCache class
14 ** This class maintains per-AppDomain cache that can be used
15 ** by RCW to reference other CCWs
16 ===========================================================*/
18 #ifndef _H_RCWREFCACHE_
19 #define _H_RCWREFCACHE_
21 #ifdef FEATURE_COMINTEROP
26 RCWRefCache(AppDomain *pAppDomain);
30 // Add a reference from RCW to CCW
32 HRESULT AddReferenceFromRCWToCCW(RCW *pRCW, ComCallWrapper *pCCW);
35 // Enumerate all Jupiter RCWs in the RCW cache and do the callback
36 // I'm using template here so there is no perf penality
38 template<class Function, class T> HRESULT EnumerateAllJupiterRCWs(Function fn, T userData)
50 // Go through the RCW cache and call the callback for all Jupiter objects
51 RCWCache *pRCWCache = m_pAppDomain->GetRCWCacheNoCreate();
52 if (pRCWCache != NULL)
54 SHash<RCWCache::RCWCacheTraits> *pHashMap = &pRCWCache->m_HashMap;
56 for (SHash<RCWCache::RCWCacheTraits>::Iterator it = pHashMap->Begin(); it != pHashMap->End(); it++)
59 _ASSERTE(pRCW != NULL);
61 if (pRCW->IsJupiterObject())
63 hr = fn(pRCW, userData);
76 // Reset dependent handle cache by assigning 0 to m_dwDepHndListFreeIndex.
78 void ResetDependentHandles();
81 // Shrink the dependent handle cache if necessary (will destroy handles) and clear unused handles.
83 void ShrinkDependentHandles();
87 // Add RCW -> CCW reference using dependent handle
90 HRESULT AddReferenceUsingDependentHandle(RCW *pRCW, ComCallWrapper *pCCW);
93 AppDomain *m_pAppDomain; // Domain
95 CQuickArrayList<OBJECTHANDLE> m_depHndList; // Internal DependentHandle cache
96 // non-NULL dependent handles followed by NULL slots
97 DWORD m_dwDepHndListFreeIndex; // The starting index where m_depHndList has available slots
98 DWORD m_dwShrinkHint; // Keep track of how many times we use less than half handles
101 #endif // FEATURE_COMINTEROP
103 #endif // _H_RCWREFCACHE_