Hello,
My patches for SGThread are now complete. I use them on Linux with no
problems and some people use them on Windows since a few weeks with no
problems either.
Patch for simgear:
- 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).
Patch for flightgear:
- Replace SGThread with OpenThreads::Thread.
- Replace SGGuard with OpenThreads::ScopedLock.
- Replace SGMutex with OpenThreads::Mutex.
- Replace SGPthreadCond by OpenThreads::Condition.
I did not touch configuration files, so to enable threads pthread still
needs to be detected (but will not be used). With these patches, only
SGQueue.hxx is used in simgear/threads (which is cross-platform since it
only uses OpenThreads).
Best regards,
Benoît
Index: src/Environment/environment_ctrl.cxx
===
RCS file: /var/cvs/FlightGear-0.9/source/src/Environment/environment_ctrl.cxx,v
retrieving revision 1.50
diff -u -r1.50 environment_ctrl.cxx
--- src/Environment/environment_ctrl.cxx 11 Oct 2007 07:53:17 - 1.50
+++ src/Environment/environment_ctrl.cxx 11 May 2008 10:48:59 -
@@ -356,7 +356,8 @@
{
#if defined(ENABLE_THREADS)
thread = new MetarThread(this);
-thread-start( 1 );
+thread-setProcessorAffinity(1);
+thread-start();
#endif // ENABLE_THREADS
}
Index: src/Environment/environment_ctrl.hxx
===
RCS file: /var/cvs/FlightGear-0.9/source/src/Environment/environment_ctrl.hxx,v
retrieving revision 1.27
diff -u -r1.27 environment_ctrl.hxx
--- src/Environment/environment_ctrl.hxx 15 Aug 2007 15:22:44 - 1.27
+++ src/Environment/environment_ctrl.hxx 11 May 2008 10:48:59 -
@@ -32,7 +32,7 @@
#include simgear/environment/metar.hxx
#if defined(ENABLE_THREADS)
-# include simgear/threads/SGThread.hxx
+# include OpenThreads/Thread
# include simgear/threads/SGQueue.hxx
#endif
@@ -233,7 +233,7 @@
* This class represents the thread of execution responsible for
* fetching the metar data.
*/
-class MetarThread : public SGThread
+class MetarThread : public OpenThreads::Thread
{
public:
MetarThread( FGMetarEnvironmentCtrl* f ) : fetcher(f) {}
Index: src/Sound/voice.cxx
===
RCS file: /var/cvs/FlightGear-0.9/source/src/Sound/voice.cxx,v
retrieving revision 1.8
diff -u -r1.8 voice.cxx
--- src/Sound/voice.cxx 23 Mar 2007 15:53:58 - 1.8
+++ src/Sound/voice.cxx 11 May 2008 10:48:59 -
@@ -71,7 +71,8 @@
}
#if defined(ENABLE_THREADS)
- _thread-start(1);
+ _thread-setProcessorAffinity(1);
+ _thread-start();
#endif
}
Index: src/Sound/voice.hxx
===
RCS file: /var/cvs/FlightGear-0.9/source/src/Sound/voice.hxx,v
retrieving revision 1.3
diff -u -r1.3 voice.hxx
--- src/Sound/voice.hxx 31 Mar 2006 10:12:00 - 1.3
+++ src/Sound/voice.hxx 11 May 2008 10:48:59 -
@@ -37,7 +37,10 @@
#include Main/fg_props.hxx
#if defined(ENABLE_THREADS)
-# include simgear/threads/SGThread.hxx
+# include OpenThreads/Thread
+# include OpenThreads/Mutex
+# include OpenThreads/ScopedLock
+# include OpenThreads/Condition
# include simgear/threads/SGQueue.hxx
#else
# include queue
@@ -74,16 +77,16 @@
#if defined(ENABLE_THREADS)
-class FGVoiceMgr::FGVoiceThread : public SGThread {
+class FGVoiceMgr::FGVoiceThread : public OpenThreads::Thread {
public:
FGVoiceThread(FGVoiceMgr *mgr) : _mgr(mgr) {}
void run();
void wake_up() { _jobs.signal(); }
private:
- void wait_for_jobs() { SGGuardSGMutex g(_mutex); _jobs.wait(_mutex); }
- SGPthreadCond _jobs;
- SGMutex _mutex;
+ void wait_for_jobs() { OpenThreads::ScopedLockOpenThreads::Mutex g(_mutex); _jobs.wait(_mutex); }
+ OpenThreads::Condition _jobs;
+ OpenThreads::Mutex _mutex;
FGVoiceMgr *_mgr;
};
#endif
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 - 1.13
+++ simgear/scene/model/shadanim.cxx 11 May 2008 10:52:53 -
@@ -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