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