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:
parent
cdff0fceea
commit
c8c693db53
@ -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();
|
||||
|
@ -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<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())
|
||||
|
@ -36,9 +36,10 @@
|
||||
#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>
|
||||
@ -47,6 +48,10 @@
|
||||
|
||||
#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);
|
||||
|
@ -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"
|
||||
|
@ -50,15 +50,19 @@
|
||||
|
||||
#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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user