enh: #3890: Get rid of SingletonHolder

This commit is contained in:
Günter Obiltschnig 2024-01-30 09:56:27 +01:00
parent 33638df51e
commit d5a5ebc2d7
23 changed files with 44 additions and 168 deletions

View File

@ -11,7 +11,6 @@
#include "ApacheApplication.h" #include "ApacheApplication.h"
#include "ApacheChannel.h" #include "ApacheChannel.h"
#include "Poco/Logger.h" #include "Poco/Logger.h"
#include "Poco/SingletonHolder.h"
#include <vector> #include <vector>
@ -48,6 +47,6 @@ void ApacheApplication::setup()
ApacheApplication& ApacheApplication::instance() ApacheApplication& ApacheApplication::instance()
{ {
static Poco::SingletonHolder<ApacheApplication> sh; static ApacheApplication aa;
return *sh.get(); return aa;
} }

View File

@ -20,7 +20,6 @@
#include "Poco/Crypto/RSACipherImpl.h" #include "Poco/Crypto/RSACipherImpl.h"
#include "Poco/Crypto/EVPCipherImpl.h" #include "Poco/Crypto/EVPCipherImpl.h"
#include "Poco/Exception.h" #include "Poco/Exception.h"
#include "Poco/SingletonHolder.h"
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/err.h> #include <openssl/err.h>
#if OPENSSL_VERSION_NUMBER >= 0x30000000L #if OPENSSL_VERSION_NUMBER >= 0x30000000L
@ -46,15 +45,10 @@ CipherFactory::~CipherFactory()
} }
namespace
{
static Poco::SingletonHolder<CipherFactory> holder;
}
CipherFactory& CipherFactory::defaultFactory() CipherFactory& CipherFactory::defaultFactory()
{ {
return *holder.get(); static CipherFactory cf;
return cf;
} }

View File

@ -14,7 +14,6 @@
#include "Poco/Data/MySQL/SessionHandle.h" #include "Poco/Data/MySQL/SessionHandle.h"
#include "Poco/Data/DataException.h" #include "Poco/Data/DataException.h"
#include "Poco/SingletonHolder.h"
#ifdef POCO_OS_FAMILY_UNIX #ifdef POCO_OS_FAMILY_UNIX
#include <pthread.h> #include <pthread.h>
#endif #endif
@ -51,7 +50,8 @@ public:
static ThreadCleanupHelper& instance() static ThreadCleanupHelper& instance()
{ {
return *_sh.get(); static ThreadCleanupHelper tch;
return tch;
} }
static void cleanup(void* data) static void cleanup(void* data)
@ -61,11 +61,9 @@ public:
private: private:
pthread_key_t _key; pthread_key_t _key;
static Poco::SingletonHolder<ThreadCleanupHelper> _sh;
}; };
Poco::SingletonHolder<ThreadCleanupHelper> ThreadCleanupHelper::_sh;
#endif #endif

View File

@ -352,14 +352,9 @@ private:
}; };
namespace
{
static ActiveThreadPoolSingletonHolder sh;
}
ActiveThreadPool& ActiveThreadPool::defaultPool() ActiveThreadPool& ActiveThreadPool::defaultPool()
{ {
static ActiveThreadPoolSingletonHolder sh;
return *sh.pool(); return *sh.pool();
} }

View File

@ -13,7 +13,6 @@
#include "Poco/ErrorHandler.h" #include "Poco/ErrorHandler.h"
#include "Poco/SingletonHolder.h"
namespace Poco { namespace Poco {
@ -103,11 +102,8 @@ ErrorHandler* ErrorHandler::set(ErrorHandler* pHandler)
ErrorHandler* ErrorHandler::defaultHandler() ErrorHandler* ErrorHandler::defaultHandler()
{ {
// NOTE: Since this is called to initialize the static _pHandler static ErrorHandler eh;
// variable, sh has to be a local static, otherwise we run return &eh;
// into static initialization order issues.
static SingletonHolder<ErrorHandler> sh;
return sh.get();
} }

View File

@ -13,7 +13,6 @@
#include "Poco/LoggingFactory.h" #include "Poco/LoggingFactory.h"
#include "Poco/SingletonHolder.h"
#include "Poco/AsyncChannel.h" #include "Poco/AsyncChannel.h"
#include "Poco/ConsoleChannel.h" #include "Poco/ConsoleChannel.h"
#include "Poco/FileChannel.h" #include "Poco/FileChannel.h"
@ -73,15 +72,10 @@ Formatter::Ptr LoggingFactory::createFormatter(const std::string& className) con
} }
namespace
{
static SingletonHolder<LoggingFactory> sh;
}
LoggingFactory& LoggingFactory::defaultFactory() LoggingFactory& LoggingFactory::defaultFactory()
{ {
return *sh.get(); static LoggingFactory lf;
return lf;
} }

View File

@ -13,7 +13,6 @@
#include "Poco/LoggingRegistry.h" #include "Poco/LoggingRegistry.h"
#include "Poco/SingletonHolder.h"
namespace Poco { namespace Poco {
@ -102,15 +101,10 @@ void LoggingRegistry::clear()
} }
namespace
{
static SingletonHolder<LoggingRegistry> sh;
}
LoggingRegistry& LoggingRegistry::defaultRegistry() LoggingRegistry& LoggingRegistry::defaultRegistry()
{ {
return *sh.get(); static LoggingRegistry lr;
return lr;
} }

View File

@ -13,7 +13,6 @@
#include "Poco/NestedDiagnosticContext.h" #include "Poco/NestedDiagnosticContext.h"
#include "Poco/SingletonHolder.h"
#include "Poco/ThreadLocal.h" #include "Poco/ThreadLocal.h"
@ -114,15 +113,10 @@ void NestedDiagnosticContext::clear()
} }
namespace
{
static ThreadLocal<NestedDiagnosticContext> ndc;
}
NestedDiagnosticContext& NestedDiagnosticContext::current() NestedDiagnosticContext& NestedDiagnosticContext::current()
{ {
return ndc.get(); static NestedDiagnosticContext ndc;
return ndc;
} }

View File

@ -16,7 +16,6 @@
#include "Poco/Notification.h" #include "Poco/Notification.h"
#include "Poco/Observer.h" #include "Poco/Observer.h"
#include "Poco/AutoPtr.h" #include "Poco/AutoPtr.h"
#include "Poco/SingletonHolder.h"
namespace Poco { namespace Poco {
@ -106,15 +105,10 @@ std::size_t NotificationCenter::countObservers() const
} }
namespace
{
static SingletonHolder<NotificationCenter> sh;
}
NotificationCenter& NotificationCenter::defaultCenter() NotificationCenter& NotificationCenter::defaultCenter()
{ {
return *sh.get(); static NotificationCenter nc;
return nc;
} }

View File

@ -15,7 +15,6 @@
#include "Poco/NotificationQueue.h" #include "Poco/NotificationQueue.h"
#include "Poco/NotificationCenter.h" #include "Poco/NotificationCenter.h"
#include "Poco/Notification.h" #include "Poco/Notification.h"
#include "Poco/SingletonHolder.h"
namespace Poco { namespace Poco {
@ -209,15 +208,10 @@ Notification::Ptr NotificationQueue::dequeueOne()
} }
namespace
{
static SingletonHolder<NotificationQueue> sh;
}
NotificationQueue& NotificationQueue::defaultQueue() NotificationQueue& NotificationQueue::defaultQueue()
{ {
return *sh.get(); static NotificationQueue nq;
return nq;
} }

View File

@ -15,7 +15,6 @@
#include "Poco/PriorityNotificationQueue.h" #include "Poco/PriorityNotificationQueue.h"
#include "Poco/NotificationCenter.h" #include "Poco/NotificationCenter.h"
#include "Poco/Notification.h" #include "Poco/Notification.h"
#include "Poco/SingletonHolder.h"
namespace Poco { namespace Poco {
@ -180,15 +179,10 @@ Notification::Ptr PriorityNotificationQueue::dequeueOne()
} }
namespace
{
static SingletonHolder<PriorityNotificationQueue> sh;
}
PriorityNotificationQueue& PriorityNotificationQueue::defaultQueue() PriorityNotificationQueue& PriorityNotificationQueue::defaultQueue()
{ {
return *sh.get(); static PriorityNotificationQueue pnq;
return pnq;
} }

View File

@ -26,7 +26,6 @@
#include "Poco/Windows1251Encoding.h" #include "Poco/Windows1251Encoding.h"
#include "Poco/Windows1252Encoding.h" #include "Poco/Windows1252Encoding.h"
#include "Poco/RWLock.h" #include "Poco/RWLock.h"
#include "Poco/SingletonHolder.h"
#include <map> #include <map>
@ -193,15 +192,10 @@ TextEncoding& TextEncoding::global()
} }
namespace
{
static SingletonHolder<TextEncodingManager> sh;
}
TextEncodingManager& TextEncoding::manager() TextEncodingManager& TextEncoding::manager()
{ {
return *sh.get(); static TextEncodingManager tem;
return tem;
} }

View File

@ -13,7 +13,6 @@
#include "Poco/ThreadLocal.h" #include "Poco/ThreadLocal.h"
#include "Poco/SingletonHolder.h"
#include "Poco/Thread.h" #include "Poco/Thread.h"
@ -54,12 +53,6 @@ TLSAbstractSlot*& ThreadLocalStorage::get(const void* key)
} }
namespace
{
static SingletonHolder<ThreadLocalStorage> sh;
}
ThreadLocalStorage& ThreadLocalStorage::current() ThreadLocalStorage& ThreadLocalStorage::current()
{ {
Thread* pThread = Thread::current(); Thread* pThread = Thread::current();
@ -69,7 +62,8 @@ ThreadLocalStorage& ThreadLocalStorage::current()
} }
else else
{ {
return *sh.get(); static ThreadLocalStorage tls;
return tls;
} }
} }

View File

@ -497,14 +497,9 @@ private:
}; };
namespace
{
static ThreadPoolSingletonHolder sh;
}
ThreadPool& ThreadPool::defaultPool() ThreadPool& ThreadPool::defaultPool()
{ {
static ThreadPoolSingletonHolder sh;
return *sh.pool(); return *sh.pool();
} }

View File

@ -17,7 +17,6 @@
#include "Poco/FileStreamFactory.h" #include "Poco/FileStreamFactory.h"
#include "Poco/URI.h" #include "Poco/URI.h"
#include "Poco/Path.h" #include "Poco/Path.h"
#include "Poco/SingletonHolder.h"
#include "Poco/Exception.h" #include "Poco/Exception.h"
@ -159,15 +158,10 @@ bool URIStreamOpener::supportsScheme(const std::string& scheme)
} }
namespace
{
static SingletonHolder<URIStreamOpener> sh;
}
URIStreamOpener& URIStreamOpener::defaultOpener() URIStreamOpener& URIStreamOpener::defaultOpener()
{ {
return *sh.get(); static URIStreamOpener so;
return so;
} }

View File

@ -18,7 +18,6 @@
#include "Poco/DigestEngine.h" #include "Poco/DigestEngine.h"
#include "Poco/MD5Engine.h" #include "Poco/MD5Engine.h"
#include "Poco/SHA1Engine.h" #include "Poco/SHA1Engine.h"
#include "Poco/SingletonHolder.h"
#include <cstring> #include <cstring>
@ -152,15 +151,10 @@ void UUIDGenerator::seed(UInt32 n)
} }
namespace
{
static SingletonHolder<UUIDGenerator> sh;
}
UUIDGenerator& UUIDGenerator::defaultGenerator() UUIDGenerator& UUIDGenerator::defaultGenerator()
{ {
return *sh.get(); static UUIDGenerator g;
return g;
} }

View File

@ -17,7 +17,6 @@
#include "Poco/Exception.h" #include "Poco/Exception.h"
using Poco::SingletonHolder;
using Poco::FastMutex; using Poco::FastMutex;
using Poco::NotFoundException; using Poco::NotFoundException;
using Poco::ExistsException; using Poco::ExistsException;
@ -137,15 +136,10 @@ void HTTPSessionFactory::setProxyConfig(const HTTPClientSession::ProxyConfig& pr
} }
namespace
{
static SingletonHolder<HTTPSessionFactory> singleton;
}
HTTPSessionFactory& HTTPSessionFactory::defaultFactory() HTTPSessionFactory& HTTPSessionFactory::defaultFactory()
{ {
return *singleton.get(); static HTTPSessionFactory f;
return f;
} }

View File

@ -19,7 +19,6 @@
#include "Poco/SharedLibrary.h" #include "Poco/SharedLibrary.h"
#include "Poco/SingletonHolder.h"
#include "Poco/UnicodeConverter.h" #include "Poco/UnicodeConverter.h"
#include <vector> #include <vector>
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
@ -227,15 +226,10 @@ private:
}; };
namespace
{
static Poco::SingletonHolder<SSPINTLMProvider> sspintlmProviderHolder;
}
SSPINTLMProvider& SSPINTLMProvider::instance() SSPINTLMProvider& SSPINTLMProvider::instance()
{ {
return *sspintlmProviderHolder.get(); static SSPINTLMProvider p;
return p;
} }

View File

@ -24,7 +24,6 @@
#include "Poco/Net/RejectCertificateHandler.h" #include "Poco/Net/RejectCertificateHandler.h"
#include "Poco/Crypto/OpenSSLInitializer.h" #include "Poco/Crypto/OpenSSLInitializer.h"
#include "Poco/Net/SSLException.h" #include "Poco/Net/SSLException.h"
#include "Poco/SingletonHolder.h"
#include "Poco/Delegate.h" #include "Poco/Delegate.h"
#include "Poco/StringTokenizer.h" #include "Poco/StringTokenizer.h"
#include "Poco/Util/Application.h" #include "Poco/Util/Application.h"
@ -107,15 +106,10 @@ void SSLManager::shutdown()
} }
namespace
{
static Poco::SingletonHolder<SSLManager> singleton;
}
SSLManager& SSLManager::instance() SSLManager& SSLManager::instance()
{ {
return *singleton.get(); static SSLManager sm;
return sm;
} }

View File

@ -22,7 +22,6 @@
#include "Poco/Net/Utility.h" #include "Poco/Net/Utility.h"
#include "Poco/Net/PrivateKeyPassphraseHandler.h" #include "Poco/Net/PrivateKeyPassphraseHandler.h"
#include "Poco/Net/RejectCertificateHandler.h" #include "Poco/Net/RejectCertificateHandler.h"
#include "Poco/SingletonHolder.h"
#include "Poco/Delegate.h" #include "Poco/Delegate.h"
#include "Poco/Util/Application.h" #include "Poco/Util/Application.h"
#include "Poco/Util/OptionException.h" #include "Poco/Util/OptionException.h"
@ -81,15 +80,10 @@ SSLManager::~SSLManager()
} }
namespace
{
static Poco::SingletonHolder<SSLManager> singleton;
}
SSLManager& SSLManager::instance() SSLManager& SSLManager::instance()
{ {
return *singleton.get(); static SSLManager sm;
return sm;
} }

View File

@ -1569,15 +1569,10 @@ void SecureSocketImpl::stateMachine()
} }
namespace
{
static Poco::SingletonHolder<StateMachine> stateMachineSingleton;
}
StateMachine& StateMachine::instance() StateMachine& StateMachine::instance()
{ {
return *stateMachineSingleton.get(); static StateMachine sm;
return sm;
} }

View File

@ -15,7 +15,6 @@
#include "Poco/Prometheus/Registry.h" #include "Poco/Prometheus/Registry.h"
#include "Poco/Prometheus/Collector.h" #include "Poco/Prometheus/Collector.h"
#include "Poco/Exception.h" #include "Poco/Exception.h"
#include "Poco/SingletonHolder.h"
using namespace std::string_literals; using namespace std::string_literals;
@ -90,15 +89,10 @@ void Registry::exportTo(Exporter& exporter) const
} }
namespace
{
static SingletonHolder<Registry> sh;
}
Registry& Registry::defaultRegistry() Registry& Registry::defaultRegistry()
{ {
return *sh.get(); static Registry r;
return r;
} }

View File

@ -17,7 +17,6 @@
#include "Poco/DOM/Document.h" #include "Poco/DOM/Document.h"
#include "Poco/DOM/Element.h" #include "Poco/DOM/Element.h"
#include "Poco/String.h" #include "Poco/String.h"
#include "Poco/SingletonHolder.h"
namespace Poco { namespace Poco {
@ -71,15 +70,10 @@ Document* DOMImplementation::createDocument(const XMLString& namespaceURI, const
} }
namespace
{
static Poco::SingletonHolder<DOMImplementation> sh;
}
const DOMImplementation& DOMImplementation::instance() const DOMImplementation& DOMImplementation::instance()
{ {
return *sh.get(); static DOMImplementation di;
return di;
} }