From Benoit Laniel: replace SG threading constructs with those from OpenThreads
Also, move any static local mutexes up to global level.
This commit is contained in:
@@ -56,6 +56,9 @@ using namespace osgUtil;
|
|||||||
using namespace osgDB;
|
using namespace osgDB;
|
||||||
using namespace simgear;
|
using namespace simgear;
|
||||||
|
|
||||||
|
using OpenThreads::ReentrantMutex;
|
||||||
|
using OpenThreads::ScopedLock;
|
||||||
|
|
||||||
// Little helper class that holds an extra reference to a
|
// Little helper class that holds an extra reference to a
|
||||||
// loaded 3d model.
|
// loaded 3d model.
|
||||||
// Since we clone all structural nodes from our 3d models,
|
// Since we clone all structural nodes from our 3d models,
|
||||||
@@ -324,7 +327,7 @@ ReaderWriter::ReadResult
|
|||||||
ModelRegistry::readImage(const string& fileName,
|
ModelRegistry::readImage(const string& fileName,
|
||||||
const ReaderWriter::Options* opt)
|
const ReaderWriter::Options* opt)
|
||||||
{
|
{
|
||||||
OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(readerMutex);
|
ScopedLock<ReentrantMutex> lock(readerMutex);
|
||||||
CallbackMap::iterator iter
|
CallbackMap::iterator iter
|
||||||
= imageCallbackMap.find(getFileExtension(fileName));
|
= imageCallbackMap.find(getFileExtension(fileName));
|
||||||
// XXX Workaround for OSG plugin bug
|
// XXX Workaround for OSG plugin bug
|
||||||
@@ -484,7 +487,7 @@ ReaderWriter::ReadResult
|
|||||||
ModelRegistry::readNode(const string& fileName,
|
ModelRegistry::readNode(const string& fileName,
|
||||||
const ReaderWriter::Options* opt)
|
const ReaderWriter::Options* opt)
|
||||||
{
|
{
|
||||||
OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(readerMutex);
|
ScopedLock<ReentrantMutex> lock(readerMutex);
|
||||||
// XXX Workaround for OSG plugin bug.
|
// XXX Workaround for OSG plugin bug.
|
||||||
OptionsPusher pusher(opt);
|
OptionsPusher pusher(opt);
|
||||||
Registry* registry = Registry::instance();
|
Registry* registry = Registry::instance();
|
||||||
|
|||||||
@@ -47,6 +47,10 @@
|
|||||||
#include "SGRotateTransform.hxx"
|
#include "SGRotateTransform.hxx"
|
||||||
#include "SGScaleTransform.hxx"
|
#include "SGScaleTransform.hxx"
|
||||||
|
|
||||||
|
using OpenThreads::Mutex;
|
||||||
|
using OpenThreads::ReentrantMutex;
|
||||||
|
using OpenThreads::ScopedLock;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Static utility functions.
|
// Static utility functions.
|
||||||
@@ -931,12 +935,12 @@ SGScaleAnimation::createAnimationGroup(osg::Group& parent)
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
OpenThreads::Mutex normalizeMutex;
|
Mutex normalizeMutex;
|
||||||
|
|
||||||
osg::StateSet* getNormalizeStateSet()
|
osg::StateSet* getNormalizeStateSet()
|
||||||
{
|
{
|
||||||
static osg::ref_ptr<osg::StateSet> normalizeStateSet;
|
static osg::ref_ptr<osg::StateSet> normalizeStateSet;
|
||||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(normalizeMutex);
|
ScopedLock<Mutex> lock(normalizeMutex);
|
||||||
if (!normalizeStateSet.valid()) {
|
if (!normalizeStateSet.valid()) {
|
||||||
normalizeStateSet = new osg::StateSet;
|
normalizeStateSet = new osg::StateSet;
|
||||||
normalizeStateSet->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
|
normalizeStateSet->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
|
||||||
@@ -1387,13 +1391,12 @@ SGAlphaTestAnimation::SGAlphaTestAnimation(const SGPropertyNode* configNode,
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
// Keep one copy of the most common alpha test its state set.
|
// 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::AlphaFunc> standardAlphaFunc;
|
||||||
osg::ref_ptr<osg::StateSet> alphaFuncStateSet;
|
osg::ref_ptr<osg::StateSet> alphaFuncStateSet;
|
||||||
|
|
||||||
osg::AlphaFunc* makeAlphaFunc(float clamp)
|
osg::AlphaFunc* makeAlphaFunc(float clamp)
|
||||||
{
|
{
|
||||||
using namespace OpenThreads;
|
|
||||||
ScopedLock<ReentrantMutex> lock(alphaTestMutex);
|
ScopedLock<ReentrantMutex> lock(alphaTestMutex);
|
||||||
if (osg::equivalent(clamp, 0.01f)) {
|
if (osg::equivalent(clamp, 0.01f)) {
|
||||||
if (standardAlphaFunc.valid())
|
if (standardAlphaFunc.valid())
|
||||||
|
|||||||
@@ -36,9 +36,10 @@
|
|||||||
#include <osg/Texture1D>
|
#include <osg/Texture1D>
|
||||||
#include <osgUtil/HighlightMapGenerator>
|
#include <osgUtil/HighlightMapGenerator>
|
||||||
|
|
||||||
|
#include <OpenThreads/Mutex>
|
||||||
|
#include <OpenThreads/ScopedLock>
|
||||||
|
|
||||||
#include <simgear/scene/util/SGUpdateVisitor.hxx>
|
#include <simgear/scene/util/SGUpdateVisitor.hxx>
|
||||||
#include <simgear/threads/SGThread.hxx>
|
|
||||||
#include <simgear/threads/SGGuard.hxx>
|
|
||||||
|
|
||||||
#include <simgear/props/condition.hxx>
|
#include <simgear/props/condition.hxx>
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
@@ -47,6 +48,10 @@
|
|||||||
|
|
||||||
#include "animation.hxx"
|
#include "animation.hxx"
|
||||||
#include "model.hxx"
|
#include "model.hxx"
|
||||||
|
|
||||||
|
using OpenThreads::Mutex;
|
||||||
|
using OpenThreads::ScopedLock;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
<animation>
|
<animation>
|
||||||
<type>shader</type>
|
<type>shader</type>
|
||||||
@@ -125,6 +130,8 @@ private:
|
|||||||
SGVec4f _lastLightColor;
|
SGVec4f _lastLightColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static Mutex cubeMutex;
|
||||||
|
|
||||||
static osg::TextureCubeMap*
|
static osg::TextureCubeMap*
|
||||||
getOrCreateTextureCubeMap()
|
getOrCreateTextureCubeMap()
|
||||||
{
|
{
|
||||||
@@ -132,8 +139,7 @@ getOrCreateTextureCubeMap()
|
|||||||
if (textureCubeMap.get())
|
if (textureCubeMap.get())
|
||||||
return textureCubeMap.get();
|
return textureCubeMap.get();
|
||||||
|
|
||||||
static SGMutex mutex;
|
ScopedLock<Mutex> lock(cubeMutex);
|
||||||
SGGuard<SGMutex> locker(mutex);
|
|
||||||
if (textureCubeMap.get())
|
if (textureCubeMap.get())
|
||||||
return textureCubeMap.get();
|
return textureCubeMap.get();
|
||||||
|
|
||||||
@@ -212,13 +218,14 @@ typedef std::map<osg::ref_ptr<osg::Texture2D>, osg::ref_ptr<osg::StateSet> >
|
|||||||
StateSetMap;
|
StateSetMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Mutex chromeMutex;
|
||||||
|
|
||||||
// The chrome effect is mixed by the alpha channel of the texture
|
// 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
|
// on the model, which will be attached to a node lower in the scene
|
||||||
// graph: 0 -> completely chrome, 1 -> completely model texture.
|
// graph: 0 -> completely chrome, 1 -> completely model texture.
|
||||||
static void create_chrome(osg::Group* group, osg::Texture2D* texture)
|
static void create_chrome(osg::Group* group, osg::Texture2D* texture)
|
||||||
{
|
{
|
||||||
static SGMutex mutex;
|
ScopedLock<Mutex> lock(chromeMutex);
|
||||||
SGGuard<SGMutex> locker(mutex);
|
|
||||||
static StateSetMap chromeMap;
|
static StateSetMap chromeMap;
|
||||||
osg::StateSet *stateSet;
|
osg::StateSet *stateSet;
|
||||||
StateSetMap::iterator iterator = chromeMap.find(texture);
|
StateSetMap::iterator iterator = chromeMap.find(texture);
|
||||||
|
|||||||
@@ -50,8 +50,6 @@
|
|||||||
#include <simgear/scene/util/SGUpdateVisitor.hxx>
|
#include <simgear/scene/util/SGUpdateVisitor.hxx>
|
||||||
#include <simgear/scene/util/SGNodeMasks.hxx>
|
#include <simgear/scene/util/SGNodeMasks.hxx>
|
||||||
#include <simgear/scene/util/QuadTreeBuilder.hxx>
|
#include <simgear/scene/util/QuadTreeBuilder.hxx>
|
||||||
#include <simgear/threads/SGThread.hxx>
|
|
||||||
#include <simgear/threads/SGGuard.hxx>
|
|
||||||
|
|
||||||
#include "SGTexturedTriangleBin.hxx"
|
#include "SGTexturedTriangleBin.hxx"
|
||||||
#include "SGLightBin.hxx"
|
#include "SGLightBin.hxx"
|
||||||
|
|||||||
@@ -50,15 +50,19 @@
|
|||||||
|
|
||||||
#include <osgUtil/CullVisitor>
|
#include <osgUtil/CullVisitor>
|
||||||
|
|
||||||
|
#include <OpenThreads/Mutex>
|
||||||
|
#include <OpenThreads/ScopedLock>
|
||||||
|
|
||||||
#include <simgear/math/sg_random.h>
|
#include <simgear/math/sg_random.h>
|
||||||
#include <simgear/debug/logstream.hxx>
|
#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/RenderConstants.hxx>
|
||||||
#include <simgear/scene/util/SGEnlargeBoundingBox.hxx>
|
#include <simgear/scene/util/SGEnlargeBoundingBox.hxx>
|
||||||
|
|
||||||
#include "SGVasiDrawable.hxx"
|
#include "SGVasiDrawable.hxx"
|
||||||
|
|
||||||
|
using OpenThreads::Mutex;
|
||||||
|
using OpenThreads::ScopedLock;
|
||||||
|
|
||||||
using namespace simgear;
|
using namespace simgear;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -123,6 +127,8 @@ getPointSpriteImage(int logResolution)
|
|||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Mutex lightMutex;
|
||||||
|
|
||||||
static osg::Texture2D*
|
static osg::Texture2D*
|
||||||
gen_standard_light_sprite(void)
|
gen_standard_light_sprite(void)
|
||||||
{
|
{
|
||||||
@@ -131,8 +137,7 @@ gen_standard_light_sprite(void)
|
|||||||
if (texture.valid())
|
if (texture.valid())
|
||||||
return texture.get();
|
return texture.get();
|
||||||
|
|
||||||
static SGMutex mutex;
|
ScopedLock<Mutex> lock(lightMutex);
|
||||||
SGGuard<SGMutex> guard(mutex);
|
|
||||||
if (texture.valid())
|
if (texture.valid())
|
||||||
return texture.get();
|
return texture.get();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user