X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2Fcommands.cxx;h=b2391e3ba7f1cff7986f8eacf5364e985739ee56;hb=7e7d877874fcd67cad0152bd1a2a073e0337235f;hp=2e2c59215494430a72498266e4617960d4f0bab9;hpb=d22640ef4e938b523bdc30cd83370977d30de856;p=simgear.git diff --git a/simgear/structure/commands.cxx b/simgear/structure/commands.cxx index 2e2c5921..b2391e3b 100644 --- a/simgear/structure/commands.cxx +++ b/simgear/structure/commands.cxx @@ -4,10 +4,20 @@ // // $Id$ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include #include +#include +#include + #include "commands.hxx" +#include + //////////////////////////////////////////////////////////////////////// @@ -25,6 +35,23 @@ SGCommandMgr::~SGCommandMgr () // no-op } +OpenThreads::Mutex SGCommandMgr::_instanceMutex; + +SGCommandMgr* +SGCommandMgr::instance() +{ + static std::auto_ptr mgr; + if (mgr.get()) + return mgr.get(); + + OpenThreads::ScopedLock lock(_instanceMutex); + if (mgr.get()) + return mgr.get(); + + mgr = std::auto_ptr(new SGCommandMgr); + return mgr.get(); +} + void SGCommandMgr::addCommand (const string &name, command_t command) {