]> git.mxchange.org Git - simgear.git/blobdiff - simgear/structure/commands.cxx
Some Linux platforms need <cstdio> for snprintf.
[simgear.git] / simgear / structure / commands.cxx
index 91d5928e139a882044c13273337e4e36a0d362f3..752f880c2ad13c60eb36f63e987516a8e77d4854 100644 (file)
@@ -9,6 +9,8 @@
 #endif
 
 #include <memory>
+#include <cassert>
+
 #include <simgear/props/props_io.hxx>
 
 #include "commands.hxx"
 // Implementation of SGCommandMgr class.
 ////////////////////////////////////////////////////////////////////////
 
+static SGCommandMgr* static_instance = NULL;
 
 SGCommandMgr::SGCommandMgr ()
 {
-  // no-op
+    assert(static_instance == NULL);
+    static_instance = this;
 }
 
 SGCommandMgr::~SGCommandMgr ()
 {
-  // no-op
+    assert(static_instance == this);
+    static_instance = NULL;
 }
 
-SGMutex SGCommandMgr::_instanceMutex;
-
 SGCommandMgr*
 SGCommandMgr::instance()
 {
-  static std::auto_ptr<SGCommandMgr> mgr;
-  if (mgr.get())
-    return mgr.get();
-
-  SGGuard<SGMutex> lock(_instanceMutex);
-  if (mgr.get())
-    return mgr.get();
-
-  mgr = std::auto_ptr<SGCommandMgr>(new SGCommandMgr);
-  return mgr.get();
+    return static_instance ? static_instance : new SGCommandMgr;
 }
 
 void