Main Page Modules Namespaces C++ Classes Compound List File List Index
TNL::ThreadQueue class Reference

TNL::ThreadQueue Class Reference

#include <tnlThread.h>

Inheritance diagram for TNL::ThreadQueue:

TNL::Object

Detailed Description

Managing object for a queue of worker threads that pass messages back and forth to the main thread.

ThreadQueue methods declared with the TNL_DECLARE_THREADQ_METHOD macro are special -- if they are called from the main thread, they will be executed on one of the worker threads and vice versa.


Public Member Functions

 ThreadQueue (U32 threadCount)
 ThreadQueue constructor. threadCount specifies the number of worker threads that will be created.

 ~ThreadQueue ()
void dispatchResponseCalls ()
 Dispatches all ThreadQueue calls queued by worker threads.


Protected Member Functions

void lock ()
 Locks the ThreadQueue for access to member variables.

void unlock ()
 Unlocks the ThreadQueue.

void postCall (Functor *theCall)
 Posts a marshalled call onto either the worker thread call list or the response call list.

void dispatchNextCall ()
 Dispatches the next available worker thread call. Called internally by the worker threads when they awaken from the semaphore.

bool isMainThread ()
 helper function to determine if the currently executing thread is a worker thread or the main thread.

ThreadStoragegetStorage ()
virtual void threadStart ()
 called by each worker thread when it starts for subclass initialization of worker threads.


Private Attributes

Vector< Thread * > mThreads
 list of worker threads on this ThreadQueue

Vector< Functor * > mThreadCalls
 list of calls to be processed by the worker threads

Vector< Functor * > mResponseCalls
 list of calls to be processed by the main thread

Semaphore mSemaphore
 Synchronization variable that manages worker threads.

Mutex mLock
 Internal Mutex for synchronizing access to thread call vectors.

ThreadStorage mStorage
 Storage variable that tracks whether this is the main thread or a worker thread.


Friends

class ThreadQueueThread


Constructor & Destructor Documentation

TNL::ThreadQueue::ThreadQueue U32  threadCount  ) 
 

ThreadQueue constructor. threadCount specifies the number of worker threads that will be created.

TNL::ThreadQueue::~ThreadQueue  ) 
 


Member Function Documentation

void TNL::ThreadQueue::lock  )  [inline, protected]
 

Locks the ThreadQueue for access to member variables.

void TNL::ThreadQueue::unlock  )  [inline, protected]
 

Unlocks the ThreadQueue.

void TNL::ThreadQueue::postCall Functor theCall  )  [protected]
 

Posts a marshalled call onto either the worker thread call list or the response call list.

void TNL::ThreadQueue::dispatchNextCall  )  [protected]
 

Dispatches the next available worker thread call. Called internally by the worker threads when they awaken from the semaphore.

bool TNL::ThreadQueue::isMainThread  )  [inline, protected]
 

helper function to determine if the currently executing thread is a worker thread or the main thread.

ThreadStorage& TNL::ThreadQueue::getStorage  )  [inline, protected]
 

virtual void TNL::ThreadQueue::threadStart  )  [inline, protected, virtual]
 

called by each worker thread when it starts for subclass initialization of worker threads.

void TNL::ThreadQueue::dispatchResponseCalls  ) 
 

Dispatches all ThreadQueue calls queued by worker threads.

This should be called periodically from a main loop.


Friends And Related Function Documentation

friend class ThreadQueueThread [friend]
 


Field Documentation

Vector<Thread *> TNL::ThreadQueue::mThreads [private]
 

list of worker threads on this ThreadQueue

Vector<Functor *> TNL::ThreadQueue::mThreadCalls [private]
 

list of calls to be processed by the worker threads

Vector<Functor *> TNL::ThreadQueue::mResponseCalls [private]
 

list of calls to be processed by the main thread

Semaphore TNL::ThreadQueue::mSemaphore [private]
 

Synchronization variable that manages worker threads.

Mutex TNL::ThreadQueue::mLock [private]
 

Internal Mutex for synchronizing access to thread call vectors.

ThreadStorage TNL::ThreadQueue::mStorage [private]
 

Storage variable that tracks whether this is the main thread or a worker thread.