6e8fbca745
match the genesis editor version 1.3.0.653.
70 lines
1.8 KiB
Objective-C
70 lines
1.8 KiB
Objective-C
#pragma once
|
|
//------------------------------------------------------------------------------
|
|
/**
|
|
@class Jobs::TPJobThreadPool
|
|
|
|
Manages the thread-pool, distributes TPJobSlice objects to the
|
|
worker threads.
|
|
|
|
FIXME: class is currently not thread-safe!
|
|
|
|
(C) 2009 Radon Labs GmbH
|
|
*/
|
|
#include "core/types.h"
|
|
#include "jobs/tp/tpworkerthread.h"
|
|
|
|
//------------------------------------------------------------------------------
|
|
namespace Jobs
|
|
{
|
|
class TPJobThreadPool
|
|
{
|
|
public:
|
|
/// constructor
|
|
TPJobThreadPool();
|
|
/// destructor
|
|
~TPJobThreadPool();
|
|
|
|
/// setup the thread pool
|
|
void Setup();
|
|
/// discard the thread pool
|
|
void Discard();
|
|
/// return true if object is setup
|
|
bool IsValid() const;
|
|
|
|
/// push a sync command into the thread pool
|
|
void PushSync(const Threading::Event* syncEvent);
|
|
/// push job slices into the the thread pool
|
|
void PushJobSlices(TPJobSlice* firstSlice, SizeT numSlices, IndexT threadIndex=InvalidIndex);
|
|
/// get a suitable worker thread index (optimally a thread with currently no load)
|
|
IndexT GetNextThreadIndex() const;
|
|
|
|
private:
|
|
static const SizeT NumWorkerThreads = 4;
|
|
Threading::CriticalSection critSect;
|
|
GPtr<TPWorkerThread> workerThreads[NumWorkerThreads];
|
|
Util::Array<TPJobSlice*> tmpJobSliceQueue[NumWorkerThreads];
|
|
IndexT nextThreadIndex;
|
|
bool isValid;
|
|
};
|
|
|
|
//------------------------------------------------------------------------------
|
|
/**
|
|
*/
|
|
inline bool
|
|
TPJobThreadPool::IsValid() const
|
|
{
|
|
return this->isValid;
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
/**
|
|
*/
|
|
inline IndexT
|
|
TPJobThreadPool::GetNextThreadIndex() const
|
|
{
|
|
return this->nextThreadIndex;
|
|
}
|
|
|
|
} // namespace Jobs
|
|
//------------------------------------------------------------------------------
|
|
|