Match and link CToken

Former-commit-id: ff40d50c8d
This commit is contained in:
Phillip Stephens 2022-10-20 07:28:06 -07:00
parent 67d74916d4
commit 0488b6e955
5 changed files with 84 additions and 5 deletions

View File

@ -624,7 +624,7 @@ LIBS = [
["Kyoto/Streams/CZipInputStream", True],
["Kyoto/Streams/CZipSupport", True],
"Kyoto/CSimplePool",
"Kyoto/CToken",
["Kyoto/CToken", True],
["Kyoto/IObj", True],
],
},

View File

@ -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;

View File

@ -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;

View File

@ -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 :=\

70
src/Kyoto/CToken.cpp Normal file
View File

@ -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;
}