mirror of https://github.com/PrimeDecomp/prime.git
Match and link CToken
This commit is contained in:
parent
8f29934c36
commit
ff40d50c8d
|
@ -624,7 +624,7 @@ LIBS = [
|
|||
["Kyoto/Streams/CZipInputStream", True],
|
||||
["Kyoto/Streams/CZipSupport", True],
|
||||
"Kyoto/CSimplePool",
|
||||
"Kyoto/CToken",
|
||||
["Kyoto/CToken", True],
|
||||
["Kyoto/IObj", True],
|
||||
],
|
||||
},
|
||||
|
|
|
@ -16,14 +16,20 @@ public:
|
|||
// , xc_objectStore(nullptr)
|
||||
// , x10_object(obj.release())
|
||||
// , x14_params(CVParamTransfer::Null()) {}
|
||||
|
||||
~CObjectReference();
|
||||
CObjectReference(IObjectStore* store, const rstl::auto_ptr< IObj >& obj, SObjectTag tag,
|
||||
CVParamTransfer xfer);
|
||||
|
||||
bool IsLoaded() const { return x10_object != nullptr; }
|
||||
|
||||
void AddReference() { x0_refCount++; }
|
||||
int RemoveReference();
|
||||
void Lock();
|
||||
void Unlock();
|
||||
IObj* GetObject();
|
||||
|
||||
private:
|
||||
ushort x0_refCount;
|
||||
short x0_refCount;
|
||||
bool x2_locked : 1;
|
||||
ushort x2_lockCount : 15;
|
||||
SObjectTag x4_objTag;
|
||||
|
|
|
@ -11,15 +11,18 @@ class CObjectReference;
|
|||
class CToken {
|
||||
public:
|
||||
CToken() {}
|
||||
CToken(CObjectReference* ref);
|
||||
CToken(IObj* obj); // : x0_objRef(new CObjectReference(obj)), x4_lockHeld(false) {}
|
||||
CToken(const CToken& other);
|
||||
~CToken();
|
||||
|
||||
CToken& operator=(const CToken&);
|
||||
|
||||
CObjOwnerDerivedFromIObjUntyped* GetObj();
|
||||
void Lock();
|
||||
void Unlock();
|
||||
bool IsLoaded() const { return x0_objRef->IsLoaded(); }
|
||||
void RemoveRef();
|
||||
CToken& operator=(const CToken&);
|
||||
|
||||
private:
|
||||
CObjectReference* x0_objRef;
|
||||
|
|
|
@ -563,7 +563,7 @@ KYOTO_1 :=\
|
|||
$(BUILD_DIR)/src/Kyoto/Streams/CZipInputStream.o\
|
||||
$(BUILD_DIR)/src/Kyoto/Streams/CZipSupport.o\
|
||||
$(BUILD_DIR)/asm/Kyoto/CSimplePool.o\
|
||||
$(BUILD_DIR)/asm/Kyoto/CToken.o\
|
||||
$(BUILD_DIR)/src/Kyoto/CToken.o\
|
||||
$(BUILD_DIR)/src/Kyoto/IObj.o\
|
||||
|
||||
ZLIB_FILES :=\
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
#include "Kyoto/CToken.hpp"
|
||||
#include "Kyoto/Alloc/CMemory.hpp"
|
||||
|
||||
CToken::CToken(CObjectReference* ref) : x0_objRef(ref), x4_lockHeld(false) {
|
||||
x0_objRef->AddReference();
|
||||
}
|
||||
|
||||
CToken::CToken(IObj* obj)
|
||||
: x0_objRef(new ("??(??)", nullptr) CObjectReference(obj)), x4_lockHeld(false) {
|
||||
x0_objRef->AddReference();
|
||||
Lock();
|
||||
}
|
||||
|
||||
CToken::CToken(const CToken& other) : x0_objRef(other.x0_objRef), x4_lockHeld(false) {
|
||||
x0_objRef->AddReference();
|
||||
if (other.x4_lockHeld) {
|
||||
Lock();
|
||||
}
|
||||
}
|
||||
|
||||
CToken::~CToken() {
|
||||
if (x4_lockHeld) {
|
||||
x0_objRef->Unlock();
|
||||
}
|
||||
RemoveRef();
|
||||
}
|
||||
|
||||
CObjOwnerDerivedFromIObjUntyped* CToken::GetObj() {
|
||||
Lock();
|
||||
|
||||
return reinterpret_cast< CObjOwnerDerivedFromIObjUntyped* >(x0_objRef->GetObject());
|
||||
}
|
||||
|
||||
void CToken::RemoveRef() {
|
||||
if (x0_objRef->RemoveReference() == 0) {
|
||||
delete x0_objRef;
|
||||
}
|
||||
}
|
||||
|
||||
void CToken::Lock() {
|
||||
if (!x4_lockHeld) {
|
||||
x0_objRef->Lock();
|
||||
x4_lockHeld = true;
|
||||
}
|
||||
}
|
||||
|
||||
void CToken::Unlock() {
|
||||
if (x4_lockHeld == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
x0_objRef->Unlock();
|
||||
x4_lockHeld = false;
|
||||
}
|
||||
|
||||
CToken& CToken::operator=(const CToken& other) {
|
||||
if (&other == const_cast< const CToken* >(this)) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Unlock();
|
||||
RemoveRef();
|
||||
x0_objRef = other.x0_objRef;
|
||||
x0_objRef->AddReference();
|
||||
if (other.x4_lockHeld) {
|
||||
Lock();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
Loading…
Reference in New Issue