Moved Block, ReentrantMutex and ReadWriteMutex into OpenThreads.

This commit is contained in:
Robert Osfield
2007-02-23 16:31:34 +00:00
parent 968a8d1118
commit ad3cac84e9
30 changed files with 67 additions and 343 deletions

View File

@@ -20,58 +20,18 @@
#include <OpenThreads/Thread>
#include <OpenThreads/Barrier>
#include <OpenThreads/Condition>
#include <OpenThreads/Block>
#include <list>
namespace osg {
class Block: virtual public osg::Referenced {
class RefBlock: virtual public osg::Referenced, public OpenThreads::Block
{
public:
Block():_released(false) {}
inline void block()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> mutlock(_mut);
if( !_released )
_cond.wait(&_mut);
}
RefBlock() {}
inline void release()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> mutlock(_mut);
if (!_released)
{
_released = true;
_cond.broadcast();
}
}
inline void reset()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> mutlock(_mut);
_released = false;
}
inline void set(bool doRelease)
{
if (doRelease!=_released)
{
if (doRelease) release();
else reset();
}
}
protected:
~Block()
{
release();
}
private:
OpenThreads::Mutex _mut;
OpenThreads::Condition _cond;
bool _released;
};
/** Base class for implementing graphics operations.*/
@@ -155,7 +115,7 @@ class OSG_EXPORT OperationsThread : public Referenced, public OpenThreads::Threa
bool _done;
OpenThreads::Mutex _operationsMutex;
osg::ref_ptr<osg::Block> _operationsBlock;
osg::ref_ptr<osg::RefBlock> _operationsBlock;
OperationQueue _operations;
osg::ref_ptr<Operation> _currentOperation;
@@ -195,7 +155,7 @@ struct OSG_EXPORT BarrierOperation : public Operation, public OpenThreads::Barri
/** ReleaseContext_Block_MakeCurrentOperation releases the context for another thread to aquire,
* then blocks waiting for context to be released, once the block is release the context is re-aqquired.*/
struct OSG_EXPORT ReleaseContext_Block_MakeCurrentOperation : public Operation, public Block
struct OSG_EXPORT ReleaseContext_Block_MakeCurrentOperation : public Operation, public RefBlock
{
ReleaseContext_Block_MakeCurrentOperation():
Operation("ReleaseContext_Block_MakeCurrent", false) {}