Mantid
Loading...
Searching...
No Matches
SingletonHolder.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include <list>
9
10namespace Mantid::Kernel {
11
12namespace {
14using CleanupList = std::list<SingletonDeleterFn>;
15
16CleanupList &cleanupList() {
17 static CleanupList cleanup;
18 return cleanup;
19}
20
25void cleanupSingletons() {
26 auto &deleters = cleanupList();
27 for (auto &deleter : deleters) {
28 deleter();
29 }
30 deleters.clear();
31}
32} // namespace
33
39 auto &deleters = cleanupList();
40 if (deleters.empty()) {
41 atexit(&cleanupSingletons);
42 }
43 deleters.push_front(func);
44}
45} // namespace Mantid::Kernel
std::function< void()> SingletonDeleterFn
Type of deleter function.
MANTID_KERNEL_DLL void deleteOnExit(const SingletonDeleterFn &func)
Register the given deleter function to be called at exit.