mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2025-01-08 06:35:33 +00:00
Move Thread.h out of the include directory, and update the BlockStatManager to compensate.
This commit is contained in:
parent
40a0947649
commit
45e926536a
|
@ -94,7 +94,7 @@ ELSE()
|
|||
SET( SOURCES ${SOURCES} "src/ThreadGroup.cpp" )
|
||||
SET( SOURCES ${SOURCES} "src/WorkerQueue.cpp" )
|
||||
|
||||
SET( HEADERS ${HEADERS} "include/Thread.h" )
|
||||
SET( HEADERS ${HEADERS} "src/Thread.h" )
|
||||
SET( HEADERS ${HEADERS} "src/ThreadGroup.h" )
|
||||
SET( HEADERS ${HEADERS} "src/WorkerQueue.h" )
|
||||
ENDIF()
|
||||
|
|
|
@ -3,7 +3,19 @@
|
|||
|
||||
#include "TexCompTypes.h"
|
||||
#include "ReferenceCounter.h"
|
||||
#include "Thread.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Forward declarations
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
class TCMutex;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// class BlockStat
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct BlockStat {
|
||||
friend class BlockStatManager;
|
||||
|
@ -36,6 +48,8 @@ class BlockStatManager {
|
|||
|
||||
public:
|
||||
BlockStatManager(int nBlocks);
|
||||
BlockStatManager(const BlockStatManager &);
|
||||
BlockStatManager &operator=(const BlockStatManager &);
|
||||
~BlockStatManager();
|
||||
|
||||
uint32 BeginBlock();
|
||||
|
@ -55,6 +69,7 @@ class BlockStatManager {
|
|||
|
||||
private:
|
||||
BlockStatList(const BlockStat &stat);
|
||||
BlockStatList(const BlockStatList &other);
|
||||
|
||||
BlockStat m_Stat;
|
||||
BlockStatList *m_Tail;
|
||||
|
@ -63,9 +78,12 @@ class BlockStatManager {
|
|||
} *m_BlockStatList;
|
||||
uint32 m_BlockStatListSz;
|
||||
|
||||
TCMutex m_Mutex;
|
||||
TCMutex *m_Mutex;
|
||||
uint32 m_NextBlock;
|
||||
ReferenceCounter m_Counter;
|
||||
|
||||
// Note: we probably shouldn't call this...
|
||||
void Copy(const BlockStatManager &);
|
||||
};
|
||||
|
||||
#endif // __BLOCK_STATS_H__
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <assert.h>
|
||||
|
||||
#include "FileStream.h"
|
||||
#include "Thread.h"
|
||||
|
||||
template <typename T>
|
||||
static T max(const T &a, const T &b) {
|
||||
|
@ -79,9 +80,36 @@ void BlockStat::ToString(CHAR *buf, int bufSz) const {
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void BlockStatManager::Copy(const BlockStatManager &other) {
|
||||
// This is a bug. If we copy the manager then all of the lists and pointers
|
||||
// become shared and can cause dereferencing issues. Check to see where you're
|
||||
// copying this class and make sure to actually create a new instance.
|
||||
assert(!"We shouldn't be copying these in this manner!");
|
||||
|
||||
m_BlockStatList = new BlockStatList(other.m_BlockStatList);
|
||||
m_BlockStatListSz = other.m_BlockStatListSz;
|
||||
m_NextBlock = other.m_NextBlock;
|
||||
|
||||
// If we do copy them, then make sure that we are actually using the exact same
|
||||
// pointers for our synchronization primitives... otherwise we could run into
|
||||
// deadlock issues.
|
||||
m_Mutex = other.m_Mutex;
|
||||
}
|
||||
|
||||
BlockStatManager::BlockStatManager(const BlockStatManager &other) {
|
||||
Copy(other);
|
||||
}
|
||||
|
||||
BlockStatManager &BlockStatManager::operator=(const BlockStatManager &other) {
|
||||
m_Counter = other.m_Counter;
|
||||
Copy(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
BlockStatManager::BlockStatManager(int nBlocks)
|
||||
: m_BlockStatListSz(max(nBlocks, 0))
|
||||
, m_NextBlock(0)
|
||||
, m_Mutex(new TCMutex)
|
||||
{
|
||||
m_BlockStatList = new BlockStatList[m_BlockStatListSz];
|
||||
if(!m_BlockStatList) {
|
||||
|
@ -95,6 +123,12 @@ BlockStatManager::~BlockStatManager() {
|
|||
if(m_Counter.GetRefCount() == 0) {
|
||||
delete [] m_BlockStatList;
|
||||
}
|
||||
|
||||
if(m_Mutex)
|
||||
{
|
||||
delete m_Mutex;
|
||||
m_Mutex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32 BlockStatManager::BeginBlock() {
|
||||
|
@ -104,7 +138,7 @@ uint32 BlockStatManager::BeginBlock() {
|
|||
return m_NextBlock-1;
|
||||
}
|
||||
|
||||
TCLock lock (m_Mutex);
|
||||
TCLock lock (*m_Mutex);
|
||||
return m_NextBlock++;
|
||||
}
|
||||
|
||||
|
@ -115,7 +149,7 @@ void BlockStatManager::AddStat(uint32 blockIdx, const BlockStat &stat) {
|
|||
return;
|
||||
}
|
||||
|
||||
TCLock lock (m_Mutex);
|
||||
TCLock lock (*m_Mutex);
|
||||
m_BlockStatList[blockIdx].AddStat(stat);
|
||||
}
|
||||
|
||||
|
@ -168,8 +202,14 @@ BlockStatManager::BlockStatList::BlockStatList(const BlockStat &stat)
|
|||
: m_Tail(0)
|
||||
, m_Stat(stat)
|
||||
{
|
||||
assert(!"If you're copying a block stat list then you're probably not using them properly.");
|
||||
}
|
||||
|
||||
BlockStatManager::BlockStatList::BlockStatList(const BlockStatList &other)
|
||||
: m_Tail(new BlockStatList(*other.m_Tail))
|
||||
, m_Stat(other.m_Stat)
|
||||
{}
|
||||
|
||||
BlockStatManager::BlockStatList::~BlockStatList() {
|
||||
if(m_Counter.GetRefCount() == 0 && m_Tail) {
|
||||
delete m_Tail;
|
||||
|
|
Loading…
Reference in a new issue