From 7c14453b5a4e77d99e2d7e19332cce5c7b9c2e1d Mon Sep 17 00:00:00 2001 From: jmt Date: Thu, 15 Jan 2009 14:31:51 +0000 Subject: [PATCH] Since we're now sure 1.9.1 will not be released from trunk, here's Yon Uriarte's patch to convert SGReferenced over to OpenThread's atomic int. --- simgear/structure/SGReferenced.hxx | 9 +++++++++ simgear/structure/commands.cxx | 10 ++++++---- simgear/structure/commands.hxx | 4 ++++ 3 files changed, 19 insertions(+), 4 deletions(-) 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 -- 2.39.5