[development] removal of unused and low stakes code related to Cry-threading (#2896)
Removal highlights include: - File indexer (used CryThread<>) linked to long gone asset browser - Producer/consumer queues from CryMT - set/vector/CLocklessPointerQueue containers also from CryMT - Cry interlocked linked list and _InterlockedCompareExchange128 - CryThread type - SAtomicVar types - CryAutoSet type - Various unused lock types -- AutoLockModify -- AutoLockRead -- CryOptionalAutoLock -- CryReadModifyLock -- CryRWLock -- ReadLock -- ReadLockCond -- WriteAfterReadLock - Misc. unused functions -- CryInterLockedAdd (not to be confused with CryInterlockedAdd, using a lower case "locked") -- CryInterlockedExchange64 (which was only defined for unix platforms) -- SpinLock -- JobSpinLock -- AtomicAdd -- JobAtomicAdd Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com>
This commit is contained in:
@@ -524,57 +524,6 @@ inline void CryFastSemaphore::Release()
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#if !defined _CRYTHREAD_HAVE_RWLOCK
|
||||
class CryRWLock
|
||||
{
|
||||
pthread_rwlock_t m_Lock;
|
||||
|
||||
CryRWLock(const CryRWLock&);
|
||||
CryRWLock& operator= (const CryRWLock&);
|
||||
|
||||
public:
|
||||
CryRWLock() { pthread_rwlock_init(&m_Lock, NULL); }
|
||||
~CryRWLock() { pthread_rwlock_destroy(&m_Lock); }
|
||||
void RLock() { pthread_rwlock_rdlock(&m_Lock); }
|
||||
bool TryRLock()
|
||||
{
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#define AZ_RESTRICTED_SECTION CRYTHREAD_PTHREADS_H_SECTION_TRY_RLOCK
|
||||
#include AZ_RESTRICTED_FILE(CryThread_pthreads_h)
|
||||
#endif
|
||||
#if defined(AZ_RESTRICTED_SECTION_IMPLEMENTED)
|
||||
#undef AZ_RESTRICTED_SECTION_IMPLEMENTED
|
||||
#else
|
||||
return pthread_rwlock_tryrdlock(&m_Lock) != EBUSY;
|
||||
#endif
|
||||
}
|
||||
void RUnlock() { Unlock(); }
|
||||
void WLock() { pthread_rwlock_wrlock(&m_Lock); }
|
||||
bool TryWLock()
|
||||
{
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#define AZ_RESTRICTED_SECTION CRYTHREAD_PTHREADS_H_SECTION_TRY_RLOCK
|
||||
#include AZ_RESTRICTED_FILE(CryThread_pthreads_h)
|
||||
#endif
|
||||
#if defined(AZ_RESTRICTED_SECTION_IMPLEMENTED)
|
||||
#undef AZ_RESTRICTED_SECTION_IMPLEMENTED
|
||||
#else
|
||||
return pthread_rwlock_trywrlock(&m_Lock) != EBUSY;
|
||||
#endif
|
||||
}
|
||||
void WUnlock() { Unlock(); }
|
||||
void Lock() { WLock(); }
|
||||
bool TryLock() { return TryWLock(); }
|
||||
void Unlock() { pthread_rwlock_unlock(&m_Lock); }
|
||||
};
|
||||
|
||||
// Indicate that this implementation header provides an implementation for
|
||||
// CryRWLock.
|
||||
#define _CRYTHREAD_HAVE_RWLOCK 1
|
||||
#endif // !defined _CRYTHREAD_HAVE_RWLOCK
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Provide TLS implementation using pthreads for those platforms without __thread
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -1145,185 +1094,3 @@ public:
|
||||
};
|
||||
|
||||
#include "MemoryAccess.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// base class for lock less Producer/Consumer queue, due platforms specific they
|
||||
// are implemeted in CryThead_platform.h
|
||||
namespace CryMT {
|
||||
namespace detail {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
class SingleProducerSingleConsumerQueueBase
|
||||
{
|
||||
public:
|
||||
SingleProducerSingleConsumerQueueBase()
|
||||
{}
|
||||
|
||||
void Push(void* pObj, volatile uint32& rProducerIndex, volatile uint32& rComsumerIndex, uint32 nBufferSize, void* arrBuffer, uint32 nObjectSize);
|
||||
void Pop(void* pObj, volatile uint32& rProducerIndex, volatile uint32& rComsumerIndex, uint32 nBufferSize, void* arrBuffer, uint32 nObjectSize);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline void SingleProducerSingleConsumerQueueBase::Push(void* pObj, volatile uint32& rProducerIndex, volatile uint32& rComsumerIndex, uint32 nBufferSize, void* arrBuffer, uint32 nObjectSize)
|
||||
{
|
||||
MemoryBarrier();
|
||||
// spin if queue is full
|
||||
int iter = 0;
|
||||
while (rProducerIndex - rComsumerIndex == nBufferSize)
|
||||
{
|
||||
Sleep(iter++ > 10 ? 1 : 0);
|
||||
}
|
||||
|
||||
char* pBuffer = alias_cast<char*>(arrBuffer);
|
||||
uint32 nIndex = rProducerIndex % nBufferSize;
|
||||
memcpy(pBuffer + (nIndex * nObjectSize), pObj, nObjectSize);
|
||||
|
||||
MemoryBarrier();
|
||||
rProducerIndex += 1;
|
||||
MemoryBarrier();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline void SingleProducerSingleConsumerQueueBase::Pop(void* pObj, volatile uint32& rProducerIndex, volatile uint32& rComsumerIndex, uint32 nBufferSize, void* arrBuffer, uint32 nObjectSize)
|
||||
{
|
||||
MemoryBarrier();
|
||||
// busy-loop if queue is empty
|
||||
int iter = 0;
|
||||
while (rProducerIndex - rComsumerIndex == 0)
|
||||
{
|
||||
Sleep(iter++ > 10 ? 1 : 0);
|
||||
}
|
||||
|
||||
char* pBuffer = alias_cast<char*>(arrBuffer);
|
||||
uint32 nIndex = rComsumerIndex % nBufferSize;
|
||||
|
||||
memcpy(pObj, pBuffer + (nIndex * nObjectSize), nObjectSize);
|
||||
|
||||
MemoryBarrier();
|
||||
rComsumerIndex += 1;
|
||||
MemoryBarrier();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
class N_ProducerSingleConsumerQueueBase
|
||||
{
|
||||
public:
|
||||
N_ProducerSingleConsumerQueueBase()
|
||||
{
|
||||
CryInitializeSListHead(fallbackList);
|
||||
}
|
||||
|
||||
void Push(void* pObj, volatile uint32& rProducerIndex, volatile uint32& rComsumerIndex, volatile uint32& rRunning, void* arrBuffer, uint32 nBufferSize, uint32 nObjectSize, volatile uint32* arrStates);
|
||||
bool Pop(void* pObj, volatile uint32& rProducerIndex, volatile uint32& rComsumerIndex, volatile uint32& rRunning, void* arrBuffer, uint32 nBufferSize, uint32 nObjectSize, volatile uint32* arrStates);
|
||||
|
||||
SLockFreeSingleLinkedListHeader fallbackList;
|
||||
struct SFallbackList
|
||||
{
|
||||
SLockFreeSingleLinkedListEntry nextEntry;
|
||||
char alignment_padding[128 - sizeof(SLockFreeSingleLinkedListEntry)];
|
||||
char object[1]; // struct will be overallocated with enough memory for the object
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline void N_ProducerSingleConsumerQueueBase::Push(void* pObj, volatile uint32& rProducerIndex, volatile uint32& rComsumerIndex, volatile uint32& rRunning, void* arrBuffer, uint32 nBufferSize, uint32 nObjectSize, volatile uint32* arrStates)
|
||||
{
|
||||
MemoryBarrier();
|
||||
uint32 nProducerIndex;
|
||||
uint32 nComsumerIndex;
|
||||
|
||||
int iter = 0;
|
||||
do
|
||||
{
|
||||
nProducerIndex = rProducerIndex;
|
||||
nComsumerIndex = rComsumerIndex;
|
||||
|
||||
if (nProducerIndex - nComsumerIndex == nBufferSize)
|
||||
{
|
||||
Sleep(iter++ > 10 ? 1 : 0);
|
||||
if (iter > 20) // 10 spins + 10 ms wait
|
||||
{
|
||||
uint32 nSizeToAlloc = sizeof(SFallbackList) + nObjectSize - 1;
|
||||
SFallbackList* pFallbackEntry = (SFallbackList*)CryModuleMemalign(nSizeToAlloc, 128);
|
||||
memcpy(pFallbackEntry->object, pObj, nObjectSize);
|
||||
CryInterlockedPushEntrySList(fallbackList, pFallbackEntry->nextEntry);
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (CryInterlockedCompareExchange(alias_cast<volatile LONG*>(&rProducerIndex), nProducerIndex + 1, nProducerIndex) == nProducerIndex)
|
||||
{
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
char* pBuffer = alias_cast<char*>(arrBuffer);
|
||||
uint32 nIndex = nProducerIndex % nBufferSize;
|
||||
|
||||
memcpy(pBuffer + (nIndex * nObjectSize), pObj, nObjectSize);
|
||||
|
||||
MemoryBarrier();
|
||||
arrStates[nIndex] = 1;
|
||||
MemoryBarrier();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline bool N_ProducerSingleConsumerQueueBase::Pop(void* pObj, volatile uint32& rProducerIndex, volatile uint32& rComsumerIndex, volatile uint32& rRunning, void* arrBuffer, uint32 nBufferSize, uint32 nObjectSize, volatile uint32* arrStates)
|
||||
{
|
||||
MemoryBarrier();
|
||||
// busy-loop if queue is empty
|
||||
int iter = 0;
|
||||
do
|
||||
{
|
||||
SFallbackList* pFallback = (SFallbackList*)CryInterlockedPopEntrySList(fallbackList);
|
||||
IF (pFallback, 0)
|
||||
{
|
||||
memcpy(pObj, pFallback->object, nObjectSize);
|
||||
CryModuleMemalignFree(pFallback);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (iter > 10)
|
||||
{
|
||||
Sleep(iter > 100 ? 1 : 0);
|
||||
}
|
||||
iter++;
|
||||
} while (rRunning && rProducerIndex - rComsumerIndex == 0);
|
||||
|
||||
if (rRunning == 0 && rProducerIndex - rComsumerIndex == 0)
|
||||
{
|
||||
// if the queue was empty, make sure we really are empty
|
||||
SFallbackList* pFallback = (SFallbackList*)CryInterlockedPopEntrySList(fallbackList);
|
||||
IF (pFallback, 0)
|
||||
{
|
||||
memcpy(pObj, pFallback->object, nObjectSize);
|
||||
CryModuleMemalignFree(pFallback);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
iter = 0;
|
||||
while (arrStates[rComsumerIndex % nBufferSize] == 0)
|
||||
{
|
||||
Sleep(iter++ > 10 ? 1 : 0);
|
||||
}
|
||||
|
||||
char* pBuffer = alias_cast<char*>(arrBuffer);
|
||||
uint32 nIndex = rComsumerIndex % nBufferSize;
|
||||
|
||||
memcpy(pObj, pBuffer + (nIndex * nObjectSize), nObjectSize);
|
||||
|
||||
MemoryBarrier();
|
||||
arrStates[nIndex] = 0;
|
||||
MemoryBarrier();
|
||||
rComsumerIndex += 1;
|
||||
MemoryBarrier();
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace CryMT
|
||||
|
||||
Reference in New Issue
Block a user