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 barrier;
|
|
|
|
class thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct CmpThread {
|
|
|
|
friend class ThreadGroup;
|
|
|
|
|
|
|
|
private:
|
|
|
|
boost::barrier *m_Barrier;
|
|
|
|
|
|
|
|
int m_Width;
|
|
|
|
int m_Height;
|
|
|
|
|
|
|
|
CompressionFunc m_CmpFunc;
|
|
|
|
|
|
|
|
unsigned char *m_OutBuf;
|
|
|
|
const unsigned char *m_InBuf;
|
|
|
|
|
|
|
|
CmpThread();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void operator ()();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ThreadGroup {
|
|
|
|
public:
|
|
|
|
ThreadGroup( int numThreads, const ImageFile &, CompressionFunc func, unsigned char *outBuf );
|
|
|
|
~ThreadGroup();
|
|
|
|
|
|
|
|
void Start();
|
|
|
|
void Join();
|
|
|
|
|
2012-08-30 18:00:18 +00:00
|
|
|
const StopWatch &GetStopWatch() const { return m_StopWatch; }
|
|
|
|
|
2012-08-29 18:43:37 +00:00
|
|
|
private:
|
2012-08-31 18:58:51 +00:00
|
|
|
boost::barrier *const m_Barrier;
|
2012-08-29 18:43:37 +00:00
|
|
|
|
|
|
|
static const int kMaxNumThreads = 256;
|
|
|
|
const int m_NumThreads;
|
|
|
|
|
|
|
|
int m_ActiveThreads;
|
|
|
|
|
|
|
|
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.
|
|
|
|
const ImageFile &m_Image;
|
|
|
|
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-08-29 18:43:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _THREAD_GROUP_H_
|