From ef1e2ab328087c61a6878c1e84f4fc5d710aebce Mon Sep 17 00:00:00 2001 From: dotnet-bot Date: Fri, 30 Jan 2015 14:14:42 -0800 Subject: Initial commit to populate CoreCLR repo [tfs-changeset: 1407945] --- src/vm/rcwrefcache.h | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/vm/rcwrefcache.h (limited to 'src/vm/rcwrefcache.h') diff --git a/src/vm/rcwrefcache.h b/src/vm/rcwrefcache.h new file mode 100644 index 0000000000..ca79f86388 --- /dev/null +++ b/src/vm/rcwrefcache.h @@ -0,0 +1,104 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// +// + +// + +/*============================================================ +** +** Header: RCWRefCache.h +** +** +** Purpose: Defines RCWRefCache class +** This class maintains per-AppDomain cache that can be used +** by RCW to reference other CCWs +===========================================================*/ + +#ifndef _H_RCWREFCACHE_ +#define _H_RCWREFCACHE_ + +#ifdef FEATURE_COMINTEROP + +class RCWRefCache +{ +public : + RCWRefCache(AppDomain *pAppDomain); + ~RCWRefCache(); + + // + // Add a reference from RCW to CCW + // + HRESULT AddReferenceFromRCWToCCW(RCW *pRCW, ComCallWrapper *pCCW); + + // + // Enumerate all Jupiter RCWs in the RCW cache and do the callback + // I'm using template here so there is no perf penality + // + template HRESULT EnumerateAllJupiterRCWs(Function fn, T userData) + { + CONTRACTL + { + NOTHROW; + GC_NOTRIGGER; + MODE_COOPERATIVE; + } + CONTRACTL_END; + + HRESULT hr; + + // Go through the RCW cache and call the callback for all Jupiter objects + RCWCache *pRCWCache = m_pAppDomain->GetRCWCacheNoCreate(); + if (pRCWCache != NULL) + { + SHash *pHashMap = &pRCWCache->m_HashMap; + + for (SHash::Iterator it = pHashMap->Begin(); it != pHashMap->End(); it++) + { + RCW *pRCW = *it; + _ASSERTE(pRCW != NULL); + + if (pRCW->IsJupiterObject()) + { + hr = fn(pRCW, userData); + if (FAILED(hr)) + { + return hr; + } + } + } + } + + return S_OK; + } + + // + // Reset dependent handle cache by assigning 0 to m_dwDepHndListFreeIndex. + // + void ResetDependentHandles(); + + // + // Shrink the dependent handle cache if necessary (will destroy handles) and clear unused handles. + // + void ShrinkDependentHandles(); + +private : + // + // Add RCW -> CCW reference using dependent handle + // May fail if OOM + // + HRESULT AddReferenceUsingDependentHandle(RCW *pRCW, ComCallWrapper *pCCW); + +private : + AppDomain *m_pAppDomain; // Domain + + CQuickArrayList m_depHndList; // Internal DependentHandle cache + // non-NULL dependent handles followed by NULL slots + DWORD m_dwDepHndListFreeIndex; // The starting index where m_depHndList has available slots + DWORD m_dwShrinkHint; // Keep track of how many times we use less than half handles +}; + +#endif // FEATURE_COMINTEROP + +#endif // _H_RCWREFCACHE_ -- cgit v1.2.3