Skip to content

Commit

Permalink
enh: #3890: Get rid of SingletonHolder
Browse files Browse the repository at this point in the history
  • Loading branch information
obiltschnig committed Jan 30, 2024
1 parent 33638df commit d5a5ebc
Show file tree
Hide file tree
Showing 23 changed files with 44 additions and 168 deletions.
5 changes: 2 additions & 3 deletions ApacheConnector/src/ApacheApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "ApacheApplication.h"
#include "ApacheChannel.h"
#include "Poco/Logger.h"
#include "Poco/SingletonHolder.h"
#include <vector>


Expand Down Expand Up @@ -48,6 +47,6 @@ void ApacheApplication::setup()

ApacheApplication& ApacheApplication::instance()
{
static Poco::SingletonHolder<ApacheApplication> sh;
return *sh.get();
static ApacheApplication aa;
return aa;
}
10 changes: 2 additions & 8 deletions Crypto/src/CipherFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "Poco/Crypto/RSACipherImpl.h"
#include "Poco/Crypto/EVPCipherImpl.h"
#include "Poco/Exception.h"
#include "Poco/SingletonHolder.h"
#include <openssl/evp.h>
#include <openssl/err.h>
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
Expand All @@ -46,15 +45,10 @@ CipherFactory::~CipherFactory()
}


namespace
{
static Poco::SingletonHolder<CipherFactory> holder;
}


CipherFactory& CipherFactory::defaultFactory()
{
return *holder.get();
static CipherFactory cf;
return cf;
}


Expand Down
6 changes: 2 additions & 4 deletions Data/MySQL/src/SessionHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include "Poco/Data/MySQL/SessionHandle.h"
#include "Poco/Data/DataException.h"
#include "Poco/SingletonHolder.h"
#ifdef POCO_OS_FAMILY_UNIX
#include <pthread.h>
#endif
Expand Down Expand Up @@ -51,7 +50,8 @@ class ThreadCleanupHelper

static ThreadCleanupHelper& instance()
{
return *_sh.get();
static ThreadCleanupHelper tch;
return tch;
}

static void cleanup(void* data)
Expand All @@ -61,11 +61,9 @@ class ThreadCleanupHelper

private:
pthread_key_t _key;
static Poco::SingletonHolder<ThreadCleanupHelper> _sh;
};


Poco::SingletonHolder<ThreadCleanupHelper> ThreadCleanupHelper::_sh;
#endif


Expand Down
7 changes: 1 addition & 6 deletions Foundation/src/ActiveThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,9 @@ class ActiveThreadPoolSingletonHolder
};


namespace
{
static ActiveThreadPoolSingletonHolder sh;
}


ActiveThreadPool& ActiveThreadPool::defaultPool()
{
static ActiveThreadPoolSingletonHolder sh;
return *sh.pool();
}

Expand Down
8 changes: 2 additions & 6 deletions Foundation/src/ErrorHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


#include "Poco/ErrorHandler.h"
#include "Poco/SingletonHolder.h"


namespace Poco {
Expand Down Expand Up @@ -103,11 +102,8 @@ ErrorHandler* ErrorHandler::set(ErrorHandler* pHandler)

ErrorHandler* ErrorHandler::defaultHandler()
{
// NOTE: Since this is called to initialize the static _pHandler
// variable, sh has to be a local static, otherwise we run
// into static initialization order issues.
static SingletonHolder<ErrorHandler> sh;
return sh.get();
static ErrorHandler eh;
return &eh;
}


Expand Down
10 changes: 2 additions & 8 deletions Foundation/src/LoggingFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


#include "Poco/LoggingFactory.h"
#include "Poco/SingletonHolder.h"
#include "Poco/AsyncChannel.h"
#include "Poco/ConsoleChannel.h"
#include "Poco/FileChannel.h"
Expand Down Expand Up @@ -73,15 +72,10 @@ Formatter::Ptr LoggingFactory::createFormatter(const std::string& className) con
}


namespace
{
static SingletonHolder<LoggingFactory> sh;
}


LoggingFactory& LoggingFactory::defaultFactory()
{
return *sh.get();
static LoggingFactory lf;
return lf;
}


Expand Down
10 changes: 2 additions & 8 deletions Foundation/src/LoggingRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


#include "Poco/LoggingRegistry.h"
#include "Poco/SingletonHolder.h"


namespace Poco {
Expand Down Expand Up @@ -102,15 +101,10 @@ void LoggingRegistry::clear()
}


namespace
{
static SingletonHolder<LoggingRegistry> sh;
}


LoggingRegistry& LoggingRegistry::defaultRegistry()
{
return *sh.get();
static LoggingRegistry lr;
return lr;
}


Expand Down
10 changes: 2 additions & 8 deletions Foundation/src/NestedDiagnosticContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


#include "Poco/NestedDiagnosticContext.h"
#include "Poco/SingletonHolder.h"
#include "Poco/ThreadLocal.h"


Expand Down Expand Up @@ -114,15 +113,10 @@ void NestedDiagnosticContext::clear()
}


namespace
{
static ThreadLocal<NestedDiagnosticContext> ndc;
}


NestedDiagnosticContext& NestedDiagnosticContext::current()
{
return ndc.get();
static NestedDiagnosticContext ndc;

This comment has been minimized.

Copy link
@siren186

siren186 May 14, 2024

Member

Without threadlocal, NDC will crash in multi-thread environment

return ndc;
}


Expand Down
10 changes: 2 additions & 8 deletions Foundation/src/NotificationCenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "Poco/Notification.h"
#include "Poco/Observer.h"
#include "Poco/AutoPtr.h"
#include "Poco/SingletonHolder.h"


namespace Poco {
Expand Down Expand Up @@ -106,15 +105,10 @@ std::size_t NotificationCenter::countObservers() const
}


namespace
{
static SingletonHolder<NotificationCenter> sh;
}


NotificationCenter& NotificationCenter::defaultCenter()
{
return *sh.get();
static NotificationCenter nc;
return nc;
}


Expand Down
10 changes: 2 additions & 8 deletions Foundation/src/NotificationQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "Poco/NotificationQueue.h"
#include "Poco/NotificationCenter.h"
#include "Poco/Notification.h"
#include "Poco/SingletonHolder.h"


namespace Poco {
Expand Down Expand Up @@ -209,15 +208,10 @@ Notification::Ptr NotificationQueue::dequeueOne()
}


namespace
{
static SingletonHolder<NotificationQueue> sh;
}


NotificationQueue& NotificationQueue::defaultQueue()
{
return *sh.get();
static NotificationQueue nq;
return nq;
}


Expand Down
10 changes: 2 additions & 8 deletions Foundation/src/PriorityNotificationQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "Poco/PriorityNotificationQueue.h"
#include "Poco/NotificationCenter.h"
#include "Poco/Notification.h"
#include "Poco/SingletonHolder.h"


namespace Poco {
Expand Down Expand Up @@ -180,15 +179,10 @@ Notification::Ptr PriorityNotificationQueue::dequeueOne()
}


namespace
{
static SingletonHolder<PriorityNotificationQueue> sh;
}


PriorityNotificationQueue& PriorityNotificationQueue::defaultQueue()
{
return *sh.get();
static PriorityNotificationQueue pnq;
return pnq;
}


Expand Down
10 changes: 2 additions & 8 deletions Foundation/src/TextEncoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "Poco/Windows1251Encoding.h"
#include "Poco/Windows1252Encoding.h"
#include "Poco/RWLock.h"
#include "Poco/SingletonHolder.h"
#include <map>


Expand Down Expand Up @@ -193,15 +192,10 @@ TextEncoding& TextEncoding::global()
}


namespace
{
static SingletonHolder<TextEncodingManager> sh;
}


TextEncodingManager& TextEncoding::manager()
{
return *sh.get();
static TextEncodingManager tem;
return tem;
}


Expand Down
10 changes: 2 additions & 8 deletions Foundation/src/ThreadLocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


#include "Poco/ThreadLocal.h"
#include "Poco/SingletonHolder.h"
#include "Poco/Thread.h"


Expand Down Expand Up @@ -54,12 +53,6 @@ TLSAbstractSlot*& ThreadLocalStorage::get(const void* key)
}


namespace
{
static SingletonHolder<ThreadLocalStorage> sh;
}


ThreadLocalStorage& ThreadLocalStorage::current()
{
Thread* pThread = Thread::current();
Expand All @@ -69,7 +62,8 @@ ThreadLocalStorage& ThreadLocalStorage::current()
}
else
{
return *sh.get();
static ThreadLocalStorage tls;
return tls;
}
}

Expand Down
7 changes: 1 addition & 6 deletions Foundation/src/ThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,14 +497,9 @@ class ThreadPoolSingletonHolder
};


namespace
{
static ThreadPoolSingletonHolder sh;
}


ThreadPool& ThreadPool::defaultPool()
{
static ThreadPoolSingletonHolder sh;
return *sh.pool();
}

Expand Down
10 changes: 2 additions & 8 deletions Foundation/src/URIStreamOpener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "Poco/FileStreamFactory.h"
#include "Poco/URI.h"
#include "Poco/Path.h"
#include "Poco/SingletonHolder.h"
#include "Poco/Exception.h"


Expand Down Expand Up @@ -159,15 +158,10 @@ bool URIStreamOpener::supportsScheme(const std::string& scheme)
}


namespace
{
static SingletonHolder<URIStreamOpener> sh;
}


URIStreamOpener& URIStreamOpener::defaultOpener()
{
return *sh.get();
static URIStreamOpener so;
return so;
}


Expand Down
10 changes: 2 additions & 8 deletions Foundation/src/UUIDGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "Poco/DigestEngine.h"
#include "Poco/MD5Engine.h"
#include "Poco/SHA1Engine.h"
#include "Poco/SingletonHolder.h"
#include <cstring>


Expand Down Expand Up @@ -152,15 +151,10 @@ void UUIDGenerator::seed(UInt32 n)
}


namespace
{
static SingletonHolder<UUIDGenerator> sh;
}


UUIDGenerator& UUIDGenerator::defaultGenerator()
{
return *sh.get();
static UUIDGenerator g;
return g;
}


Expand Down
Loading

0 comments on commit d5a5ebc

Please sign in to comment.