少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
 
#include "gc/GCHandle.h"
#include "vm/CCWBase.h"
#include "vm/Exception.h"
#include "utils/TemplateUtils.h"
#include "utils/Memory.h"
 
namespace il2cpp
{
namespace vm
{
    template<typename TDerived>
    struct NOVTABLE NonCachedCCWBase : CCWBase
    {
    private:
        volatile uint32_t m_RefCount;
        uint32_t m_GCHandle;
 
    public:
        inline NonCachedCCWBase(Il2CppObject* obj) :
            CCWBase(obj),
            m_RefCount(1) // We start with a ref count of 1
        {
            m_GCHandle = gc::GCHandle::New(GetManagedObjectInline(), false);
            IL2CPP_ASSERT(m_GCHandle != 0);
            Il2CppStaticAssert(utils::TemplateUtils::IsBaseOf<NonCachedCCWBase<TDerived>, TDerived>::value);
        }
 
        inline ~NonCachedCCWBase()
        {
            IL2CPP_ASSERT(m_GCHandle != 0);
            gc::GCHandle::Free(m_GCHandle);
            m_GCHandle = 0;
        }
 
        IL2CPP_FORCE_INLINE uint32_t AddRefImpl()
        {
            return Atomic::Increment(&m_RefCount);
        }
 
        IL2CPP_FORCE_INLINE uint32_t ReleaseImpl()
        {
            const uint32_t count = Atomic::Decrement(&m_RefCount);
            if (count == 0)
                Destroy();
 
            return count;
        }
 
        IL2CPP_FORCE_INLINE static TDerived* __CreateInstance(Il2CppObject* obj)
        {
            void* memory = utils::Memory::Malloc(sizeof(TDerived));
            if (memory == NULL)
                Exception::RaiseOutOfMemoryException();
            return new(memory) TDerived(obj);
        }
 
        virtual void STDCALL Destroy() IL2CPP_FINAL IL2CPP_OVERRIDE
        {
            IL2CPP_ASSERT(m_RefCount == 0);
 
            TDerived* instance = static_cast<TDerived*>(this);
            instance->~TDerived();
            utils::Memory::Free(instance);
        }
    };
}
}