diff --git a/Code/Mantid/API/src/AlgorithmFactory.cpp b/Code/Mantid/API/src/AlgorithmFactory.cpp index 384676c2aa20ec44ab522cf78e7a380ba34fef7c..9c6a8eba364dba75b4e4803a30f8981c3d61bc48 100644 --- a/Code/Mantid/API/src/AlgorithmFactory.cpp +++ b/Code/Mantid/API/src/AlgorithmFactory.cpp @@ -13,11 +13,13 @@ namespace API // are constructed so that it is destroyed after us and thus does // not close any loaded DLLs with loaded algorithms in them Mantid::Kernel::LibraryManager::Instance(); + std::cerr << "Algorithm Factory created." << std::endl; g_log.debug() << "Algorithm Factory created." << std::endl; } AlgorithmFactoryImpl::~AlgorithmFactoryImpl() { + std::cerr << "Algorithm Factory destroyed." << std::endl; // g_log.debug() << "Algorithm Factory destroyed." << std::endl; } diff --git a/Code/Mantid/API/src/AlgorithmManager.cpp b/Code/Mantid/API/src/AlgorithmManager.cpp index 638090982479ed1a975fd3ccc9e9785139caeb53..1c03c714ae5bf543a586928faf38f29aad514bf8 100644 --- a/Code/Mantid/API/src/AlgorithmManager.cpp +++ b/Code/Mantid/API/src/AlgorithmManager.cpp @@ -16,6 +16,7 @@ namespace Mantid /// Private Constructor for singleton class AlgorithmManagerImpl::AlgorithmManagerImpl(): g_log(Kernel::Logger::get("AlgorithmManager")), no_of_alg(0) { + std::cerr << "Algorithm Manager created." << std::endl; g_log.debug() << "Algorithm Manager created." << std::endl; } @@ -25,7 +26,8 @@ namespace Mantid */ AlgorithmManagerImpl::~AlgorithmManagerImpl() { - g_log.debug() << "Algorithm Manager destroyed." << std::endl; + std::cerr << "Algorithm Manager destroyed." << std::endl; +// g_log.debug() << "Algorithm Manager destroyed." << std::endl; } /** Creates an instance of an algorithm, but does not own that instance diff --git a/Code/Mantid/API/src/AnalysisDataService.cpp b/Code/Mantid/API/src/AnalysisDataService.cpp index 1f27a1d7002089494978ab1b6b439b8e2b0a6f8c..c83bf257e4b39f2938b1378ca8739a016993388e 100644 --- a/Code/Mantid/API/src/AnalysisDataService.cpp +++ b/Code/Mantid/API/src/AnalysisDataService.cpp @@ -145,7 +145,8 @@ AnalysisDataServiceImpl::AnalysisDataServiceImpl(const AnalysisDataServiceImpl&) */ AnalysisDataServiceImpl::~AnalysisDataServiceImpl() { - g_log.debug() << "Analysis Data Service destroyed." << std::endl; + std::cerr << "Analysis Data Service destroyed." << std::endl; +// g_log.debug() << "Analysis Data Service destroyed." << std::endl; } diff --git a/Code/Mantid/API/src/FrameworkManager.cpp b/Code/Mantid/API/src/FrameworkManager.cpp index 063b5433df1ce497aa46d78bc8fbc6a721e95f0b..741d17b94d55a099456149d4d60f6d8ff2b5cc0c 100644 --- a/Code/Mantid/API/src/FrameworkManager.cpp +++ b/Code/Mantid/API/src/FrameworkManager.cpp @@ -25,14 +25,13 @@ namespace API /// Default constructor FrameworkManagerImpl::FrameworkManagerImpl() : g_log(Kernel::Logger::get("FrameworkManager")) { - std::cout << "FrmMgr created!" << std::endl; g_log.debug() << "FrameworkManager created." << std::endl; } /// Destructor FrameworkManagerImpl::~FrameworkManagerImpl() { - std::cout << "FrmMgr destroyed!" << std::endl; + std::cerr << "FrameworkManager destroyed." << std::endl; // g_log.debug() << "FrameworkManager destroyed." << std::endl; } diff --git a/Code/Mantid/Kernel/inc/MantidKernel/SingletonHolder.h b/Code/Mantid/Kernel/inc/MantidKernel/SingletonHolder.h index c51689cd37b71931caf995f05188fd067e374f74..46cbf5448f133f8fc342c08854be7fc4ac78fc69 100644 --- a/Code/Mantid/Kernel/inc/MantidKernel/SingletonHolder.h +++ b/Code/Mantid/Kernel/inc/MantidKernel/SingletonHolder.h @@ -33,6 +33,11 @@ namespace Mantid namespace Kernel { +/// prototype for function passed to atexit() +typedef void (*atexit_func_t)(void); +extern void CleanupSingletons(void); +extern void AddSingleton(atexit_func_t func); + template <typename T> class SingletonHolder { @@ -68,7 +73,8 @@ inline T& SingletonHolder<T>::Instance() { // std::cerr << "creating singleton " << typeid(T).name() << std::endl; pInstance = CreateUsingNew<T>::Create(); - atexit(&DestroySingleton); + AddSingleton(&DestroySingleton); + atexit(&CleanupSingletons); } return *pInstance; } diff --git a/Code/Mantid/Kernel/src/LibraryManager.cpp b/Code/Mantid/Kernel/src/LibraryManager.cpp index be31417fc18f66d70652b097418bd3eb4835a4a3..03647a4da0c6ae9c2a58af9fba1991f96bcc2336 100644 --- a/Code/Mantid/Kernel/src/LibraryManager.cpp +++ b/Code/Mantid/Kernel/src/LibraryManager.cpp @@ -20,12 +20,14 @@ namespace Kernel /// Constructor LibraryManagerImpl::LibraryManagerImpl() : g_log(Logger::get("LibraryManager")) { + std::cerr << "LibraryManager created." << std::endl; g_log.debug() << "LibraryManager created." << std::endl; } /// Destructor LibraryManagerImpl::~LibraryManagerImpl() { + std::cerr << "LibraryManager destroyed." << std::endl; // g_log.debug() << "LibraryManager destroyed." << std::endl; } diff --git a/Code/Mantid/Kernel/src/SingletonHolder.cpp b/Code/Mantid/Kernel/src/SingletonHolder.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f1c76ae4033265308a336cf82a49e548bab992c3 --- /dev/null +++ b/Code/Mantid/Kernel/src/SingletonHolder.cpp @@ -0,0 +1,42 @@ +#include <list> +#include <MantidKernel/SingletonHolder.h> + +namespace Mantid +{ +namespace Kernel +{ + +/// List of functions to call on program exit +static std::list<atexit_func_t>* cleanup_list = NULL; + +/// Function registed to atexit() that will clean up +/// all our singletons +/// This function may be registed more than once, so needs to +/// clear the list once it has called all the functions +void CleanupSingletons(void) +{ + if (cleanup_list == NULL) + { + return; + } + std::list<atexit_func_t>::const_iterator it; + for(it=cleanup_list->begin(); it != cleanup_list->end(); it++) + { + (*(*it))(); + } + delete cleanup_list; + cleanup_list = NULL; +} + +/// Add s singleton cleanup function to our atexit list +void AddSingleton(atexit_func_t func) +{ + if (cleanup_list == NULL) + { + cleanup_list = new std::list<atexit_func_t>; + } + cleanup_list->push_front(func); +} + +} +}