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// ============================================================
5//
6// LoadContext.inl
7//
8
9
10//
11// Implements the inlined methods of LoadContext template class
12//
13// ============================================================
14
15#ifndef __BINDER__LOAD_CONTEXT_INL__
16#define __BINDER__LOAD_CONTEXT_INL__
17
18template <DWORD dwIncludeFlags>
19LoadContext<dwIncludeFlags>::LoadContext() :
20 SHash<AssemblyHashTraits<ContextEntry *, dwIncludeFlags> >::SHash()
21{
22 m_cRef = 1;
23}
24
25template <DWORD dwIncludeFlags>
26LoadContext<dwIncludeFlags>::~LoadContext()
27{
28 // Delete context entries and contents array
29 for (typename Hash::Iterator i = Hash::Begin(), end = Hash::End(); i != end; i++)
30 {
31 const ContextEntry *pContextEntry = *i;
32 delete pContextEntry;
33 }
34 this->RemoveAll();
35}
36
37template <DWORD dwIncludeFlags>
38ULONG LoadContext<dwIncludeFlags>::AddRef()
39{
40 return InterlockedIncrement(&m_cRef);
41}
42
43template <DWORD dwIncludeFlags>
44ULONG LoadContext<dwIncludeFlags>::Release()
45{
46 ULONG ulRef = InterlockedDecrement(&m_cRef);
47
48 if (ulRef == 0)
49 {
50 delete this;
51 }
52
53 return ulRef;
54}
55
56template <DWORD dwIncludeFlags>
57ContextEntry *LoadContext<dwIncludeFlags>::Lookup(AssemblyName *pAssemblyName)
58{
59 ContextEntry *pContextEntry =
60 SHash<AssemblyHashTraits<ContextEntry *, dwIncludeFlags> >::Lookup(pAssemblyName);
61
62 return pContextEntry;
63}
64
65template <DWORD dwIncludeFlags>
66HRESULT LoadContext<dwIncludeFlags>::Register(BindResult *pBindResult)
67{
68 HRESULT hr = S_OK;
69 ContextEntry *pContextEntry = NULL;
70
71 SAFE_NEW(pContextEntry, ContextEntry);
72
73 pContextEntry->SetIsDynamicBind(pBindResult->GetIsDynamicBind());
74 pContextEntry->SetIsInGAC(pBindResult->GetIsInGAC());
75 pContextEntry->SetIsSharable(pBindResult->GetIsSharable());
76 pContextEntry->SetAssemblyName(pBindResult->GetAssemblyName(), TRUE /* fAddRef */);
77 pContextEntry->SetAssembly(pBindResult->GetAssembly());
78
79 if (pBindResult->GetIsFirstRequest())
80 {
81 pContextEntry->SetIsFirstRequest(TRUE);
82 }
83
84 SHash<AssemblyHashTraits<ContextEntry *, dwIncludeFlags> >::Add(pContextEntry);
85
86 Exit:
87 return hr;
88}
89
90#endif
91