mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 11:19:10 +00:00
Merge pnUtRef with hsRefCnt, and remove the former
This commit is contained in:
@ -65,21 +65,48 @@ void hsRefCnt::UnRef()
|
||||
--fRefCnt;
|
||||
}
|
||||
|
||||
hsSafeRefCnt::~hsSafeRefCnt()
|
||||
hsAtomicRefCnt::~hsAtomicRefCnt()
|
||||
{
|
||||
#ifdef HS_DEBUGGING
|
||||
hsThrowIfFalse(fRefCnt == 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
void hsSafeRefCnt::UnRef()
|
||||
void hsAtomicRefCnt::UnRef(const char* tag)
|
||||
{
|
||||
#ifdef HS_DEBUGGING
|
||||
hsThrowIfFalse(fRefCnt >= 1);
|
||||
#endif
|
||||
|
||||
#ifdef REFCOUNT_DEBUGGING
|
||||
if (tag)
|
||||
DEBUG_MSG("Dec %p %s: %u", this, tag, prev - 1);
|
||||
else
|
||||
DEBUG_MSG("Dec %p: %u", this, prev - 1);
|
||||
#endif
|
||||
|
||||
if (fRefCnt == 1) // don't decrement if we call delete
|
||||
delete this;
|
||||
else
|
||||
--fRefCnt;
|
||||
}
|
||||
|
||||
void hsAtomicRefCnt::Ref(const char* tag)
|
||||
{
|
||||
#ifdef REFCOUNT_DEBUGGING
|
||||
if (tag)
|
||||
DEBUG_MSG("Inc %p %s: %u", this, tag, prev + 1);
|
||||
else
|
||||
DEBUG_MSG("Inc %p: %u", this, prev + 1);
|
||||
#endif
|
||||
|
||||
++fRefCnt;
|
||||
}
|
||||
|
||||
void hsAtomicRefCnt::TransferRef(const char* oldTag, const char* newTag)
|
||||
{
|
||||
#ifdef REFCOUNT_DEBUGGING
|
||||
DEBUG_MSG("Inc %p %s: (xfer)", this, newTag);
|
||||
DEBUG_MSG("Dec %p %s: (xfer)", this, oldTag);
|
||||
#endif
|
||||
}
|
||||
|
@ -69,18 +69,21 @@ public:
|
||||
|
||||
// Thread-safe version. TODO: Evaluate whether this is fast enough to
|
||||
// merge with hsRefCnt above.
|
||||
class hsSafeRefCnt
|
||||
class hsAtomicRefCnt
|
||||
{
|
||||
private:
|
||||
std::atomic<int> fRefCnt;
|
||||
|
||||
public:
|
||||
hsSafeRefCnt() : fRefCnt(1) { }
|
||||
virtual ~hsSafeRefCnt();
|
||||
hsAtomicRefCnt() : fRefCnt(1) { }
|
||||
virtual ~hsAtomicRefCnt();
|
||||
|
||||
inline int RefCnt() const { return fRefCnt; }
|
||||
void UnRef();
|
||||
inline void Ref() { ++fRefCnt; }
|
||||
void UnRef(const char* tag = nullptr);
|
||||
void Ref(const char* tag = nullptr);
|
||||
|
||||
// Useless, but left here for debugging compatibility with AtomicRef
|
||||
void TransferRef(const char* oldTag, const char* newTag);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user