Use atomic operations to modify resource record refcount

* Scary that this has been broken for so long!
This commit is contained in:
baldurk
2016-01-17 12:03:31 +01:00
parent c94e2e60b7
commit 54a9c8bfd5
5 changed files with 16 additions and 5 deletions
+3 -3
View File
@@ -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);
+2 -2
View File
@@ -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;
+5
View File
@@ -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)
{
+1
View File
@@ -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);
+5
View File
@@ -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)
{