OGRE  1.10.12
Object-Oriented Graphics Rendering Engine
Ogre::DefaultWorkQueue Class Reference

Implementation of a general purpose request / response style background work queue. More...

#include <OgreDefaultWorkQueueTBB.h>

+ Inheritance diagram for Ogre::DefaultWorkQueue:

Public Types

typedef unsigned long long int RequestID
 Numeric identifier for a request. More...
 

Public Member Functions

 DefaultWorkQueue (const String &name=BLANKSTRING)
 
 DefaultWorkQueue (const String &name=BLANKSTRING)
 
virtual ~DefaultWorkQueue ()
 
virtual ~DefaultWorkQueue (void)
 
virtual void _processNextRequest ()
 Process the next request on the queue. More...
 
void _registerThreadWithRenderSystem ()
 Register the current thread with the rendersystem. More...
 
virtual void _threadMain ()
 Main function for each thread spawned. More...
 
virtual void _threadMain ()
 Process the next request on the queue. More...
 
virtual void abortAllRequests ()
 Abort all previously issued requests. More...
 
virtual bool abortPendingRequest (RequestID id)
 Abort request if it is not being processed currently. More...
 
virtual void abortPendingRequestsByChannel (uint16 channel)
 Abort all previously issued requests in a given channel. More...
 
virtual void abortRequest (RequestID id)
 Abort a previously issued request. More...
 
virtual void abortRequestsByChannel (uint16 channel)
 Abort all previously issued requests in a given channel. More...
 
virtual RequestID addRequest (uint16 channel, uint16 requestType, const Any &rData, uint8 retryCount=0, bool forceSynchronous=false, bool idleThread=false)
 Add a new request to the queue. More...
 
virtual void addRequestHandler (uint16 channel, RequestHandler *rh)
 Add a request handler instance to the queue. More...
 
virtual void addResponseHandler (uint16 channel, ResponseHandler *rh)
 Add a response handler instance to the queue. More...
 
virtual uint16 getChannel (const String &channelName)
 Get a channel ID for a given channel name. More...
 
const StringgetName () const
 Get the name of the work queue. More...
 
virtual bool getRequestsAccepted () const
 Returns whether requests are being accepted right now. More...
 
virtual unsigned long getResponseProcessingTimeLimit () const
 Get the time limit imposed on the processing of responses in a single frame, in milliseconds (0 indicates no limit). More...
 
virtual bool getWorkersCanAccessRenderSystem () const
 Get whether worker threads will be allowed to access render system resources. More...
 
virtual size_t getWorkerThreadCount () const
 Get the number of worker threads that this queue will start when startup() is called. More...
 
virtual bool isPaused () const
 Return whether the queue is paused ie not sending more work to workers. More...
 
virtual bool isShuttingDown () const
 Returns whether the queue is trying to shut down. More...
 
virtual void processResponses ()
 Process the responses in the queue. More...
 
virtual void removeRequestHandler (uint16 channel, RequestHandler *rh)
 Remove a request handler. More...
 
virtual void removeResponseHandler (uint16 channel, ResponseHandler *rh)
 Remove a Response handler. More...
 
virtual void setPaused (bool pause)
 Set whether to pause further processing of any requests. More...
 
virtual void setRequestsAccepted (bool accept)
 Set whether to accept new requests or not. More...
 
virtual void setResponseProcessingTimeLimit (unsigned long ms)
 Set the time limit imposed on the processing of responses in a single frame, in milliseconds (0 indicates no limit). More...
 
virtual void setWorkersCanAccessRenderSystem (bool access)
 Set whether worker threads will be allowed to access render system resources. More...
 
virtual void setWorkerThreadCount (size_t c)
 Set the number of worker threads that this queue will start when startup() is called (default 1). More...
 
virtual void shutdown ()
 Shut down the queue. More...
 
virtual void shutdown ()
 Shut down the queue. More...
 
virtual void startup (bool forceRestart=true)
 Start up the queue with the options that have been set. More...
 
virtual void startup (bool forceRestart=true)
 Start up the queue with the options that have been set. More...
 

Detailed Description

Implementation of a general purpose request / response style background work queue.

Remarks
This default implementation of a work queue starts a thread pool and provides queues to process requests.
This implementation utilises tbb's task system for the WorkQueue implementation.

Member Typedef Documentation

◆ RequestID

typedef unsigned long long int Ogre::WorkQueue::RequestID
inherited

Numeric identifier for a request.

Constructor & Destructor Documentation

◆ DefaultWorkQueue() [1/2]

Ogre::DefaultWorkQueue::DefaultWorkQueue ( const String name = BLANKSTRING)

◆ ~DefaultWorkQueue() [1/2]

virtual Ogre::DefaultWorkQueue::~DefaultWorkQueue ( )
virtual

◆ DefaultWorkQueue() [2/2]

Ogre::DefaultWorkQueue::DefaultWorkQueue ( const String name = BLANKSTRING)

◆ ~DefaultWorkQueue() [2/2]

virtual Ogre::DefaultWorkQueue::~DefaultWorkQueue ( void  )
virtual

Member Function Documentation

◆ _threadMain() [1/2]

virtual void Ogre::DefaultWorkQueue::_threadMain ( )
virtual

Main function for each thread spawned.

Implements Ogre::DefaultWorkQueueBase.

◆ shutdown() [1/2]

virtual void Ogre::DefaultWorkQueue::shutdown ( )
virtual

Shut down the queue.

Implements Ogre::WorkQueue.

◆ startup() [1/2]

virtual void Ogre::DefaultWorkQueue::startup ( bool  forceRestart = true)
virtual

Start up the queue with the options that have been set.

Parameters
forceRestartIf the queue is already running, whether to shut it down and restart.

Implements Ogre::WorkQueue.

◆ _threadMain() [2/2]

virtual void Ogre::DefaultWorkQueue::_threadMain ( )
virtual

Process the next request on the queue.

Remarks
This method is public, but only intended for advanced users to call. The only reason you would call this, is if you were using your own thread to drive the worker processing. The thread calling this method will be the thread used to call the RequestHandler.Main function for each thread spawned.

Implements Ogre::DefaultWorkQueueBase.

◆ shutdown() [2/2]

virtual void Ogre::DefaultWorkQueue::shutdown ( )
virtual

Shut down the queue.

Implements Ogre::WorkQueue.

◆ startup() [2/2]

virtual void Ogre::DefaultWorkQueue::startup ( bool  forceRestart = true)
virtual

Start up the queue with the options that have been set.

Parameters
forceRestartIf the queue is already running, whether to shut it down and restart.

Implements Ogre::WorkQueue.

◆ _registerThreadWithRenderSystem()

void Ogre::DefaultWorkQueue::_registerThreadWithRenderSystem ( )

Register the current thread with the rendersystem.

◆ getName()

const String& Ogre::DefaultWorkQueueBase::getName ( ) const
inherited

Get the name of the work queue.

◆ getWorkerThreadCount()

virtual size_t Ogre::DefaultWorkQueueBase::getWorkerThreadCount ( ) const
virtualinherited

Get the number of worker threads that this queue will start when startup() is called.

◆ setWorkerThreadCount()

virtual void Ogre::DefaultWorkQueueBase::setWorkerThreadCount ( size_t  c)
virtualinherited

Set the number of worker threads that this queue will start when startup() is called (default 1).

Calling this will have no effect unless the queue is shut down and restarted.

◆ getWorkersCanAccessRenderSystem()

virtual bool Ogre::DefaultWorkQueueBase::getWorkersCanAccessRenderSystem ( ) const
virtualinherited

Get whether worker threads will be allowed to access render system resources.

Accessing render system resources from a separate thread can require that a context is maintained for that thread. Also, it requires that the render system is running in threadsafe mode, which only happens when OGRE_THREAD_SUPPORT=1. This option defaults to false, which means that threads can not use GPU resources, and the render system can work in non-threadsafe mode, which is more efficient.

◆ setWorkersCanAccessRenderSystem()

virtual void Ogre::DefaultWorkQueueBase::setWorkersCanAccessRenderSystem ( bool  access)
virtualinherited

Set whether worker threads will be allowed to access render system resources.

Accessing render system resources from a separate thread can require that a context is maintained for that thread. Also, it requires that the render system is running in threadsafe mode, which only happens when OGRE_THREAD_SUPPORT=1. This option defaults to false, which means that threads can not use GPU resources, and the render system can work in non-threadsafe mode, which is more efficient. Calling this will have no effect unless the queue is shut down and restarted.

◆ _processNextRequest()

virtual void Ogre::DefaultWorkQueueBase::_processNextRequest ( )
virtualinherited

Process the next request on the queue.

Remarks
This method is public, but only intended for advanced users to call. The only reason you would call this, is if you were using your own thread to drive the worker processing. The thread calling this method will be the thread used to call the RequestHandler.

◆ isShuttingDown()

virtual bool Ogre::DefaultWorkQueueBase::isShuttingDown ( ) const
inlinevirtualinherited

Returns whether the queue is trying to shut down.

◆ addRequestHandler()

virtual void Ogre::DefaultWorkQueueBase::addRequestHandler ( uint16  channel,
RequestHandler rh 
)
virtualinherited

Add a request handler instance to the queue.

Remarks
Every queue must have at least one request handler instance for each channel in which requests are raised. If you add more than one handler per channel, then you must implement canHandleRequest differently in each if you wish them to respond to different requests.
Parameters
channelThe channel for requests you want to handle
rhYour handler

Implements Ogre::WorkQueue.

◆ removeRequestHandler()

virtual void Ogre::DefaultWorkQueueBase::removeRequestHandler ( uint16  channel,
RequestHandler rh 
)
virtualinherited

Remove a request handler.

Implements Ogre::WorkQueue.

◆ addResponseHandler()

virtual void Ogre::DefaultWorkQueueBase::addResponseHandler ( uint16  channel,
ResponseHandler rh 
)
virtualinherited

Add a response handler instance to the queue.

Remarks
Every queue must have at least one response handler instance for each channel in which requests are raised. If you add more than one, then you must implement canHandleResponse differently in each if you wish them to respond to different responses.
Parameters
channelThe channel for responses you want to handle
rhYour handler

Implements Ogre::WorkQueue.

◆ removeResponseHandler()

virtual void Ogre::DefaultWorkQueueBase::removeResponseHandler ( uint16  channel,
ResponseHandler rh 
)
virtualinherited

Remove a Response handler.

Implements Ogre::WorkQueue.

◆ addRequest()

virtual RequestID Ogre::DefaultWorkQueueBase::addRequest ( uint16  channel,
uint16  requestType,
const Any rData,
uint8  retryCount = 0,
bool  forceSynchronous = false,
bool  idleThread = false 
)
virtualinherited

Add a new request to the queue.

Parameters
channelThe channel this request will go into = 0; the channel is the top-level categorisation of the request
requestTypeAn identifier that's unique within this queue which identifies the type of the request (user decides the actual value)
rDataThe data required by the request process.
retryCountThe number of times the request should be retried if it fails.
forceSynchronousForces the request to be processed immediately even if threading is enabled.
idleThreadRequest should be processed on the idle thread. Idle requests will be processed on a single worker thread. You should use this in the following situations:
  1. If a request handler can't process multiple requests in parallel.
  2. If you add lot of requests, but you want to keep the game fast.
  3. If you have lot of more important threads. (example: physics).
Returns
The ID of the request that has been added

Implements Ogre::WorkQueue.

◆ abortRequest()

virtual void Ogre::DefaultWorkQueueBase::abortRequest ( RequestID  id)
virtualinherited

Abort a previously issued request.

If the request is still waiting to be processed, it will be removed from the queue.

Parameters
idThe ID of the previously issued request.

Implements Ogre::WorkQueue.

◆ abortPendingRequest()

virtual bool Ogre::DefaultWorkQueueBase::abortPendingRequest ( RequestID  id)
virtualinherited

Abort request if it is not being processed currently.

Parameters
idThe ID of the previously issued request.
Return values
trueIf request was aborted successfully.
falseIf request is already being processed so it can not be aborted.

Implements Ogre::WorkQueue.

◆ abortRequestsByChannel()

virtual void Ogre::DefaultWorkQueueBase::abortRequestsByChannel ( uint16  channel)
virtualinherited

Abort all previously issued requests in a given channel.

Any requests still waiting to be processed of the given channel, will be removed from the queue. Requests which are processed, but response handler is not called will also be removed.

Parameters
channelThe type of request to be aborted

Implements Ogre::WorkQueue.

◆ abortPendingRequestsByChannel()

virtual void Ogre::DefaultWorkQueueBase::abortPendingRequestsByChannel ( uint16  channel)
virtualinherited

Abort all previously issued requests in a given channel.

Any requests still waiting to be processed of the given channel, will be removed from the queue. It will not remove requests, where the request handler is already called.

Parameters
channelThe type of request to be aborted

Implements Ogre::WorkQueue.

◆ abortAllRequests()

virtual void Ogre::DefaultWorkQueueBase::abortAllRequests ( )
virtualinherited

Abort all previously issued requests.

Any requests still waiting to be processed will be removed from the queue. Any requests that are being processed will still complete.

Implements Ogre::WorkQueue.

◆ setPaused()

virtual void Ogre::DefaultWorkQueueBase::setPaused ( bool  pause)
virtualinherited

Set whether to pause further processing of any requests.

If true, any further requests will simply be queued and not processed until setPaused(false) is called. Any requests which are in the process of being worked on already will still continue.

Implements Ogre::WorkQueue.

◆ isPaused()

virtual bool Ogre::DefaultWorkQueueBase::isPaused ( ) const
virtualinherited

Return whether the queue is paused ie not sending more work to workers.

Implements Ogre::WorkQueue.

◆ setRequestsAccepted()

virtual void Ogre::DefaultWorkQueueBase::setRequestsAccepted ( bool  accept)
virtualinherited

Set whether to accept new requests or not.

If true, requests are added to the queue as usual. If false, requests are silently ignored until setRequestsAccepted(true) is called.

Implements Ogre::WorkQueue.

◆ getRequestsAccepted()

virtual bool Ogre::DefaultWorkQueueBase::getRequestsAccepted ( ) const
virtualinherited

Returns whether requests are being accepted right now.

Implements Ogre::WorkQueue.

◆ processResponses()

virtual void Ogre::DefaultWorkQueueBase::processResponses ( )
virtualinherited

Process the responses in the queue.

Remarks
This method is public, and must be called from the main render thread to 'pump' responses through the system. The method will usually try to clear all responses before returning = 0; however, you can specify a time limit on the response processing to limit the impact of spikes in demand by calling setResponseProcessingTimeLimit.

Implements Ogre::WorkQueue.

◆ getResponseProcessingTimeLimit()

virtual unsigned long Ogre::DefaultWorkQueueBase::getResponseProcessingTimeLimit ( ) const
inlinevirtualinherited

Get the time limit imposed on the processing of responses in a single frame, in milliseconds (0 indicates no limit).

Implements Ogre::WorkQueue.

◆ setResponseProcessingTimeLimit()

virtual void Ogre::DefaultWorkQueueBase::setResponseProcessingTimeLimit ( unsigned long  ms)
inlinevirtualinherited

Set the time limit imposed on the processing of responses in a single frame, in milliseconds (0 indicates no limit).

This sets the maximum time that will be spent in processResponses() in a single frame. The default is 8ms.

Implements Ogre::WorkQueue.

References Ogre::WorkQueue::RequestHandler::canHandleRequest(), Ogre::WorkQueue::RequestHandler::handleRequest(), OGRE_WQ_LOCK_RW_MUTEX_READ, OGRE_WQ_LOCK_RW_MUTEX_WRITE, OGRE_WQ_MUTEX, and OGRE_WQ_RW_MUTEX.

◆ getChannel()

virtual uint16 Ogre::WorkQueue::getChannel ( const String channelName)
virtualinherited

Get a channel ID for a given channel name.

Remarks
Channels are assigned on a first-come, first-served basis and are not persistent across application instances. This method allows applications to not worry about channel clashes through manually assigned channel numbers.

The documentation for this class was generated from the following files: