Added OperationQueue class for future work on support thread pools that share

a single OpeationQueue.
This commit is contained in:
Robert Osfield 2007-07-09 11:03:33 +00:00
parent e8f8c0c147
commit d70228c98d

View File

@ -35,13 +35,13 @@ class RefBlock: virtual public osg::Referenced, public OpenThreads::Block
};
/** Base class for implementing graphics operations.*/
struct Operation : virtual public Referenced
class Operation : virtual public Referenced
{
public:
Operation(const std::string& name, bool keep):
_name(name),
_keep(keep) {}
virtual ~Operation() {}
/** Set the human readable name of the operation.*/
void setName(const std::string& name) { _name = name; }
@ -61,10 +61,49 @@ struct Operation : virtual public Referenced
/** Do the actual task of this operation.*/
virtual void operator () (Object*) = 0;
protected:
virtual ~Operation() {}
std::string _name;
bool _keep;
};
class OSG_EXPORT OperationQueue : public Referenced
{
public:
OperationQueue();
RefBlock* getOperationsBlock() { return _operationsBlock.get(); }
const RefBlock* getOperationsBlock() const { return _operationsBlock.get(); }
/** Add operation to end of OperationQueue, this will be
* executed by the operation thread once this operation gets to the head of the queue.*/
void add(Operation* operation);
/** Remove operation from OperationQueue.*/
void remove(Operation* operation);
/** Remove named operation from OperationQueue.*/
void remove(const std::string& name);
/** Remove all operations from OperationQueue.*/
void removeAllOperations();
protected:
virtual ~OperationQueue();
typedef std::list< ref_ptr<Operation> > Operations;
OpenThreads::Mutex _operationsMutex;
osg::ref_ptr<osg::RefBlock> _operationsBlock;
Operations _operations;
};
/** GraphicsThread is a helper class for running OpenGL GraphicsOperation within a single thread assigned to a specific GraphicsContext.*/
class OSG_EXPORT OperationsThread : public Referenced, public OpenThreads::Thread
{
@ -110,13 +149,13 @@ class OSG_EXPORT OperationsThread : public Referenced, public OpenThreads::Threa
observer_ptr<Object> _parent;
typedef std::list< ref_ptr<Operation> > OperationQueue;
typedef std::list< ref_ptr<Operation> > Operations;
bool _done;
OpenThreads::Mutex _operationsMutex;
osg::ref_ptr<osg::RefBlock> _operationsBlock;
OperationQueue _operations;
Operations _operations;
osg::ref_ptr<Operation> _currentOperation;
};