Hello,
Here is the updated patch to remove the dependencies on SGThread for
*SimGear* (FlightGear will follow later).
Here is what it does:
- Replace SGMutex with OpenThreads::Mutex.
- Replace SGGuard with OpenThreads::ScopedLock (which acts exactly like
SGGuard, see include/OpenThreads/ScopedLock).
- Use global variables for mutex where needed to be thread safe (as
pointed by Tim).
No other changes are made (it does not touch configure or makefiles) so
it should be safe to use even with other soft like fg ;).
Best regards,
Benoît
Index: simgear/scene/model/shadanim.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/model/shadanim.cxx,v
retrieving revision 1.13
diff -u -r1.13 shadanim.cxx
--- simgear/scene/model/shadanim.cxx 4 Dec 2007 22:38:41 -0000 1.13
+++ simgear/scene/model/shadanim.cxx 6 May 2008 16:50:14 -0000
@@ -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>
@@ -125,6 +126,8 @@
SGVec4f _lastLightColor;
};
+static OpenThreads::Mutex cubeMutex;
+
static osg::TextureCubeMap*
getOrCreateTextureCubeMap()
{
@@ -132,8 +135,7 @@
if (textureCubeMap.get())
return textureCubeMap.get();
- static SGMutex mutex;
- SGGuard<SGMutex> locker(mutex);
+ OpenThreads::ScopedLock<OpenThreads::Mutex> lock(cubeMutex);
if (textureCubeMap.get())
return textureCubeMap.get();
@@ -212,13 +214,14 @@
StateSetMap;
}
+static OpenThreads::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);
+ OpenThreads::ScopedLock<OpenThreads::Mutex> lock(chromeMutex);
static StateSetMap chromeMap;
osg::StateSet *stateSet;
StateSetMap::iterator iterator = chromeMap.find(texture);
Index: simgear/scene/tgdb/obj.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/tgdb/obj.cxx,v
retrieving revision 1.34
diff -u -r1.34 obj.cxx
--- simgear/scene/tgdb/obj.cxx 1 May 2008 12:21:52 -0000 1.34
+++ simgear/scene/tgdb/obj.cxx 6 May 2008 16:50:14 -0000
@@ -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: simgear/scene/tgdb/pt_lights.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/tgdb/pt_lights.cxx,v
retrieving revision 1.14
diff -u -r1.14 pt_lights.cxx
--- simgear/scene/tgdb/pt_lights.cxx 21 Dec 2007 06:24:53 -0000 1.14
+++ simgear/scene/tgdb/pt_lights.cxx 6 May 2008 16:50:15 -0000
@@ -50,10 +50,11 @@
#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>
@@ -123,6 +124,8 @@
return image;
}
+static OpenThreads::Mutex lightMutex;
+
static osg::Texture2D*
gen_standard_light_sprite(void)
{
@@ -131,8 +134,7 @@
if (texture.valid())
return texture.get();
- static SGMutex mutex;
- SGGuard<SGMutex> guard(mutex);
+ OpenThreads::ScopedLock<OpenThreads::Mutex> lock(lightMutex);
if (texture.valid())
return texture.get();
Index: simgear/scene/util/SGSceneFeatures.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/util/SGSceneFeatures.cxx,v
retrieving revision 1.3
diff -u -r1.3 SGSceneFeatures.cxx
--- simgear/scene/util/SGSceneFeatures.cxx 8 Jun 2007 06:50:16 -0000 1.3
+++ simgear/scene/util/SGSceneFeatures.cxx 6 May 2008 16:50:15 -0000
@@ -31,9 +31,10 @@
#include <osg/PointSprite>
#include <osg/Texture>
+#include <OpenThreads/Mutex>
+#include <OpenThreads/ScopedLock>
+
#include <simgear/structure/SGSharedPtr.hxx>
-#include <simgear/threads/SGThread.hxx>
-#include <simgear/threads/SGGuard.hxx>
SGSceneFeatures::SGSceneFeatures() :
_textureCompression(UseARBCompression),
@@ -44,14 +45,15 @@
{
}
+OpenThreads::Mutex SGSceneFeatures::_instanceMutex;
+
SGSceneFeatures*
SGSceneFeatures::instance()
{
static SGSharedPtr<SGSceneFeatures> sceneFeatures;
if (sceneFeatures)
return sceneFeatures;
- static SGMutex mutex;
- SGGuard<SGMutex> guard(mutex);
+ OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_instanceMutex);
if (sceneFeatures)
return sceneFeatures;
sceneFeatures = new SGSceneFeatures;
Index: simgear/scene/util/SGSceneFeatures.hxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/util/SGSceneFeatures.hxx,v
retrieving revision 1.3
diff -u -r1.3 SGSceneFeatures.hxx
--- simgear/scene/util/SGSceneFeatures.hxx 8 Jun 2007 06:50:16 -0000 1.3
+++ simgear/scene/util/SGSceneFeatures.hxx 6 May 2008 16:50:15 -0000
@@ -22,6 +22,8 @@
#ifndef SG_SCENE_FEATURES_HXX
#define SG_SCENE_FEATURES_HXX
+#include <OpenThreads/Mutex>
+
#include <simgear/structure/SGReferenced.hxx>
namespace osg { class Texture; }
@@ -94,6 +96,8 @@
bool _pointSpriteLights;
bool _distanceAttenuationLights;
int _textureFilter;
+
+ static OpenThreads::Mutex _instanceMutex;
};
#endif
Index: simgear/structure/SGAtomic.hxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/structure/SGAtomic.hxx,v
retrieving revision 1.3
diff -u -r1.3 SGAtomic.hxx
--- simgear/structure/SGAtomic.hxx 15 Oct 2007 18:49:51 -0000 1.3
+++ simgear/structure/SGAtomic.hxx 6 May 2008 16:50:15 -0000
@@ -33,8 +33,8 @@
# define SGATOMIC_USE_WIN32_INTERLOCKED
#else
// The sledge hammer ...
-# include <simgear/threads/SGThread.hxx>
-# include <simgear/threads/SGGuard.hxx>
+# include <OpenThreads/Mutex>
+# include <OpenThreads/ScopedLock>
#endif
class SGAtomic {
@@ -50,7 +50,7 @@
#elif defined(SGATOMIC_USE_WIN32_INTERLOCKED)
return InterlockedIncrement(reinterpret_cast<long volatile*>(&mValue));
#else
- SGGuard<SGMutex> lock(mMutex);
+ OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
return ++mValue;
#endif
}
@@ -63,7 +63,7 @@
#elif defined(SGATOMIC_USE_WIN32_INTERLOCKED)
return InterlockedDecrement(reinterpret_cast<long volatile*>(&mValue));
#else
- SGGuard<SGMutex> lock(mMutex);
+ OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
return --mValue;
#endif
}
@@ -78,7 +78,7 @@
#elif defined(SGATOMIC_USE_WIN32_INTERLOCKED)
return static_cast<unsigned const volatile &>(mValue);
#else
- SGGuard<SGMutex> lock(mMutex);
+ OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
return mValue;
#endif
}
@@ -90,7 +90,7 @@
#if !defined(SGATOMIC_USE_GCC4_BUILTINS) \
&& !defined(SGATOMIC_USE_MIPOSPRO_BUILTINS) \
&& !defined(SGATOMIC_USE_WIN32_INTERLOCKED)
- mutable SGMutex mMutex;
+ mutable OpenThreads::Mutex mMutex;
#endif
#ifdef SGATOMIC_USE_WIN32_INTERLOCKED
__declspec(align(32))
Index: simgear/structure/commands.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/structure/commands.cxx,v
retrieving revision 1.2
diff -u -r1.2 commands.cxx
--- simgear/structure/commands.cxx 4 Jan 2007 12:47:12 -0000 1.2
+++ simgear/structure/commands.cxx 6 May 2008 16:50:15 -0000
@@ -6,8 +6,9 @@
#include <memory>
#include <simgear/props/props_io.hxx>
-#include <simgear/threads/SGThread.hxx>
-#include <simgear/threads/SGGuard.hxx>
+
+#include <OpenThreads/Mutex>
+#include <OpenThreads/ScopedLock>
#include "commands.hxx"
@@ -28,6 +29,8 @@
// no-op
}
+OpenThreads::Mutex SGCommandMgr::_instanceMutex;
+
SGCommandMgr*
SGCommandMgr::instance()
{
@@ -35,8 +38,7 @@
if (mgr.get())
return mgr.get();
- static SGMutex lock;
- SGGuard<SGMutex> guard(lock);
+ OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_instanceMutex);
if (mgr.get())
return mgr.get();
Index: simgear/structure/commands.hxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/structure/commands.hxx,v
retrieving revision 1.2
diff -u -r1.2 commands.hxx
--- simgear/structure/commands.hxx 4 Jan 2007 12:47:12 -0000 1.2
+++ simgear/structure/commands.hxx 6 May 2008 16:50:15 -0000
@@ -17,6 +17,8 @@
#include <map>
#include <vector>
+#include <OpenThreads/Mutex>
+
#include <simgear/props/props.hxx>
SG_USING_STD(string);
@@ -109,6 +111,8 @@
typedef map<string,command_t> command_map;
command_map _commands;
+ static OpenThreads::Mutex _instanceMutex;
+
};
#endif // __COMMANDS_HXX
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel