2012-08-29 18:43:37 +00:00
|
|
|
#ifndef _THREAD_GROUP_H_
|
|
|
|
#define _THREAD_GROUP_H_
|
|
|
|
|
|
|
|
#include "TexComp.h"
|
2012-08-30 18:00:18 +00:00
|
|
|
#include "StopWatch.h"
|
2012-08-29 18:43:37 +00:00
|
|
|
|
|
|
|
// forward declare
|
|
|
|
namespace boost {
|
|
|
|
class thread;
|
2012-08-31 21:33:54 +00:00
|
|
|
class mutex;
|
2012-09-15 16:13:32 +00:00
|
|
|
class barrier;
|
2012-08-31 21:33:54 +00:00
|
|
|
class condition_variable;
|
2012-08-29 18:43:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct CmpThread {
|
|
|
|
friend class ThreadGroup;
|
|
|
|
|
|
|
|
private:
|
2012-09-15 16:13:32 +00:00
|
|
|
boost::barrier *m_StartBarrier;
|
2012-08-31 21:33:54 +00:00
|
|
|
|
2012-09-15 16:13:32 +00:00
|
|
|
int *m_ParentCounter;
|
|
|
|
|
2012-08-31 21:33:54 +00:00
|
|
|
boost::mutex *m_ParentCounterLock;
|
|
|
|
boost::condition_variable *m_FinishCV;
|
|
|
|
|
2012-08-29 18:43:37 +00:00
|
|
|
int m_Width;
|
|
|
|
int m_Height;
|
|
|
|
|
|
|
|
CompressionFunc m_CmpFunc;
|
|
|
|
|
|
|
|
unsigned char *m_OutBuf;
|
|
|
|
const unsigned char *m_InBuf;
|
|
|
|
|
2012-09-15 16:13:32 +00:00
|
|
|
bool *m_ParentExitFlag;
|
|
|
|
|
2012-08-29 18:43:37 +00:00
|
|
|
CmpThread();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void operator ()();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ThreadGroup {
|
|
|
|
public:
|
2012-09-21 16:39:09 +00:00
|
|
|
ThreadGroup( int numThreads, const unsigned char *inBuf, unsigned int inBufSz, CompressionFunc func, unsigned char *outBuf );
|
2012-08-29 18:43:37 +00:00
|
|
|
~ThreadGroup();
|
|
|
|
|
2012-09-15 16:13:32 +00:00
|
|
|
bool PrepareThreads();
|
|
|
|
bool Start();
|
2012-08-29 18:43:37 +00:00
|
|
|
void Join();
|
2012-09-15 16:13:32 +00:00
|
|
|
bool CleanUpThreads();
|
2012-08-29 18:43:37 +00:00
|
|
|
|
2012-08-30 18:00:18 +00:00
|
|
|
const StopWatch &GetStopWatch() const { return m_StopWatch; }
|
|
|
|
|
2012-09-15 16:13:32 +00:00
|
|
|
enum EThreadState {
|
|
|
|
eThreadState_Waiting,
|
|
|
|
eThreadState_Running,
|
|
|
|
eThreadState_Done
|
|
|
|
};
|
|
|
|
|
2012-08-29 18:43:37 +00:00
|
|
|
private:
|
2012-09-15 16:13:32 +00:00
|
|
|
boost::barrier *const m_StartBarrier;
|
|
|
|
|
2012-08-31 21:33:54 +00:00
|
|
|
boost::mutex *const m_FinishMutex;
|
|
|
|
boost::condition_variable *const m_FinishCV;
|
2012-08-29 18:43:37 +00:00
|
|
|
|
|
|
|
static const int kMaxNumThreads = 256;
|
|
|
|
const int m_NumThreads;
|
|
|
|
|
|
|
|
int m_ActiveThreads;
|
2012-08-31 21:33:54 +00:00
|
|
|
int m_ThreadsFinished;
|
2012-08-29 18:43:37 +00:00
|
|
|
|
|
|
|
CmpThread m_Threads[kMaxNumThreads];
|
|
|
|
boost::thread *m_ThreadHandles[kMaxNumThreads];
|
2012-08-30 18:00:18 +00:00
|
|
|
|
2012-08-31 18:58:51 +00:00
|
|
|
// State variables.
|
2012-09-21 16:39:09 +00:00
|
|
|
const unsigned int m_ImageDataSz;
|
|
|
|
const unsigned char *const m_ImageData;
|
2012-08-31 18:58:51 +00:00
|
|
|
const CompressionFunc m_Func;
|
|
|
|
unsigned char *m_OutBuf;
|
|
|
|
|
|
|
|
unsigned int GetCompressedBlockSize();
|
|
|
|
unsigned int GetUncompressedBlockSize();
|
|
|
|
|
2012-08-30 18:00:18 +00:00
|
|
|
StopWatch m_StopWatch;
|
2012-09-15 16:13:32 +00:00
|
|
|
|
|
|
|
EThreadState m_ThreadState;
|
|
|
|
bool m_ExitFlag;
|
2012-08-29 18:43:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _THREAD_GROUP_H_
|