[redcode/crythread-2nd-pass] replaced remaining CryInterlocked* usage with equivalent AZStd version
Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com>
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <AzCore/std/parallel/atomic.h>
|
||||
|
||||
// Base class for functor storage.
|
||||
// Not intended for direct usage.
|
||||
class IFunctorBase
|
||||
@@ -27,19 +29,19 @@ public:
|
||||
|
||||
void AddRef()
|
||||
{
|
||||
CryInterlockedIncrement(&m_nReferences);
|
||||
m_nReferences.fetch_add(1, AZStd::memory_order_acq_rel);
|
||||
}
|
||||
|
||||
void Release()
|
||||
{
|
||||
if (CryInterlockedDecrement(&m_nReferences) <= 0)
|
||||
if (m_nReferences.fetch_sub(1, AZStd::memory_order_acq_rel) == 1)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
volatile int m_nReferences;
|
||||
AZStd::atomic_int m_nReferences;
|
||||
};
|
||||
|
||||
// Base Template for specialization.
|
||||
|
||||
@@ -18,6 +18,9 @@ void CryFatalError(const char*, ...) PRINTF_PARAMS(1, 2);
|
||||
#if defined(APPLE)
|
||||
#include <cstddef>
|
||||
#endif
|
||||
|
||||
#include <AzCore/std/parallel/atomic.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// SMART POINTER
|
||||
//////////////////////////////////////////////////////////////////
|
||||
@@ -352,38 +355,32 @@ protected:
|
||||
class CMultiThreadRefCount
|
||||
{
|
||||
public:
|
||||
CMultiThreadRefCount()
|
||||
: m_cnt(0) {}
|
||||
CMultiThreadRefCount() {}
|
||||
virtual ~CMultiThreadRefCount() {}
|
||||
|
||||
inline int AddRef()
|
||||
{
|
||||
return CryInterlockedIncrement(&m_cnt);
|
||||
return m_count.fetch_add(1, AZStd::memory_order_acq_rel) + 1; // because we get the original value back
|
||||
}
|
||||
inline int Release()
|
||||
{
|
||||
const int nCount = CryInterlockedDecrement(&m_cnt);
|
||||
assert(nCount >= 0);
|
||||
const int nCount = m_count.fetch_sub(1, AZStd::memory_order_acq_rel) - 1; // because we get the original value back
|
||||
AZ_Assert(nCount >= 0, "Deleting Reference Counted Object Twice");
|
||||
if (nCount == 0)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
else if (nCount < 0)
|
||||
{
|
||||
assert(0);
|
||||
CryFatalError("Deleting Reference Counted Object Twice");
|
||||
}
|
||||
return nCount;
|
||||
}
|
||||
|
||||
inline int GetRefCount() const { return m_cnt; }
|
||||
inline int GetRefCount() const { return m_count.load(AZStd::memory_order_acquire); }
|
||||
|
||||
protected:
|
||||
// Allows the memory for the object to be deallocated in the dynamic module where it was originally constructed, as it may use different memory manager (Debug/Release configurations)
|
||||
virtual void DeleteThis() { delete this; }
|
||||
|
||||
private:
|
||||
volatile int m_cnt;
|
||||
AZStd::atomic_int m_count{ 0 };
|
||||
};
|
||||
|
||||
// base class for interfaces implementing reference counting that needs to be thread-safe
|
||||
@@ -404,29 +401,24 @@ public:
|
||||
|
||||
virtual void AddRef()
|
||||
{
|
||||
CryInterlockedIncrement(&m_nRefCounter);
|
||||
m_nRefCounter.fetch_add(1, AZStd::memory_order_acq_rel);
|
||||
}
|
||||
|
||||
virtual void Release()
|
||||
{
|
||||
const int nCount = CryInterlockedDecrement(&m_nRefCounter);
|
||||
assert(nCount >= 0);
|
||||
const int nCount = m_nRefCounter.fetch_sub(1, AZStd::memory_order_acq_rel) - 1; // because we get the original value back
|
||||
AZ_Assert(nCount >= 0, "Deleting Reference Counted Object Twice");
|
||||
if (nCount == 0)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
else if (nCount < 0)
|
||||
{
|
||||
assert(0);
|
||||
CryFatalError("Deleting Reference Counted Object Twice");
|
||||
}
|
||||
}
|
||||
|
||||
Counter NumRefs() const { return m_nRefCounter; }
|
||||
Counter NumRefs() const { return m_nRefCounter.load(AZStd::memory_order_acquire); }
|
||||
|
||||
protected:
|
||||
|
||||
volatile Counter m_nRefCounter;
|
||||
AZStd::atomic<Counter> m_nRefCounter{ 0 };
|
||||
};
|
||||
|
||||
typedef _i_reference_target<int> _i_reference_target_t;
|
||||
|
||||
@@ -153,7 +153,7 @@ namespace Audio
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void SAudioRequestDataInternal::Release()
|
||||
{
|
||||
const int nCount = CryInterlockedDecrement(&m_nRefCounter);
|
||||
const int nCount = m_nRefCounter.fetch_sub(1, AZStd::memory_order_acq_rel) - 1; // because we get the original value back
|
||||
AZ_Assert(nCount >= 0, "AudioRequests Release - Decremented reference counter too many times!");
|
||||
|
||||
if (nCount == 0)
|
||||
|
||||
Reference in New Issue
Block a user