Skip to content

Commit

Permalink
To address a thread related crash reported in osgParticle changed the…
Browse files Browse the repository at this point in the history
… ParticleSystem

to have an optional compile path for either using a OpenThreads::ReadWriteMutex or an 
OpenThreads::Mutex as it's base implementation, with the Mutex now being used by default.
  • Loading branch information
robertosfield committed Feb 9, 2009
1 parent 5a15b61 commit aa8870a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
27 changes: 23 additions & 4 deletions include/osgParticle/ParticleSystem
Expand Up @@ -30,7 +30,17 @@
#include <osg/Vec3>
#include <osg/BoundingBox>

#include <OpenThreads/ReadWriteMutex>
// 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 <OpenThreads/ReadWriteMutex>
#else
#include <OpenThreads/Mutex>
#include <OpenThreads/ScopedLock>
#endif


namespace osgParticle
{
Expand Down Expand Up @@ -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<OpenThreads::Mutex> ScopedReadLock;
typedef OpenThreads::ScopedLock<OpenThreads::Mutex> ScopedWriteLock;
#endif

ReadWriterMutex* getReadWriteMutex() const { return &_readWriteMutex; }

protected:

Expand Down Expand Up @@ -222,8 +242,7 @@ namespace osgParticle
int _detail;
mutable int _draw_count;

mutable OpenThreads::ReadWriteMutex _readWriteMutex;

mutable ReadWriterMutex _readWriteMutex;
};

// INLINE FUNCTIONS
Expand Down
2 changes: 1 addition & 1 deletion src/osgParticle/ConnectedParticleSystem.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/osgParticle/ParticleProcessor.cpp
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/osgParticle/ParticleSystem.cpp
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/osgParticle/ParticleSystemUpdater.cpp
Expand Up @@ -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()))
{
Expand Down
25 changes: 20 additions & 5 deletions src/osgWrappers/osgParticle/ParticleSystem.cpp
Expand Up @@ -10,7 +10,7 @@
#include <osgIntrospection/StaticMethodInfo>
#include <osgIntrospection/Attributes>

#include <OpenThreads/ReadWriteMutex>
#include <OpenThreads/Mutex>
#include <osg/BoundingBox>
#include <osg/CopyOp>
#include <osg/Object>
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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

0 comments on commit aa8870a

Please sign in to comment.