From: James Turner Date: Sat, 23 Nov 2013 20:00:23 +0000 (+0000) Subject: Allow Command-manager singleton to be deleted. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=10375086ed794770fcb97591ec19c60c0fcdaff1;p=simgear.git Allow Command-manager singleton to be deleted. (Shutdown can delete commands in an orderly way) --- diff --git a/simgear/structure/commands.cxx b/simgear/structure/commands.cxx index 91d5928e..9a410936 100644 --- a/simgear/structure/commands.cxx +++ b/simgear/structure/commands.cxx @@ -9,6 +9,8 @@ #endif #include +#include + #include #include "commands.hxx" @@ -23,32 +25,24 @@ // 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 mgr; - if (mgr.get()) - return mgr.get(); - - SGGuard lock(_instanceMutex); - if (mgr.get()) - return mgr.get(); - - mgr = std::auto_ptr(new SGCommandMgr); - return mgr.get(); + return static_instance; } void diff --git a/simgear/structure/commands.hxx b/simgear/structure/commands.hxx index c9ad2370..2ffabf0a 100644 --- a/simgear/structure/commands.hxx +++ b/simgear/structure/commands.hxx @@ -16,7 +16,6 @@ #include #include -#include #include // forward decls @@ -87,16 +86,16 @@ private: } public: - + /** + * Default constructor (sets instance to created item) + */ + SGCommandMgr (); /** - * Destructor. + * Destructor. (sets instance to NULL) */ virtual ~SGCommandMgr (); - /** - * Implement the classical singleton. - */ static SGCommandMgr* instance(); /** @@ -155,10 +154,7 @@ public: */ bool removeCommand(const std::string& name); protected: - /** - * Default constructor. - */ - SGCommandMgr (); + private: @@ -166,8 +162,6 @@ private: typedef std::map command_map; command_map _commands; - static SGMutex _instanceMutex; - }; #endif // __COMMANDS_HXX