mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-28 04:41:07 +00:00
Use atomic operations to modify resource record refcount
* Scary that this has been broken for so long!
This commit is contained in:
@@ -63,9 +63,9 @@ void ResourceRecord::AddResourceReferences(ResourceRecordHandler *mgr)
|
||||
|
||||
void ResourceRecord::Delete(ResourceRecordHandler *mgr)
|
||||
{
|
||||
RefCount--;
|
||||
RDCASSERT(RefCount >= 0);
|
||||
if(RefCount <= 0)
|
||||
int32_t ref = Atomic::Dec32(&RefCount);
|
||||
RDCASSERT(ref >= 0);
|
||||
if(ref <= 0)
|
||||
{
|
||||
for(auto it = Parents.begin(); it != Parents.end(); ++it)
|
||||
(*it)->Delete(mgr);
|
||||
|
||||
@@ -156,7 +156,7 @@ struct ResourceRecord
|
||||
recordlist.insert(m_Chunks.begin(), m_Chunks.end());
|
||||
}
|
||||
|
||||
void AddRef() { RefCount++; }
|
||||
void AddRef() { Atomic::Inc32(&RefCount); }
|
||||
int GetRefCount() const { return RefCount; }
|
||||
void Delete(ResourceRecordHandler *mgr);
|
||||
|
||||
@@ -269,7 +269,7 @@ struct ResourceRecord
|
||||
bool DataWritten;
|
||||
|
||||
protected:
|
||||
int RefCount;
|
||||
volatile int32_t RefCount;
|
||||
|
||||
byte *DataPtr;
|
||||
uint64_t DataOffset;
|
||||
|
||||
@@ -52,6 +52,11 @@ namespace Atomic
|
||||
{
|
||||
return __sync_add_and_fetch(i, int32_t(1));
|
||||
}
|
||||
|
||||
int32_t Dec32(volatile int32_t *i)
|
||||
{
|
||||
return __sync_add_and_fetch(i, int32_t(-1));
|
||||
}
|
||||
|
||||
int64_t Inc64(volatile int64_t *i)
|
||||
{
|
||||
|
||||
@@ -166,6 +166,7 @@ namespace Network
|
||||
namespace Atomic
|
||||
{
|
||||
int32_t Inc32(volatile int32_t *i);
|
||||
int32_t Dec32(volatile int32_t *i);
|
||||
int64_t Inc64(volatile int64_t *i);
|
||||
int64_t Dec64(volatile int64_t *i);
|
||||
int64_t ExchAdd64(volatile int64_t *i, int64_t a);
|
||||
|
||||
@@ -54,6 +54,11 @@ namespace Atomic
|
||||
{
|
||||
return (int32_t)InterlockedIncrement((volatile LONG *)i);
|
||||
}
|
||||
|
||||
int32_t Dec32(volatile int32_t *i)
|
||||
{
|
||||
return (int32_t)InterlockedDecrement((volatile LONG *)i);
|
||||
}
|
||||
|
||||
int64_t Inc64(volatile int64_t *i)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user