mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 16:44:36 +00:00
revert ThreadPool rename
revert ThreadPool rename, resources ThreadPool class is already nested in namespace VHACD
This commit is contained in:
parent
8cf2b1d0ef
commit
81a913616c
12 changed files with 69 additions and 69 deletions
|
|
@ -262,7 +262,7 @@ void StandardMainLoop::init()
|
||||||
RedBook::init();
|
RedBook::init();
|
||||||
Platform::initConsole();
|
Platform::initConsole();
|
||||||
|
|
||||||
TorqueThreadPool::GlobalThreadPool::createSingleton();
|
ThreadPool::GlobalThreadPool::createSingleton();
|
||||||
|
|
||||||
// Set engineAPI initialized to true
|
// Set engineAPI initialized to true
|
||||||
engineAPI::gIsInitialized = true;
|
engineAPI::gIsInitialized = true;
|
||||||
|
|
@ -293,7 +293,7 @@ void StandardMainLoop::init()
|
||||||
|
|
||||||
Con::setVariable("TorqueScriptFileExtension", TORQUE_SCRIPT_EXTENSION);
|
Con::setVariable("TorqueScriptFileExtension", TORQUE_SCRIPT_EXTENSION);
|
||||||
|
|
||||||
Con::addVariable( "_forceAllMainThread", TypeBool, &TorqueThreadPool::getForceAllMainThread(), "Force all work items to execute on main thread. turns this into a single-threaded system. Primarily useful to find whether malfunctions are caused by parallel execution or not.\n"
|
Con::addVariable( "_forceAllMainThread", TypeBool, &ThreadPool::getForceAllMainThread(), "Force all work items to execute on main thread. turns this into a single-threaded system. Primarily useful to find whether malfunctions are caused by parallel execution or not.\n"
|
||||||
"@ingroup platform" );
|
"@ingroup platform" );
|
||||||
|
|
||||||
#if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE )
|
#if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE )
|
||||||
|
|
@ -351,7 +351,7 @@ void StandardMainLoop::shutdown()
|
||||||
|
|
||||||
EngineModuleManager::shutdownSystem();
|
EngineModuleManager::shutdownSystem();
|
||||||
|
|
||||||
TorqueThreadPool::GlobalThreadPool::deleteSingleton();
|
ThreadPool::GlobalThreadPool::deleteSingleton();
|
||||||
|
|
||||||
#ifdef TORQUE_ENABLE_VFS
|
#ifdef TORQUE_ENABLE_VFS
|
||||||
closeEmbeddedVFSArchive();
|
closeEmbeddedVFSArchive();
|
||||||
|
|
@ -636,7 +636,7 @@ bool StandardMainLoop::doMainLoop()
|
||||||
if(!Process::processEvents())
|
if(!Process::processEvents())
|
||||||
keepRunning = false;
|
keepRunning = false;
|
||||||
|
|
||||||
TorqueThreadPool::processMainThreadWorkItems();
|
ThreadPool::processMainThreadWorkItems();
|
||||||
Sampler::endFrame();
|
Sampler::endFrame();
|
||||||
ConsoleValue::resetConversionBuffer();
|
ConsoleValue::resetConversionBuffer();
|
||||||
PROFILE_END_NAMED(MainLoop);
|
PROFILE_END_NAMED(MainLoop);
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ namespace ImageUtil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Thread work job for compression
|
//Thread work job for compression
|
||||||
struct CompressJob : public TorqueThreadPool::WorkItem
|
struct CompressJob : public ThreadPool::WorkItem
|
||||||
{
|
{
|
||||||
S32 width;
|
S32 width;
|
||||||
S32 height;
|
S32 height;
|
||||||
|
|
@ -124,7 +124,7 @@ namespace ImageUtil
|
||||||
srcDDS->mFlags.set(DDSFile::CompressedData);
|
srcDDS->mFlags.set(DDSFile::CompressedData);
|
||||||
|
|
||||||
//grab global thread pool
|
//grab global thread pool
|
||||||
TorqueThreadPool* pThreadPool = &TorqueThreadPool::GLOBAL();
|
ThreadPool* pThreadPool = &ThreadPool::GLOBAL();
|
||||||
|
|
||||||
if (cubemap)
|
if (cubemap)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -336,7 +336,7 @@ void TheoraTexture::_onTextureEvent( GFXTexCallbackCode code )
|
||||||
{
|
{
|
||||||
// Blast out work items and then release all texture locks.
|
// Blast out work items and then release all texture locks.
|
||||||
|
|
||||||
TorqueThreadPool::GLOBAL().flushWorkItems();
|
ThreadPool::GLOBAL().flushWorkItems();
|
||||||
mAsyncState->getFrameStream()->releaseTextureLocks();
|
mAsyncState->getFrameStream()->releaseTextureLocks();
|
||||||
|
|
||||||
// The Theora decoder does not implement seeking at the moment,
|
// The Theora decoder does not implement seeking at the moment,
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ class TheoraTexture : private IOutputStream< TheoraTextureFrame* >,
|
||||||
|
|
||||||
///
|
///
|
||||||
FrameReadItem( AsyncBufferedInputStream< TheoraTextureFrame*, IInputStream< OggTheoraFrame* >* >* stream,
|
FrameReadItem( AsyncBufferedInputStream< TheoraTextureFrame*, IInputStream< OggTheoraFrame* >* >* stream,
|
||||||
TorqueThreadPool::Context* context );
|
ThreadPool::Context* context );
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Stream filter that turns a stream of OggTheoraFrames into a buffered background stream of TheoraTextureFrame
|
/// Stream filter that turns a stream of OggTheoraFrames into a buffered background stream of TheoraTextureFrame
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class AsyncBufferedInputStream : public IInputStreamFilter< T, Stream >,
|
||||||
ElementList mBufferedElements;
|
ElementList mBufferedElements;
|
||||||
|
|
||||||
/// The thread pool to which read items are queued.
|
/// The thread pool to which read items are queued.
|
||||||
TorqueThreadPool* mThreadPool;
|
ThreadPool* mThreadPool;
|
||||||
|
|
||||||
/// The thread context used for prioritizing read items in the pool.
|
/// The thread context used for prioritizing read items in the pool.
|
||||||
ThreadContext* mThreadContext;
|
ThreadContext* mThreadContext;
|
||||||
|
|
@ -132,7 +132,7 @@ class AsyncBufferedInputStream : public IInputStreamFilter< T, Stream >,
|
||||||
U32 numSourceElementsToRead = 0,
|
U32 numSourceElementsToRead = 0,
|
||||||
U32 numReadAhead = DEFAULT_STREAM_LOOKAHEAD,
|
U32 numReadAhead = DEFAULT_STREAM_LOOKAHEAD,
|
||||||
bool isLooping = false,
|
bool isLooping = false,
|
||||||
TorqueThreadPool* pool = &TorqueThreadPool::GLOBAL(),
|
ThreadPool* pool = &ThreadPool::GLOBAL(),
|
||||||
ThreadContext* context = ThreadContext::ROOT_CONTEXT() );
|
ThreadContext* context = ThreadContext::ROOT_CONTEXT() );
|
||||||
|
|
||||||
virtual ~AsyncBufferedInputStream();
|
virtual ~AsyncBufferedInputStream();
|
||||||
|
|
@ -162,7 +162,7 @@ AsyncBufferedInputStream< T, Stream >::AsyncBufferedInputStream
|
||||||
U32 numSourceElementsToRead,
|
U32 numSourceElementsToRead,
|
||||||
U32 numReadAhead,
|
U32 numReadAhead,
|
||||||
bool isLooping,
|
bool isLooping,
|
||||||
TorqueThreadPool* threadPool,
|
ThreadPool* threadPool,
|
||||||
ThreadContext* threadContext )
|
ThreadContext* threadContext )
|
||||||
: Parent( stream ),
|
: Parent( stream ),
|
||||||
mIsLooping( isLooping ),
|
mIsLooping( isLooping ),
|
||||||
|
|
@ -321,7 +321,7 @@ class AsyncBufferedReadItem : public ThreadWorkItem
|
||||||
///
|
///
|
||||||
AsyncBufferedReadItem(
|
AsyncBufferedReadItem(
|
||||||
const AsyncStreamRef& asyncStream,
|
const AsyncStreamRef& asyncStream,
|
||||||
TorqueThreadPool::Context* context = NULL
|
ThreadPool::Context* context = NULL
|
||||||
)
|
)
|
||||||
: Parent( context ),
|
: Parent( context ),
|
||||||
mAsyncStream( asyncStream ),
|
mAsyncStream( asyncStream ),
|
||||||
|
|
@ -376,7 +376,7 @@ class AsyncSingleBufferedInputStream : public AsyncBufferedInputStream< T, Strea
|
||||||
U32 numSourceElementsToRead = 0,
|
U32 numSourceElementsToRead = 0,
|
||||||
U32 numReadAhead = Parent::DEFAULT_STREAM_LOOKAHEAD,
|
U32 numReadAhead = Parent::DEFAULT_STREAM_LOOKAHEAD,
|
||||||
bool isLooping = false,
|
bool isLooping = false,
|
||||||
TorqueThreadPool* pool = &TorqueThreadPool::GLOBAL(),
|
ThreadPool* pool = &ThreadPool::GLOBAL(),
|
||||||
ThreadContext* context = ThreadContext::ROOT_CONTEXT() )
|
ThreadContext* context = ThreadContext::ROOT_CONTEXT() )
|
||||||
: Parent( stream,
|
: Parent( stream,
|
||||||
numSourceElementsToRead,
|
numSourceElementsToRead,
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ class AsyncPacketBufferedInputStream : public AsyncBufferedInputStream< Packet*,
|
||||||
PacketReadItem( const ThreadSafeRef< AsyncPacketBufferedInputStream< Stream, Packet > >& asyncStream,
|
PacketReadItem( const ThreadSafeRef< AsyncPacketBufferedInputStream< Stream, Packet > >& asyncStream,
|
||||||
PacketType* packet,
|
PacketType* packet,
|
||||||
U32 numElements,
|
U32 numElements,
|
||||||
TorqueThreadPool::Context* context = NULL )
|
ThreadPool::Context* context = NULL )
|
||||||
: Parent( asyncStream->getSourceStream(), numElements, 0, *packet, false, 0, context ),
|
: Parent( asyncStream->getSourceStream(), numElements, 0, *packet, false, 0, context ),
|
||||||
mAsyncStream( asyncStream ),
|
mAsyncStream( asyncStream ),
|
||||||
mPacket( packet ) {}
|
mPacket( packet ) {}
|
||||||
|
|
@ -227,7 +227,7 @@ class AsyncPacketBufferedInputStream : public AsyncBufferedInputStream< Packet*,
|
||||||
U32 numSourceElementsToRead = 0,
|
U32 numSourceElementsToRead = 0,
|
||||||
U32 numReadAhead = Parent::DEFAULT_STREAM_LOOKAHEAD,
|
U32 numReadAhead = Parent::DEFAULT_STREAM_LOOKAHEAD,
|
||||||
bool isLooping = false,
|
bool isLooping = false,
|
||||||
TorqueThreadPool* pool = &TorqueThreadPool::GLOBAL(),
|
ThreadPool* pool = &ThreadPool::GLOBAL(),
|
||||||
ThreadContext* context = ThreadContext::ROOT_CONTEXT() );
|
ThreadContext* context = ThreadContext::ROOT_CONTEXT() );
|
||||||
|
|
||||||
/// @return the size of stream packets returned by this stream in number of elements.
|
/// @return the size of stream packets returned by this stream in number of elements.
|
||||||
|
|
@ -241,7 +241,7 @@ AsyncPacketBufferedInputStream< Stream, Packet >::AsyncPacketBufferedInputStream
|
||||||
U32 numSourceElementsToRead,
|
U32 numSourceElementsToRead,
|
||||||
U32 numReadAhead,
|
U32 numReadAhead,
|
||||||
bool isLooping,
|
bool isLooping,
|
||||||
TorqueThreadPool* threadPool,
|
ThreadPool* threadPool,
|
||||||
ThreadContext* threadContext )
|
ThreadContext* threadContext )
|
||||||
: Parent( stream, numSourceElementsToRead, numReadAhead, isLooping, threadPool, threadContext ),
|
: Parent( stream, numSourceElementsToRead, numReadAhead, isLooping, threadPool, threadContext ),
|
||||||
mPacketSize( packetSize ),
|
mPacketSize( packetSize ),
|
||||||
|
|
|
||||||
|
|
@ -65,11 +65,11 @@ struct NetAsync::NameLookupRequest
|
||||||
|
|
||||||
/// Work item issued to the thread pool for each lookup request.
|
/// Work item issued to the thread pool for each lookup request.
|
||||||
|
|
||||||
struct NetAsync::NameLookupWorkItem : public TorqueThreadPool::WorkItem
|
struct NetAsync::NameLookupWorkItem : public ThreadPool::WorkItem
|
||||||
{
|
{
|
||||||
typedef TorqueThreadPool::WorkItem Parent;
|
typedef ThreadPool::WorkItem Parent;
|
||||||
|
|
||||||
NameLookupWorkItem( NameLookupRequest& request, TorqueThreadPool::Context* context = 0 )
|
NameLookupWorkItem( NameLookupRequest& request, ThreadPool::Context* context = 0 )
|
||||||
: Parent( context ),
|
: Parent( context ),
|
||||||
mRequest( request )
|
mRequest( request )
|
||||||
{
|
{
|
||||||
|
|
@ -133,7 +133,7 @@ void NetAsync::queueLookup(const char* remoteAddr, NetSocket socket)
|
||||||
dStrncpy(lookupRequest.remoteAddr, remoteAddr, sizeof(lookupRequest.remoteAddr));
|
dStrncpy(lookupRequest.remoteAddr, remoteAddr, sizeof(lookupRequest.remoteAddr));
|
||||||
|
|
||||||
ThreadSafeRef< NameLookupWorkItem > workItem( new NameLookupWorkItem( lookupRequest ) );
|
ThreadSafeRef< NameLookupWorkItem > workItem( new NameLookupWorkItem( lookupRequest ) );
|
||||||
TorqueThreadPool::GLOBAL().queueWorkItem( workItem );
|
ThreadPool::GLOBAL().queueWorkItem( workItem );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetAsync::checkLookup(NetSocket socket, void* out_h_addr,
|
bool NetAsync::checkLookup(NetSocket socket, void* out_h_addr,
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,11 @@
|
||||||
// ThreadPool::Context.
|
// ThreadPool::Context.
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
|
|
||||||
TorqueThreadPool::Context TorqueThreadPool::Context::smRootContext( "ROOT", NULL, 1.0 );
|
ThreadPool::Context ThreadPool::Context::smRootContext( "ROOT", NULL, 1.0 );
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
TorqueThreadPool::Context::Context( const char* name, TorqueThreadPool::Context* parent, F32 priorityBias )
|
ThreadPool::Context::Context( const char* name, ThreadPool::Context* parent, F32 priorityBias )
|
||||||
: mParent( parent ),
|
: mParent( parent ),
|
||||||
mName( name ),
|
mName( name ),
|
||||||
mChildren( 0 ),
|
mChildren( 0 ),
|
||||||
|
|
@ -55,7 +55,7 @@ TorqueThreadPool::Context::Context( const char* name, TorqueThreadPool::Context*
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
TorqueThreadPool::Context::~Context()
|
ThreadPool::Context::~Context()
|
||||||
{
|
{
|
||||||
if( mParent )
|
if( mParent )
|
||||||
for( Context* context = mParent->mChildren, *prev = 0; context != 0; prev = context, context = context->mSibling )
|
for( Context* context = mParent->mChildren, *prev = 0; context != 0; prev = context, context = context->mSibling )
|
||||||
|
|
@ -70,7 +70,7 @@ TorqueThreadPool::Context::~Context()
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
TorqueThreadPool::Context* TorqueThreadPool::Context::getChild( const char* name )
|
ThreadPool::Context* ThreadPool::Context::getChild( const char* name )
|
||||||
{
|
{
|
||||||
for( Context* child = getChildren(); child != 0; child = child->getSibling() )
|
for( Context* child = getChildren(); child != 0; child = child->getSibling() )
|
||||||
if( dStricmp( child->getName(), name ) == 0 )
|
if( dStricmp( child->getName(), name ) == 0 )
|
||||||
|
|
@ -80,7 +80,7 @@ TorqueThreadPool::Context* TorqueThreadPool::Context::getChild( const char* name
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
F32 TorqueThreadPool::Context::getAccumulatedPriorityBias()
|
F32 ThreadPool::Context::getAccumulatedPriorityBias()
|
||||||
{
|
{
|
||||||
if( !mAccumulatedPriorityBias )
|
if( !mAccumulatedPriorityBias )
|
||||||
updateAccumulatedPriorityBiases();
|
updateAccumulatedPriorityBiases();
|
||||||
|
|
@ -89,7 +89,7 @@ F32 TorqueThreadPool::Context::getAccumulatedPriorityBias()
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
void TorqueThreadPool::Context::setPriorityBias( F32 value )
|
void ThreadPool::Context::setPriorityBias( F32 value )
|
||||||
{
|
{
|
||||||
mPriorityBias = value;
|
mPriorityBias = value;
|
||||||
mAccumulatedPriorityBias = 0.0;
|
mAccumulatedPriorityBias = 0.0;
|
||||||
|
|
@ -97,7 +97,7 @@ void TorqueThreadPool::Context::setPriorityBias( F32 value )
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
void TorqueThreadPool::Context::updateAccumulatedPriorityBiases()
|
void ThreadPool::Context::updateAccumulatedPriorityBiases()
|
||||||
{
|
{
|
||||||
// Update our own priority bias.
|
// Update our own priority bias.
|
||||||
|
|
||||||
|
|
@ -117,7 +117,7 @@ void TorqueThreadPool::Context::updateAccumulatedPriorityBiases()
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
void TorqueThreadPool::WorkItem::process()
|
void ThreadPool::WorkItem::process()
|
||||||
{
|
{
|
||||||
execute();
|
execute();
|
||||||
mExecuted = true;
|
mExecuted = true;
|
||||||
|
|
@ -125,14 +125,14 @@ void TorqueThreadPool::WorkItem::process()
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
bool TorqueThreadPool::WorkItem::isCancellationRequested()
|
bool ThreadPool::WorkItem::isCancellationRequested()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
bool TorqueThreadPool::WorkItem::cancellationPoint()
|
bool ThreadPool::WorkItem::cancellationPoint()
|
||||||
{
|
{
|
||||||
if( isCancellationRequested() )
|
if( isCancellationRequested() )
|
||||||
{
|
{
|
||||||
|
|
@ -145,7 +145,7 @@ bool TorqueThreadPool::WorkItem::cancellationPoint()
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
F32 TorqueThreadPool::WorkItem::getPriority()
|
F32 ThreadPool::WorkItem::getPriority()
|
||||||
{
|
{
|
||||||
return 1.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
|
|
@ -160,7 +160,7 @@ F32 TorqueThreadPool::WorkItem::getPriority()
|
||||||
/// @see ThreadSafePriorityQueueWithUpdate
|
/// @see ThreadSafePriorityQueueWithUpdate
|
||||||
/// @see ThreadPool::WorkItem
|
/// @see ThreadPool::WorkItem
|
||||||
///
|
///
|
||||||
struct TorqueThreadPool::WorkItemWrapper : public ThreadSafeRef< WorkItem >
|
struct ThreadPool::WorkItemWrapper : public ThreadSafeRef< WorkItem >
|
||||||
{
|
{
|
||||||
typedef ThreadSafeRef< WorkItem > Parent;
|
typedef ThreadSafeRef< WorkItem > Parent;
|
||||||
|
|
||||||
|
|
@ -172,7 +172,7 @@ struct TorqueThreadPool::WorkItemWrapper : public ThreadSafeRef< WorkItem >
|
||||||
F32 getPriority();
|
F32 getPriority();
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool TorqueThreadPool::WorkItemWrapper::isAlive()
|
inline bool ThreadPool::WorkItemWrapper::isAlive()
|
||||||
{
|
{
|
||||||
WorkItem* item = ptr();
|
WorkItem* item = ptr();
|
||||||
if( !item )
|
if( !item )
|
||||||
|
|
@ -186,7 +186,7 @@ inline bool TorqueThreadPool::WorkItemWrapper::isAlive()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline F32 TorqueThreadPool::WorkItemWrapper::getPriority()
|
inline F32 ThreadPool::WorkItemWrapper::getPriority()
|
||||||
{
|
{
|
||||||
WorkItem* item = ptr();
|
WorkItem* item = ptr();
|
||||||
AssertFatal( item != 0, "ThreadPool::WorkItemWrapper::getPriority - called on dead item" );
|
AssertFatal( item != 0, "ThreadPool::WorkItemWrapper::getPriority - called on dead item" );
|
||||||
|
|
@ -201,20 +201,20 @@ inline F32 TorqueThreadPool::WorkItemWrapper::getPriority()
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
struct TorqueThreadPool::WorkerThread : public Thread
|
struct ThreadPool::WorkerThread : public Thread
|
||||||
{
|
{
|
||||||
WorkerThread( TorqueThreadPool* pool, U32 index );
|
WorkerThread( ThreadPool* pool, U32 index );
|
||||||
|
|
||||||
WorkerThread* getNext();
|
WorkerThread* getNext();
|
||||||
void run( void* arg = 0 ) override;
|
void run( void* arg = 0 ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
U32 mIndex;
|
U32 mIndex;
|
||||||
TorqueThreadPool* mPool;
|
ThreadPool* mPool;
|
||||||
WorkerThread* mNext;
|
WorkerThread* mNext;
|
||||||
};
|
};
|
||||||
|
|
||||||
TorqueThreadPool::WorkerThread::WorkerThread( TorqueThreadPool* pool, U32 index )
|
ThreadPool::WorkerThread::WorkerThread( ThreadPool* pool, U32 index )
|
||||||
: mIndex( index ),
|
: mIndex( index ),
|
||||||
mPool( pool )
|
mPool( pool )
|
||||||
{
|
{
|
||||||
|
|
@ -224,12 +224,12 @@ TorqueThreadPool::WorkerThread::WorkerThread( TorqueThreadPool* pool, U32 index
|
||||||
pool->mThreads = this;
|
pool->mThreads = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline TorqueThreadPool::WorkerThread* TorqueThreadPool::WorkerThread::getNext()
|
inline ThreadPool::WorkerThread* ThreadPool::WorkerThread::getNext()
|
||||||
{
|
{
|
||||||
return mNext;
|
return mNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorqueThreadPool::WorkerThread::run( void* arg )
|
void ThreadPool::WorkerThread::run( void* arg )
|
||||||
{
|
{
|
||||||
#ifdef TORQUE_DEBUG
|
#ifdef TORQUE_DEBUG
|
||||||
{
|
{
|
||||||
|
|
@ -300,13 +300,13 @@ void TorqueThreadPool::WorkerThread::run( void* arg )
|
||||||
// ThreadPool.
|
// ThreadPool.
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
|
|
||||||
bool TorqueThreadPool::smForceAllMainThread;
|
bool ThreadPool::smForceAllMainThread;
|
||||||
U32 TorqueThreadPool::smMainThreadTimeMS;
|
U32 ThreadPool::smMainThreadTimeMS;
|
||||||
TorqueThreadPool::QueueType TorqueThreadPool::smMainThreadQueue;
|
ThreadPool::QueueType ThreadPool::smMainThreadQueue;
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
TorqueThreadPool::TorqueThreadPool( const char* name, U32 numThreads )
|
ThreadPool::ThreadPool( const char* name, U32 numThreads )
|
||||||
: mName( name ),
|
: mName( name ),
|
||||||
mNumThreads( numThreads ),
|
mNumThreads( numThreads ),
|
||||||
mNumThreadsAwake( 0 ),
|
mNumThreadsAwake( 0 ),
|
||||||
|
|
@ -347,14 +347,14 @@ TorqueThreadPool::TorqueThreadPool( const char* name, U32 numThreads )
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
TorqueThreadPool::~TorqueThreadPool()
|
ThreadPool::~ThreadPool()
|
||||||
{
|
{
|
||||||
shutdown();
|
shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
void TorqueThreadPool::shutdown()
|
void ThreadPool::shutdown()
|
||||||
{
|
{
|
||||||
const U32 numThreads = mNumThreads;
|
const U32 numThreads = mNumThreads;
|
||||||
|
|
||||||
|
|
@ -387,7 +387,7 @@ void TorqueThreadPool::shutdown()
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
void TorqueThreadPool::queueWorkItem( WorkItem* item )
|
void ThreadPool::queueWorkItem( WorkItem* item )
|
||||||
{
|
{
|
||||||
bool executeRightAway = ( getForceAllMainThread() );
|
bool executeRightAway = ( getForceAllMainThread() );
|
||||||
#ifdef DEBUG_SPEW
|
#ifdef DEBUG_SPEW
|
||||||
|
|
@ -410,7 +410,7 @@ void TorqueThreadPool::queueWorkItem( WorkItem* item )
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
void TorqueThreadPool::flushWorkItems( S32 timeOut )
|
void ThreadPool::flushWorkItems( S32 timeOut )
|
||||||
{
|
{
|
||||||
AssertFatal( mNumThreads, "ThreadPool::flushWorkItems() - no worker threads in pool" );
|
AssertFatal( mNumThreads, "ThreadPool::flushWorkItems() - no worker threads in pool" );
|
||||||
|
|
||||||
|
|
@ -432,7 +432,7 @@ void TorqueThreadPool::flushWorkItems( S32 timeOut )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorqueThreadPool::waitForAllItems( S32 timeOut )
|
void ThreadPool::waitForAllItems( S32 timeOut )
|
||||||
{
|
{
|
||||||
U32 endTime = 0;
|
U32 endTime = 0;
|
||||||
if( timeOut != -1 )
|
if( timeOut != -1 )
|
||||||
|
|
@ -454,14 +454,14 @@ void TorqueThreadPool::waitForAllItems( S32 timeOut )
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
void TorqueThreadPool::queueWorkItemOnMainThread( WorkItem* item )
|
void ThreadPool::queueWorkItemOnMainThread( WorkItem* item )
|
||||||
{
|
{
|
||||||
smMainThreadQueue.insert( item->getPriority(), item );
|
smMainThreadQueue.insert( item->getPriority(), item );
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
void TorqueThreadPool::processMainThreadWorkItems()
|
void ThreadPool::processMainThreadWorkItems()
|
||||||
{
|
{
|
||||||
AssertFatal( ThreadManager::isMainThread(),
|
AssertFatal( ThreadManager::isMainThread(),
|
||||||
"ThreadPool::processMainThreadWorkItems - this function must only be called on the main thread" );
|
"ThreadPool::processMainThreadWorkItems - this function must only be called on the main thread" );
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@
|
||||||
/// automatically being released once the last concurrent work item has been
|
/// automatically being released once the last concurrent work item has been
|
||||||
/// processed or discarded.
|
/// processed or discarded.
|
||||||
///
|
///
|
||||||
class TorqueThreadPool
|
class ThreadPool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -298,9 +298,9 @@ class TorqueThreadPool
|
||||||
/// will be based on the number of CPU cores available.
|
/// will be based on the number of CPU cores available.
|
||||||
///
|
///
|
||||||
/// @param numThreads Number of threads to create or zero for default.
|
/// @param numThreads Number of threads to create or zero for default.
|
||||||
TorqueThreadPool( const char* name, U32 numThreads = 0 );
|
ThreadPool( const char* name, U32 numThreads = 0 );
|
||||||
|
|
||||||
~TorqueThreadPool();
|
~ThreadPool();
|
||||||
|
|
||||||
/// Manually shutdown threads outside of static destructors.
|
/// Manually shutdown threads outside of static destructors.
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
|
@ -397,16 +397,16 @@ class TorqueThreadPool
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the global thread pool singleton.
|
/// Return the global thread pool singleton.
|
||||||
static TorqueThreadPool& GLOBAL();
|
static ThreadPool& GLOBAL();
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef TorqueThreadPool::Context ThreadContext;
|
typedef ThreadPool::Context ThreadContext;
|
||||||
typedef TorqueThreadPool::WorkItem ThreadWorkItem;
|
typedef ThreadPool::WorkItem ThreadWorkItem;
|
||||||
|
|
||||||
|
|
||||||
struct TorqueThreadPool::GlobalThreadPool : public TorqueThreadPool, public ManagedSingleton< GlobalThreadPool >
|
struct ThreadPool::GlobalThreadPool : public ThreadPool, public ManagedSingleton< GlobalThreadPool >
|
||||||
{
|
{
|
||||||
typedef TorqueThreadPool Parent;
|
typedef ThreadPool Parent;
|
||||||
|
|
||||||
GlobalThreadPool()
|
GlobalThreadPool()
|
||||||
: Parent( "GLOBAL" ) {}
|
: Parent( "GLOBAL" ) {}
|
||||||
|
|
@ -415,7 +415,7 @@ struct TorqueThreadPool::GlobalThreadPool : public TorqueThreadPool, public Mana
|
||||||
static const char* getSingletonName() { return "GlobalThreadPool"; }
|
static const char* getSingletonName() { return "GlobalThreadPool"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
inline TorqueThreadPool& TorqueThreadPool::GLOBAL()
|
inline ThreadPool& ThreadPool::GLOBAL()
|
||||||
{
|
{
|
||||||
return *( GlobalThreadPool::instance() );
|
return *( GlobalThreadPool::instance() );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@
|
||||||
///
|
///
|
||||||
/// @param T Type of elements being streamed.
|
/// @param T Type of elements being streamed.
|
||||||
template< typename T, class Stream >
|
template< typename T, class Stream >
|
||||||
class AsyncIOItem : public TorqueThreadPool::WorkItem
|
class AsyncIOItem : public ThreadPool::WorkItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -358,11 +358,11 @@ enum
|
||||||
/// @note Don't use this directly but rather use THREAD_POOL() instead.
|
/// @note Don't use this directly but rather use THREAD_POOL() instead.
|
||||||
/// This way, the sound code may be easily switched to using a common
|
/// This way, the sound code may be easily switched to using a common
|
||||||
/// pool later on.
|
/// pool later on.
|
||||||
class SFXThreadPool : public TorqueThreadPool, public ManagedSingleton< SFXThreadPool >
|
class SFXThreadPool : public ThreadPool, public ManagedSingleton< SFXThreadPool >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef TorqueThreadPool Parent;
|
typedef ThreadPool Parent;
|
||||||
|
|
||||||
/// Create a ThreadPool called "SFX" with two threads.
|
/// Create a ThreadPool called "SFX" with two threads.
|
||||||
SFXThreadPool()
|
SFXThreadPool()
|
||||||
|
|
@ -399,7 +399,7 @@ extern ThreadSafeRef< SFXBufferProcessList > gBufferUpdateList;
|
||||||
extern ThreadSafeDeque< SFXBuffer* > gDeadBufferList;
|
extern ThreadSafeDeque< SFXBuffer* > gDeadBufferList;
|
||||||
|
|
||||||
/// Return the thread pool used for SFX work.
|
/// Return the thread pool used for SFX work.
|
||||||
inline TorqueThreadPool& THREAD_POOL()
|
inline ThreadPool& THREAD_POOL()
|
||||||
{
|
{
|
||||||
return *( SFXThreadPool::instance() );
|
return *( SFXThreadPool::instance() );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ FIXTURE(ThreadPool)
|
||||||
public:
|
public:
|
||||||
// Represents a single unit of work. In this test we just set an element in
|
// Represents a single unit of work. In this test we just set an element in
|
||||||
// a result vector.
|
// a result vector.
|
||||||
struct TestItem : public TorqueThreadPool::WorkItem
|
struct TestItem : public ThreadPool::WorkItem
|
||||||
{
|
{
|
||||||
U32 mIndex;
|
U32 mIndex;
|
||||||
Vector<U32>& mResults;
|
Vector<U32>& mResults;
|
||||||
|
|
@ -46,7 +46,7 @@ public:
|
||||||
|
|
||||||
// A worker that delays for some time. We'll use this to test the ThreadPool's
|
// A worker that delays for some time. We'll use this to test the ThreadPool's
|
||||||
// synchronous and asynchronous operations.
|
// synchronous and asynchronous operations.
|
||||||
struct DelayItem : public TorqueThreadPool::WorkItem
|
struct DelayItem : public ThreadPool::WorkItem
|
||||||
{
|
{
|
||||||
U32 ms;
|
U32 ms;
|
||||||
DelayItem(U32 _ms) : ms(_ms) {}
|
DelayItem(U32 _ms) : ms(_ms) {}
|
||||||
|
|
@ -69,7 +69,7 @@ TEST_FIX(ThreadPool, BasicAPI)
|
||||||
results[i] = U32(-1);
|
results[i] = U32(-1);
|
||||||
|
|
||||||
// Launch the work items.
|
// Launch the work items.
|
||||||
TorqueThreadPool* pool = &TorqueThreadPool::GLOBAL();
|
ThreadPool* pool = &ThreadPool::GLOBAL();
|
||||||
for (U32 i = 0; i < numItems; i++)
|
for (U32 i = 0; i < numItems; i++)
|
||||||
{
|
{
|
||||||
ThreadSafeRef<TestItem> item(new TestItem(i, results));
|
ThreadSafeRef<TestItem> item(new TestItem(i, results));
|
||||||
|
|
@ -89,7 +89,7 @@ TEST_FIX(ThreadPool, Asynchronous)
|
||||||
const U32 delay = 500; //ms
|
const U32 delay = 500; //ms
|
||||||
|
|
||||||
// Launch a single delaying work item.
|
// Launch a single delaying work item.
|
||||||
TorqueThreadPool* pool = &TorqueThreadPool::GLOBAL();
|
ThreadPool* pool = &ThreadPool::GLOBAL();
|
||||||
ThreadSafeRef<DelayItem> item(new DelayItem(delay));
|
ThreadSafeRef<DelayItem> item(new DelayItem(delay));
|
||||||
pool->queueWorkItem(item);
|
pool->queueWorkItem(item);
|
||||||
|
|
||||||
|
|
@ -107,7 +107,7 @@ TEST_FIX(ThreadPool, Synchronous)
|
||||||
const U32 delay = 500; //ms
|
const U32 delay = 500; //ms
|
||||||
|
|
||||||
// Launch a single delaying work item.
|
// Launch a single delaying work item.
|
||||||
TorqueThreadPool* pool = &TorqueThreadPool::GLOBAL();
|
ThreadPool* pool = &ThreadPool::GLOBAL();
|
||||||
ThreadSafeRef<DelayItem> item(new DelayItem(delay));
|
ThreadSafeRef<DelayItem> item(new DelayItem(delay));
|
||||||
pool->queueWorkItem(item);
|
pool->queueWorkItem(item);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue