diff --git a/include/osgParticle/ParticleSystem b/include/osgParticle/ParticleSystem index 6617adbf6..ba7ccda96 100644 --- a/include/osgParticle/ParticleSystem +++ b/include/osgParticle/ParticleSystem @@ -30,7 +30,17 @@ #include #include -#include +// 9th Febrary 2009, disabled the use of ReadWriteMutex as it looks like this +// is introducing threading problems due to threading problems in OpenThreads::ReadWriteMutex. +// #define OSGPARTICLE_USE_ReadWriteMutex + +#ifdef OSGPARTICLE_USE_ReadWriteMutex + #include +#else + #include + #include +#endif + namespace osgParticle { @@ -182,7 +192,17 @@ namespace osgParticle virtual osg::BoundingBox computeBound() const; - OpenThreads::ReadWriteMutex* getReadWriteMutex() const { return &_readWriteMutex; } +#ifdef OSGPARTICLE_USE_ReadWriteMutex + typedef OpenThreads::ReadWriteMutex ReadWriterMutex; + typedef OpenThreads::ScopedReadLock ScopedReadLock; + typedef OpenThreads::ScopedWriteLock ScopedWriteLock; +#else + typedef OpenThreads::Mutex ReadWriterMutex; + typedef OpenThreads::ScopedLock ScopedReadLock; + typedef OpenThreads::ScopedLock ScopedWriteLock; +#endif + + ReadWriterMutex* getReadWriteMutex() const { return &_readWriteMutex; } protected: @@ -222,8 +242,7 @@ namespace osgParticle int _detail; mutable int _draw_count; - mutable OpenThreads::ReadWriteMutex _readWriteMutex; - + mutable ReadWriterMutex _readWriteMutex; }; // INLINE FUNCTIONS diff --git a/src/osgParticle/ConnectedParticleSystem.cpp b/src/osgParticle/ConnectedParticleSystem.cpp index 2c673eb1b..9b2ef69e6 100644 --- a/src/osgParticle/ConnectedParticleSystem.cpp +++ b/src/osgParticle/ConnectedParticleSystem.cpp @@ -116,7 +116,7 @@ void ConnectedParticleSystem::drawImplementation(osg::RenderInfo& renderInfo) co { osg::State& state = *renderInfo.getState(); - OpenThreads::ScopedReadLock lock(_readWriteMutex); + ScopedReadLock lock(_readWriteMutex); const Particle* particle = (_startParticle != Particle::INVALID_INDEX) ? &_particles[_startParticle] : 0; if (!particle) return; diff --git a/src/osgParticle/ParticleProcessor.cpp b/src/osgParticle/ParticleProcessor.cpp index e19313ee7..47e8d9249 100644 --- a/src/osgParticle/ParticleProcessor.cpp +++ b/src/osgParticle/ParticleProcessor.cpp @@ -64,7 +64,7 @@ void osgParticle::ParticleProcessor::traverse(osg::NodeVisitor& nv) { if (nv.getFrameStamp()) { - OpenThreads::ScopedWriteLock lock(*(_ps->getReadWriteMutex())); + ParticleSystem::ScopedWriteLock lock(*(_ps->getReadWriteMutex())); //added- 1/17/06- bgandere@nps.edu //a check to make sure we havent updated yet this frame diff --git a/src/osgParticle/ParticleSystem.cpp b/src/osgParticle/ParticleSystem.cpp index d768e0471..d37ea2ebf 100644 --- a/src/osgParticle/ParticleSystem.cpp +++ b/src/osgParticle/ParticleSystem.cpp @@ -96,7 +96,7 @@ void osgParticle::ParticleSystem::drawImplementation(osg::RenderInfo& renderInfo { osg::State& state = *renderInfo.getState(); - OpenThreads::ScopedReadLock lock(_readWriteMutex); + ScopedReadLock lock(_readWriteMutex); // update the frame count, so other objects can detect when // this particle system is culled diff --git a/src/osgParticle/ParticleSystemUpdater.cpp b/src/osgParticle/ParticleSystemUpdater.cpp index 04aa1990f..41e8f2f60 100644 --- a/src/osgParticle/ParticleSystemUpdater.cpp +++ b/src/osgParticle/ParticleSystemUpdater.cpp @@ -40,7 +40,7 @@ void osgParticle::ParticleSystemUpdater::traverse(osg::NodeVisitor& nv) { ParticleSystem* ps = i->get(); - OpenThreads::ScopedWriteLock lock(*(ps->getReadWriteMutex())); + ParticleSystem::ScopedWriteLock lock(*(ps->getReadWriteMutex())); if (!ps->isFrozen() && (ps->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !ps->getFreezeOnCull())) { diff --git a/src/osgWrappers/osgParticle/ParticleSystem.cpp b/src/osgWrappers/osgParticle/ParticleSystem.cpp index ff43b575d..315d27444 100644 --- a/src/osgWrappers/osgParticle/ParticleSystem.cpp +++ b/src/osgWrappers/osgParticle/ParticleSystem.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include #include @@ -27,6 +27,12 @@ #undef OUT #endif +TYPE_NAME_ALIAS(OpenThreads::Mutex, osgParticle::ParticleSystem::ReadWriterMutex) + +TYPE_NAME_ALIAS(OpenThreads::ScopedLock< OpenThreads::Mutex >, osgParticle::ParticleSystem::ScopedReadLock) + +TYPE_NAME_ALIAS(OpenThreads::ScopedLock< OpenThreads::Mutex >, osgParticle::ParticleSystem::ScopedWriteLock) + BEGIN_ENUM_REFLECTOR(osgParticle::ParticleSystem::Alignment) I_DeclaringFile("osgParticle/ParticleSystem"); I_EnumLabel(osgParticle::ParticleSystem::BILLBOARD); @@ -249,9 +255,9 @@ BEGIN_OBJECT_REFLECTOR(osgParticle::ParticleSystem) __osg_BoundingBox__computeBound, "Compute the bounding box around Drawables's geometry. ", ""); - I_Method0(OpenThreads::ReadWriteMutex *, getReadWriteMutex, + I_Method0(osgParticle::ParticleSystem::ReadWriterMutex *, getReadWriteMutex, Properties::NON_VIRTUAL, - __OpenThreads_ReadWriteMutex_P1__getReadWriteMutex, + __ReadWriterMutex_P1__getReadWriteMutex, "", ""); I_ProtectedMethod2(void, update_bounds, IN, const osg::Vec3 &, p, IN, float, r, @@ -299,8 +305,17 @@ BEGIN_OBJECT_REFLECTOR(osgParticle::ParticleSystem) I_SimpleProperty(osgParticle::ParticleSystem::ParticleScaleReferenceFrame, ParticleScaleReferenceFrame, __ParticleScaleReferenceFrame__getParticleScaleReferenceFrame, __void__setParticleScaleReferenceFrame__ParticleScaleReferenceFrame); - I_SimpleProperty(OpenThreads::ReadWriteMutex *, ReadWriteMutex, - __OpenThreads_ReadWriteMutex_P1__getReadWriteMutex, + I_SimpleProperty(osgParticle::ParticleSystem::ReadWriterMutex *, ReadWriteMutex, + __ReadWriterMutex_P1__getReadWriteMutex, 0); END_REFLECTOR +BEGIN_VALUE_REFLECTOR(OpenThreads::ScopedLock< OpenThreads::Mutex >) + I_DeclaringFile("OpenThreads/ScopedLock"); + I_Constructor1(IN, OpenThreads::Mutex &, m, + Properties::EXPLICIT, + ____ScopedLock__M_R1, + "", + ""); +END_REFLECTOR +