From c8c693db53abb8c71f253e0f8698c457a2c74edf Mon Sep 17 00:00:00 2001 From: timoore Date: Thu, 12 Jun 2008 08:14:40 +0000 Subject: [PATCH] From Benoit Laniel: replace SG threading constructs with those from OpenThreads Also, move any static local mutexes up to global level. --- simgear/scene/model/ModelRegistry.cxx | 7 +++++-- simgear/scene/model/animation.cxx | 11 +++++++---- simgear/scene/model/shadanim.cxx | 19 +++++++++++++------ simgear/scene/tgdb/obj.cxx | 2 -- simgear/scene/tgdb/pt_lights.cxx | 13 +++++++++---- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/simgear/scene/model/ModelRegistry.cxx b/simgear/scene/model/ModelRegistry.cxx index 6eef53aa..6b44a055 100644 --- a/simgear/scene/model/ModelRegistry.cxx +++ b/simgear/scene/model/ModelRegistry.cxx @@ -56,6 +56,9 @@ using namespace osgUtil; using namespace osgDB; using namespace simgear; +using OpenThreads::ReentrantMutex; +using OpenThreads::ScopedLock; + // Little helper class that holds an extra reference to a // loaded 3d model. // Since we clone all structural nodes from our 3d models, @@ -324,7 +327,7 @@ ReaderWriter::ReadResult ModelRegistry::readImage(const string& fileName, const ReaderWriter::Options* opt) { - OpenThreads::ScopedLock lock(readerMutex); + ScopedLock lock(readerMutex); CallbackMap::iterator iter = imageCallbackMap.find(getFileExtension(fileName)); // XXX Workaround for OSG plugin bug @@ -484,7 +487,7 @@ ReaderWriter::ReadResult ModelRegistry::readNode(const string& fileName, const ReaderWriter::Options* opt) { - OpenThreads::ScopedLock lock(readerMutex); + ScopedLock lock(readerMutex); // XXX Workaround for OSG plugin bug. OptionsPusher pusher(opt); Registry* registry = Registry::instance(); diff --git a/simgear/scene/model/animation.cxx b/simgear/scene/model/animation.cxx index 4d9c7731..1dd74cc9 100644 --- a/simgear/scene/model/animation.cxx +++ b/simgear/scene/model/animation.cxx @@ -47,6 +47,10 @@ #include "SGRotateTransform.hxx" #include "SGScaleTransform.hxx" +using OpenThreads::Mutex; +using OpenThreads::ReentrantMutex; +using OpenThreads::ScopedLock; + //////////////////////////////////////////////////////////////////////// // Static utility functions. @@ -931,12 +935,12 @@ SGScaleAnimation::createAnimationGroup(osg::Group& parent) namespace { -OpenThreads::Mutex normalizeMutex; +Mutex normalizeMutex; osg::StateSet* getNormalizeStateSet() { static osg::ref_ptr normalizeStateSet; - OpenThreads::ScopedLock lock(normalizeMutex); + ScopedLock lock(normalizeMutex); if (!normalizeStateSet.valid()) { normalizeStateSet = new osg::StateSet; normalizeStateSet->setMode(GL_NORMALIZE, osg::StateAttribute::ON); @@ -1387,13 +1391,12 @@ SGAlphaTestAnimation::SGAlphaTestAnimation(const SGPropertyNode* configNode, namespace { // Keep one copy of the most common alpha test its state set. -OpenThreads::ReentrantMutex alphaTestMutex; +ReentrantMutex alphaTestMutex; osg::ref_ptr standardAlphaFunc; osg::ref_ptr alphaFuncStateSet; osg::AlphaFunc* makeAlphaFunc(float clamp) { - using namespace OpenThreads; ScopedLock lock(alphaTestMutex); if (osg::equivalent(clamp, 0.01f)) { if (standardAlphaFunc.valid()) diff --git a/simgear/scene/model/shadanim.cxx b/simgear/scene/model/shadanim.cxx index 1eae56de..9f94730d 100644 --- a/simgear/scene/model/shadanim.cxx +++ b/simgear/scene/model/shadanim.cxx @@ -36,9 +36,10 @@ #include #include +#include +#include + #include -#include -#include #include #include @@ -47,6 +48,10 @@ #include "animation.hxx" #include "model.hxx" + +using OpenThreads::Mutex; +using OpenThreads::ScopedLock; + /* shader @@ -125,6 +130,8 @@ private: SGVec4f _lastLightColor; }; +static Mutex cubeMutex; + static osg::TextureCubeMap* getOrCreateTextureCubeMap() { @@ -132,8 +139,7 @@ getOrCreateTextureCubeMap() if (textureCubeMap.get()) return textureCubeMap.get(); - static SGMutex mutex; - SGGuard locker(mutex); + ScopedLock lock(cubeMutex); if (textureCubeMap.get()) return textureCubeMap.get(); @@ -212,13 +218,14 @@ typedef std::map, osg::ref_ptr > StateSetMap; } +static Mutex chromeMutex; + // The chrome effect is mixed by the alpha channel of the texture // on the model, which will be attached to a node lower in the scene // graph: 0 -> completely chrome, 1 -> completely model texture. static void create_chrome(osg::Group* group, osg::Texture2D* texture) { - static SGMutex mutex; - SGGuard locker(mutex); + ScopedLock lock(chromeMutex); static StateSetMap chromeMap; osg::StateSet *stateSet; StateSetMap::iterator iterator = chromeMap.find(texture); diff --git a/simgear/scene/tgdb/obj.cxx b/simgear/scene/tgdb/obj.cxx index dbfd660a..da21d9f1 100644 --- a/simgear/scene/tgdb/obj.cxx +++ b/simgear/scene/tgdb/obj.cxx @@ -50,8 +50,6 @@ #include #include #include -#include -#include #include "SGTexturedTriangleBin.hxx" #include "SGLightBin.hxx" diff --git a/simgear/scene/tgdb/pt_lights.cxx b/simgear/scene/tgdb/pt_lights.cxx index e5c9a19c..274a4e18 100644 --- a/simgear/scene/tgdb/pt_lights.cxx +++ b/simgear/scene/tgdb/pt_lights.cxx @@ -50,15 +50,19 @@ #include +#include +#include + #include #include -#include -#include #include #include #include "SGVasiDrawable.hxx" +using OpenThreads::Mutex; +using OpenThreads::ScopedLock; + using namespace simgear; static void @@ -123,6 +127,8 @@ getPointSpriteImage(int logResolution) return image; } +static Mutex lightMutex; + static osg::Texture2D* gen_standard_light_sprite(void) { @@ -131,8 +137,7 @@ gen_standard_light_sprite(void) if (texture.valid()) return texture.get(); - static SGMutex mutex; - SGGuard guard(mutex); + ScopedLock lock(lightMutex); if (texture.valid()) return texture.get(); -- 2.39.5