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.
This commit is contained in:
jmt
2009-01-15 14:31:51 +00:00
committed by Tim Moore
parent db8f7f21e8
commit 7c14453b5a
3 changed files with 19 additions and 4 deletions

View File

@@ -20,8 +20,13 @@
#ifndef SGReferenced_HXX
#define SGReferenced_HXX
#define USE_OPENTHREADS_ATOMIC
#ifndef USE_OPENTHREADS_ATOMIC
#include "SGAtomic.hxx"
#else
#include <OpenThreads/Atomic>
#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

View File

@@ -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 @@ 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<SGMutex> guard(lock);
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_instanceMutex);
if (mgr.get())
return mgr.get();

View File

@@ -17,6 +17,8 @@
#include <map>
#include <vector>
#include <OpenThreads/Mutex>
#include <simgear/props/props.hxx>
using std::string;
@@ -109,6 +111,8 @@ private:
typedef map<string,command_t> command_map;
command_map _commands;
static OpenThreads::Mutex _instanceMutex;
};
#endif // __COMMANDS_HXX