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:
@@ -20,8 +20,13 @@
|
|||||||
|
|
||||||
#ifndef SGReferenced_HXX
|
#ifndef SGReferenced_HXX
|
||||||
#define SGReferenced_HXX
|
#define SGReferenced_HXX
|
||||||
|
#define USE_OPENTHREADS_ATOMIC
|
||||||
|
|
||||||
|
#ifndef USE_OPENTHREADS_ATOMIC
|
||||||
#include "SGAtomic.hxx"
|
#include "SGAtomic.hxx"
|
||||||
|
#else
|
||||||
|
#include <OpenThreads/Atomic>
|
||||||
|
#endif
|
||||||
|
|
||||||
/// Base class for all reference counted SimGear objects
|
/// Base class for all reference counted SimGear objects
|
||||||
/// Classes derived from this one are meant to be managed with
|
/// 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; }
|
{ if (ref) return 1u < ref->_refcount; else return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#ifndef USE_OPENTHREADS_ATOMIC
|
||||||
mutable SGAtomic _refcount;
|
mutable SGAtomic _refcount;
|
||||||
|
#else
|
||||||
|
mutable OpenThreads::Atomic _refcount;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,8 +6,9 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <simgear/props/props_io.hxx>
|
#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"
|
#include "commands.hxx"
|
||||||
|
|
||||||
@@ -28,6 +29,8 @@ SGCommandMgr::~SGCommandMgr ()
|
|||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OpenThreads::Mutex SGCommandMgr::_instanceMutex;
|
||||||
|
|
||||||
SGCommandMgr*
|
SGCommandMgr*
|
||||||
SGCommandMgr::instance()
|
SGCommandMgr::instance()
|
||||||
{
|
{
|
||||||
@@ -35,8 +38,7 @@ SGCommandMgr::instance()
|
|||||||
if (mgr.get())
|
if (mgr.get())
|
||||||
return mgr.get();
|
return mgr.get();
|
||||||
|
|
||||||
static SGMutex lock;
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_instanceMutex);
|
||||||
SGGuard<SGMutex> guard(lock);
|
|
||||||
if (mgr.get())
|
if (mgr.get())
|
||||||
return mgr.get();
|
return mgr.get();
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <OpenThreads/Mutex>
|
||||||
|
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
@@ -109,6 +111,8 @@ private:
|
|||||||
typedef map<string,command_t> command_map;
|
typedef map<string,command_t> command_map;
|
||||||
command_map _commands;
|
command_map _commands;
|
||||||
|
|
||||||
|
static OpenThreads::Mutex _instanceMutex;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __COMMANDS_HXX
|
#endif // __COMMANDS_HXX
|
||||||
|
|||||||
Reference in New Issue
Block a user