]> git.mxchange.org Git - simgear.git/commitdiff
From Benoit Laniel: replace SG threading constructs with those from OpenThreads
authortimoore <timoore>
Thu, 12 Jun 2008 08:14:40 +0000 (08:14 +0000)
committertimoore <timoore>
Thu, 12 Jun 2008 08:14:40 +0000 (08:14 +0000)
Also, move any static local mutexes up to global level.

simgear/scene/model/ModelRegistry.cxx
simgear/scene/model/animation.cxx
simgear/scene/model/shadanim.cxx
simgear/scene/tgdb/obj.cxx
simgear/scene/tgdb/pt_lights.cxx

index 6eef53aae64bcc7df4b6260f6aaeb0eaa73dec7d..6b44a0555b2901bf7ae9505c2fb1f0f993f966c8 100644 (file)
@@ -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<OpenThreads::ReentrantMutex> lock(readerMutex);
+    ScopedLock<ReentrantMutex> 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<OpenThreads::ReentrantMutex> lock(readerMutex);
+    ScopedLock<ReentrantMutex> lock(readerMutex);
     // XXX Workaround for OSG plugin bug.
     OptionsPusher pusher(opt);
     Registry* registry = Registry::instance();
index 4d9c77312b9d7e856629b4eb2a969f5dae19df9a..1dd74cc9baead72141dce8364ca3660a100211a3 100644 (file)
 #include "SGRotateTransform.hxx"
 #include "SGScaleTransform.hxx"
 
+using OpenThreads::Mutex;
+using OpenThreads::ReentrantMutex;
+using OpenThreads::ScopedLock;
+
 \f
 ////////////////////////////////////////////////////////////////////////
 // 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<osg::StateSet> normalizeStateSet;
-    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(normalizeMutex);
+    ScopedLock<Mutex> 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<osg::AlphaFunc> standardAlphaFunc;
 osg::ref_ptr<osg::StateSet> alphaFuncStateSet;
 
 osg::AlphaFunc* makeAlphaFunc(float clamp)
 {
-    using namespace OpenThreads;
     ScopedLock<ReentrantMutex> lock(alphaTestMutex);
     if (osg::equivalent(clamp, 0.01f)) {
         if (standardAlphaFunc.valid())
index 1eae56de7602523f5bf8016ff4c445ee4f963df3..9f94730df5687f824b82982ee260309d25258c61 100644 (file)
 #include <osg/Texture1D>
 #include <osgUtil/HighlightMapGenerator>
 
+#include <OpenThreads/Mutex>
+#include <OpenThreads/ScopedLock>
+
 #include <simgear/scene/util/SGUpdateVisitor.hxx>
-#include <simgear/threads/SGThread.hxx>
-#include <simgear/threads/SGGuard.hxx>
 
 #include <simgear/props/condition.hxx>
 #include <simgear/props/props.hxx>
 
 #include "animation.hxx"
 #include "model.hxx"
+
+using OpenThreads::Mutex;
+using OpenThreads::ScopedLock;
+
 /*
     <animation>
         <type>shader</type>
@@ -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<SGMutex> locker(mutex);
+  ScopedLock<Mutex> lock(cubeMutex);
   if (textureCubeMap.get())
     return textureCubeMap.get();
 
@@ -212,13 +218,14 @@ typedef std::map<osg::ref_ptr<osg::Texture2D>, osg::ref_ptr<osg::StateSet> >
 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<SGMutex> locker(mutex);
+    ScopedLock<Mutex> lock(chromeMutex);
     static StateSetMap chromeMap;
     osg::StateSet *stateSet;
     StateSetMap::iterator iterator = chromeMap.find(texture);
index dbfd660a58a3cd0761a9de23b9e6f88df9c283e3..da21d9f16f05f77572b62ed71fae913753693a3f 100644 (file)
@@ -50,8 +50,6 @@
 #include <simgear/scene/util/SGUpdateVisitor.hxx>
 #include <simgear/scene/util/SGNodeMasks.hxx>
 #include <simgear/scene/util/QuadTreeBuilder.hxx>
-#include <simgear/threads/SGThread.hxx>
-#include <simgear/threads/SGGuard.hxx>
 
 #include "SGTexturedTriangleBin.hxx"
 #include "SGLightBin.hxx"
index e5c9a19cd6504daa2d404c6f4b983efa9728efa0..274a4e1873054e609192e9b7f8bd157e4e97be45 100644 (file)
 
 #include <osgUtil/CullVisitor>
 
+#include <OpenThreads/Mutex>
+#include <OpenThreads/ScopedLock>
+
 #include <simgear/math/sg_random.h>
 #include <simgear/debug/logstream.hxx>
-#include <simgear/threads/SGThread.hxx>
-#include <simgear/threads/SGGuard.hxx>
 #include <simgear/scene/util/RenderConstants.hxx>
 #include <simgear/scene/util/SGEnlargeBoundingBox.hxx>
 
 #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<SGMutex> guard(mutex);
+  ScopedLock<Mutex> lock(lightMutex);
   if (texture.valid())
     return texture.get();