diff --git a/simgear/props/Makefile.am b/simgear/props/Makefile.am index f1cf6f9a..f3ad95d0 100644 --- a/simgear/props/Makefile.am +++ b/simgear/props/Makefile.am @@ -20,6 +20,7 @@ props_test_LDADD = \ $(top_builddir)/simgear/xml/libsgxml.a \ $(top_builddir)/simgear/misc/libsgmisc.a \ $(top_builddir)/simgear/debug/libsgdebug.a \ - $(top_builddir)/simgear/structure/libsgstructure.a + $(top_builddir)/simgear/structure/libsgstructure.a \ + -lOpenThreads INCLUDES = -I$(top_srcdir) diff --git a/simgear/scene/util/SGSceneFeatures.cxx b/simgear/scene/util/SGSceneFeatures.cxx index 71edb2eb..4367e453 100644 --- a/simgear/scene/util/SGSceneFeatures.cxx +++ b/simgear/scene/util/SGSceneFeatures.cxx @@ -31,9 +31,10 @@ #include #include +#include +#include + #include -#include -#include SGSceneFeatures::SGSceneFeatures() : _textureCompression(UseARBCompression), @@ -44,14 +45,14 @@ SGSceneFeatures::SGSceneFeatures() : { } -static SGMutex mutexSGSceneFeatures_instance; +static OpenThreads::Mutex mutexSGSceneFeatures_instance; SGSceneFeatures* SGSceneFeatures::instance() { static SGSharedPtr sceneFeatures; if (sceneFeatures) return sceneFeatures; - SGGuard guard(mutexSGSceneFeatures_instance); + OpenThreads::ScopedLock lock(mutexSGSceneFeatures_instance); if (sceneFeatures) return sceneFeatures; sceneFeatures = new SGSceneFeatures; diff --git a/simgear/scene/util/SGSceneFeatures.hxx b/simgear/scene/util/SGSceneFeatures.hxx index 458633ff..ced6c919 100644 --- a/simgear/scene/util/SGSceneFeatures.hxx +++ b/simgear/scene/util/SGSceneFeatures.hxx @@ -22,6 +22,8 @@ #ifndef SG_SCENE_FEATURES_HXX #define SG_SCENE_FEATURES_HXX +#include + #include namespace osg { class Texture; } @@ -94,6 +96,8 @@ private: bool _pointSpriteLights; bool _distanceAttenuationLights; int _textureFilter; + + static OpenThreads::Mutex _instanceMutex; }; #endif diff --git a/simgear/sound/Makefile.am b/simgear/sound/Makefile.am index c6273463..48381175 100644 --- a/simgear/sound/Makefile.am +++ b/simgear/sound/Makefile.am @@ -30,6 +30,7 @@ openal_test2_LDADD = \ $(top_builddir)/simgear/debug/libsgdebug.a \ $(top_builddir)/simgear/misc/libsgmisc.a \ $(top_builddir)/simgear/structure/libsgstructure.a \ - $(openal_LIBS) + $(openal_LIBS) \ + -lOpenThreads INCLUDES = -I$(top_srcdir) -DSRC_DIR=\"$(top_srcdir)/simgear/sound\" diff --git a/simgear/structure/SGReferenced.hxx b/simgear/structure/SGReferenced.hxx index 6a3038f3..6bce1eb8 100644 --- a/simgear/structure/SGReferenced.hxx +++ b/simgear/structure/SGReferenced.hxx @@ -20,8 +20,13 @@ #ifndef SGReferenced_HXX #define SGReferenced_HXX +#define USE_OPENTHREADS_ATOMIC +#ifndef USE_OPENTHREADS_ATOMIC #include "SGAtomic.hxx" +#else +#include +#endif /// Base class for all reference counted SimGear objects /// Classes derived from this one are meant to be managed with @@ -49,7 +54,11 @@ public: { if (ref) return 1u < ref->_refcount; else return false; } private: +#ifndef USE_OPENTHREADS_ATOMIC mutable SGAtomic _refcount; +#else + mutable OpenThreads::Atomic _refcount; +#endif }; #endif diff --git a/simgear/structure/commands.cxx b/simgear/structure/commands.cxx index 49a9c63c..16706d96 100644 --- a/simgear/structure/commands.cxx +++ b/simgear/structure/commands.cxx @@ -6,8 +6,9 @@ #include #include -#include -#include + +#include +#include #include "commands.hxx" @@ -28,6 +29,8 @@ SGCommandMgr::~SGCommandMgr () // no-op } +OpenThreads::Mutex SGCommandMgr::_instanceMutex; + SGCommandMgr* SGCommandMgr::instance() { @@ -35,8 +38,7 @@ SGCommandMgr::instance() if (mgr.get()) return mgr.get(); - static SGMutex lock; - SGGuard guard(lock); + OpenThreads::ScopedLock lock(_instanceMutex); if (mgr.get()) return mgr.get(); diff --git a/simgear/structure/commands.hxx b/simgear/structure/commands.hxx index 21f44963..0825ffd9 100644 --- a/simgear/structure/commands.hxx +++ b/simgear/structure/commands.hxx @@ -17,6 +17,8 @@ #include #include +#include + #include using std::string; @@ -109,6 +111,8 @@ private: typedef map command_map; command_map _commands; + static OpenThreads::Mutex _instanceMutex; + }; #endif // __COMMANDS_HXX diff --git a/simgear/threads/SGQueue.hxx b/simgear/threads/SGQueue.hxx index 41bd3272..80877375 100644 --- a/simgear/threads/SGQueue.hxx +++ b/simgear/threads/SGQueue.hxx @@ -5,8 +5,9 @@ #include #include -#include "SGThread.hxx" -#include "SGGuard.hxx" +#include +#include +#include /** * SGQueue defines an interface for a FIFO. @@ -73,7 +74,7 @@ protected: /** * A simple thread safe queue. All access functions are guarded with a mutex. */ -template +template class SGLockedQueue : public SGQueue { public: @@ -94,7 +95,7 @@ public: * @return bool True if queue is empty, otherwisr false. */ virtual bool empty() { - SGGuard g(mutex); + OpenThreads::ScopedLock g(mutex); return this->fifo.empty(); } @@ -104,7 +105,7 @@ public: * @param T object to add. */ virtual void push( const T& item ) { - SGGuard g(mutex); + OpenThreads::ScopedLock g(mutex); this->fifo.push( item ); } @@ -114,7 +115,7 @@ public: * @return T next available object. */ virtual T front() { - SGGuard g(mutex); + OpenThreads::ScopedLock g(mutex); assert( ! this->fifo.empty() ); T item = this->fifo.front(); return item; @@ -126,7 +127,7 @@ public: * @return T next available object. */ virtual T pop() { - SGGuard g(mutex); + OpenThreads::ScopedLock g(mutex); //if (fifo.empty()) throw NoSuchElementException(); assert( ! this->fifo.empty() ); // if (fifo.empty()) @@ -145,7 +146,7 @@ public: * @return size_t size of queue. */ virtual size_t size() { - SGGuard g(mutex); + OpenThreads::ScopedLock g(mutex); return this->fifo.size(); } @@ -184,7 +185,7 @@ public: * */ virtual bool empty() { - SGGuard g(mutex); + OpenThreads::ScopedLock g(mutex); return this->fifo.empty(); } @@ -194,7 +195,7 @@ public: * @param T object to add. */ virtual void push( const T& item ) { - SGGuard g(mutex); + OpenThreads::ScopedLock g(mutex); this->fifo.push( item ); not_empty.signal(); } @@ -206,7 +207,7 @@ public: * @return T next available object. */ virtual T front() { - SGGuard g(mutex); + OpenThreads::ScopedLock g(mutex); assert(this->fifo.empty() != true); //if (fifo.empty()) throw ?? @@ -222,10 +223,10 @@ public: * @return T next available object. */ virtual T pop() { - SGGuard g(mutex); + OpenThreads::ScopedLock g(mutex); while (this->fifo.empty()) - not_empty.wait(mutex); + not_empty.wait(&mutex); assert(this->fifo.empty() != true); //if (fifo.empty()) throw ?? @@ -241,7 +242,7 @@ public: * @return size_t size of queue. */ virtual size_t size() { - SGGuard g(mutex); + OpenThreads::ScopedLock g(mutex); return this->fifo.size(); } @@ -250,12 +251,12 @@ private: /** * Mutex to serialise access. */ - SGMutex mutex; + OpenThreads::Mutex mutex; /** * Condition to signal when queue not empty. */ - SGPthreadCond not_empty; + OpenThreads::Condition not_empty; private: // Prevent copying.