X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2Fcommands.cxx;h=16706d96ecde648e8095fdb78cd2674ccbecd086;hb=ff7e70f4d570c472bbc6fe4198483d927914a35e;hp=2e2c59215494430a72498266e4617960d4f0bab9;hpb=d22640ef4e938b523bdc30cd83370977d30de856;p=simgear.git diff --git a/simgear/structure/commands.cxx b/simgear/structure/commands.cxx index 2e2c5921..16706d96 100644 --- a/simgear/structure/commands.cxx +++ b/simgear/structure/commands.cxx @@ -4,8 +4,12 @@ // // $Id$ +#include #include +#include +#include + #include "commands.hxx" @@ -25,6 +29,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) {