Skip to content

Commit d5a5ebc

Browse files
committedJan 30, 2024
enh: pocoproject#3890: Get rid of SingletonHolder
1 parent 33638df commit d5a5ebc

23 files changed

+44
-168
lines changed
 

‎ApacheConnector/src/ApacheApplication.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "ApacheApplication.h"
1212
#include "ApacheChannel.h"
1313
#include "Poco/Logger.h"
14-
#include "Poco/SingletonHolder.h"
1514
#include <vector>
1615

1716

@@ -48,6 +47,6 @@ void ApacheApplication::setup()
4847

4948
ApacheApplication& ApacheApplication::instance()
5049
{
51-
static Poco::SingletonHolder<ApacheApplication> sh;
52-
return *sh.get();
50+
static ApacheApplication aa;
51+
return aa;
5352
}

‎Crypto/src/CipherFactory.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "Poco/Crypto/RSACipherImpl.h"
2121
#include "Poco/Crypto/EVPCipherImpl.h"
2222
#include "Poco/Exception.h"
23-
#include "Poco/SingletonHolder.h"
2423
#include <openssl/evp.h>
2524
#include <openssl/err.h>
2625
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
@@ -46,15 +45,10 @@ CipherFactory::~CipherFactory()
4645
}
4746

4847

49-
namespace
50-
{
51-
static Poco::SingletonHolder<CipherFactory> holder;
52-
}
53-
54-
5548
CipherFactory& CipherFactory::defaultFactory()
5649
{
57-
return *holder.get();
50+
static CipherFactory cf;
51+
return cf;
5852
}
5953

6054

‎Data/MySQL/src/SessionHandle.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include "Poco/Data/MySQL/SessionHandle.h"
1616
#include "Poco/Data/DataException.h"
17-
#include "Poco/SingletonHolder.h"
1817
#ifdef POCO_OS_FAMILY_UNIX
1918
#include <pthread.h>
2019
#endif
@@ -51,7 +50,8 @@ class ThreadCleanupHelper
5150

5251
static ThreadCleanupHelper& instance()
5352
{
54-
return *_sh.get();
53+
static ThreadCleanupHelper tch;
54+
return tch;
5555
}
5656

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

6262
private:
6363
pthread_key_t _key;
64-
static Poco::SingletonHolder<ThreadCleanupHelper> _sh;
6564
};
6665

6766

68-
Poco::SingletonHolder<ThreadCleanupHelper> ThreadCleanupHelper::_sh;
6967
#endif
7068

7169

‎Foundation/src/ActiveThreadPool.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,9 @@ class ActiveThreadPoolSingletonHolder
352352
};
353353

354354

355-
namespace
356-
{
357-
static ActiveThreadPoolSingletonHolder sh;
358-
}
359-
360-
361355
ActiveThreadPool& ActiveThreadPool::defaultPool()
362356
{
357+
static ActiveThreadPoolSingletonHolder sh;
363358
return *sh.pool();
364359
}
365360

‎Foundation/src/ErrorHandler.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414

1515
#include "Poco/ErrorHandler.h"
16-
#include "Poco/SingletonHolder.h"
1716

1817

1918
namespace Poco {
@@ -103,11 +102,8 @@ ErrorHandler* ErrorHandler::set(ErrorHandler* pHandler)
103102

104103
ErrorHandler* ErrorHandler::defaultHandler()
105104
{
106-
// NOTE: Since this is called to initialize the static _pHandler
107-
// variable, sh has to be a local static, otherwise we run
108-
// into static initialization order issues.
109-
static SingletonHolder<ErrorHandler> sh;
110-
return sh.get();
105+
static ErrorHandler eh;
106+
return &eh;
111107
}
112108

113109

‎Foundation/src/LoggingFactory.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414

1515
#include "Poco/LoggingFactory.h"
16-
#include "Poco/SingletonHolder.h"
1716
#include "Poco/AsyncChannel.h"
1817
#include "Poco/ConsoleChannel.h"
1918
#include "Poco/FileChannel.h"
@@ -73,15 +72,10 @@ Formatter::Ptr LoggingFactory::createFormatter(const std::string& className) con
7372
}
7473

7574

76-
namespace
77-
{
78-
static SingletonHolder<LoggingFactory> sh;
79-
}
80-
81-
8275
LoggingFactory& LoggingFactory::defaultFactory()
8376
{
84-
return *sh.get();
77+
static LoggingFactory lf;
78+
return lf;
8579
}
8680

8781

‎Foundation/src/LoggingRegistry.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414

1515
#include "Poco/LoggingRegistry.h"
16-
#include "Poco/SingletonHolder.h"
1716

1817

1918
namespace Poco {
@@ -102,15 +101,10 @@ void LoggingRegistry::clear()
102101
}
103102

104103

105-
namespace
106-
{
107-
static SingletonHolder<LoggingRegistry> sh;
108-
}
109-
110-
111104
LoggingRegistry& LoggingRegistry::defaultRegistry()
112105
{
113-
return *sh.get();
106+
static LoggingRegistry lr;
107+
return lr;
114108
}
115109

116110

‎Foundation/src/NestedDiagnosticContext.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414

1515
#include "Poco/NestedDiagnosticContext.h"
16-
#include "Poco/SingletonHolder.h"
1716
#include "Poco/ThreadLocal.h"
1817

1918

@@ -114,15 +113,10 @@ void NestedDiagnosticContext::clear()
114113
}
115114

116115

117-
namespace
118-
{
119-
static ThreadLocal<NestedDiagnosticContext> ndc;
120-
}
121-
122-
123116
NestedDiagnosticContext& NestedDiagnosticContext::current()
124117
{
125-
return ndc.get();
118+
static NestedDiagnosticContext ndc;
119+
return ndc;
126120
}
127121

128122

‎Foundation/src/NotificationCenter.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "Poco/Notification.h"
1717
#include "Poco/Observer.h"
1818
#include "Poco/AutoPtr.h"
19-
#include "Poco/SingletonHolder.h"
2019

2120

2221
namespace Poco {
@@ -106,15 +105,10 @@ std::size_t NotificationCenter::countObservers() const
106105
}
107106

108107

109-
namespace
110-
{
111-
static SingletonHolder<NotificationCenter> sh;
112-
}
113-
114-
115108
NotificationCenter& NotificationCenter::defaultCenter()
116109
{
117-
return *sh.get();
110+
static NotificationCenter nc;
111+
return nc;
118112
}
119113

120114

‎Foundation/src/NotificationQueue.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "Poco/NotificationQueue.h"
1616
#include "Poco/NotificationCenter.h"
1717
#include "Poco/Notification.h"
18-
#include "Poco/SingletonHolder.h"
1918

2019

2120
namespace Poco {
@@ -209,15 +208,10 @@ Notification::Ptr NotificationQueue::dequeueOne()
209208
}
210209

211210

212-
namespace
213-
{
214-
static SingletonHolder<NotificationQueue> sh;
215-
}
216-
217-
218211
NotificationQueue& NotificationQueue::defaultQueue()
219212
{
220-
return *sh.get();
213+
static NotificationQueue nq;
214+
return nq;
221215
}
222216

223217

‎Foundation/src/PriorityNotificationQueue.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "Poco/PriorityNotificationQueue.h"
1616
#include "Poco/NotificationCenter.h"
1717
#include "Poco/Notification.h"
18-
#include "Poco/SingletonHolder.h"
1918

2019

2120
namespace Poco {
@@ -180,15 +179,10 @@ Notification::Ptr PriorityNotificationQueue::dequeueOne()
180179
}
181180

182181

183-
namespace
184-
{
185-
static SingletonHolder<PriorityNotificationQueue> sh;
186-
}
187-
188-
189182
PriorityNotificationQueue& PriorityNotificationQueue::defaultQueue()
190183
{
191-
return *sh.get();
184+
static PriorityNotificationQueue pnq;
185+
return pnq;
192186
}
193187

194188

‎Foundation/src/TextEncoding.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "Poco/Windows1251Encoding.h"
2727
#include "Poco/Windows1252Encoding.h"
2828
#include "Poco/RWLock.h"
29-
#include "Poco/SingletonHolder.h"
3029
#include <map>
3130

3231

@@ -193,15 +192,10 @@ TextEncoding& TextEncoding::global()
193192
}
194193

195194

196-
namespace
197-
{
198-
static SingletonHolder<TextEncodingManager> sh;
199-
}
200-
201-
202195
TextEncodingManager& TextEncoding::manager()
203196
{
204-
return *sh.get();
197+
static TextEncodingManager tem;
198+
return tem;
205199
}
206200

207201

‎Foundation/src/ThreadLocal.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414

1515
#include "Poco/ThreadLocal.h"
16-
#include "Poco/SingletonHolder.h"
1716
#include "Poco/Thread.h"
1817

1918

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

5655

57-
namespace
58-
{
59-
static SingletonHolder<ThreadLocalStorage> sh;
60-
}
61-
62-
6356
ThreadLocalStorage& ThreadLocalStorage::current()
6457
{
6558
Thread* pThread = Thread::current();
@@ -69,7 +62,8 @@ ThreadLocalStorage& ThreadLocalStorage::current()
6962
}
7063
else
7164
{
72-
return *sh.get();
65+
static ThreadLocalStorage tls;
66+
return tls;
7367
}
7468
}
7569

‎Foundation/src/ThreadPool.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,9 @@ class ThreadPoolSingletonHolder
497497
};
498498

499499

500-
namespace
501-
{
502-
static ThreadPoolSingletonHolder sh;
503-
}
504-
505-
506500
ThreadPool& ThreadPool::defaultPool()
507501
{
502+
static ThreadPoolSingletonHolder sh;
508503
return *sh.pool();
509504
}
510505

‎Foundation/src/URIStreamOpener.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "Poco/FileStreamFactory.h"
1818
#include "Poco/URI.h"
1919
#include "Poco/Path.h"
20-
#include "Poco/SingletonHolder.h"
2120
#include "Poco/Exception.h"
2221

2322

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

161160

162-
namespace
163-
{
164-
static SingletonHolder<URIStreamOpener> sh;
165-
}
166-
167-
168161
URIStreamOpener& URIStreamOpener::defaultOpener()
169162
{
170-
return *sh.get();
163+
static URIStreamOpener so;
164+
return so;
171165
}
172166

173167

‎Foundation/src/UUIDGenerator.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "Poco/DigestEngine.h"
1919
#include "Poco/MD5Engine.h"
2020
#include "Poco/SHA1Engine.h"
21-
#include "Poco/SingletonHolder.h"
2221
#include <cstring>
2322

2423

@@ -152,15 +151,10 @@ void UUIDGenerator::seed(UInt32 n)
152151
}
153152

154153

155-
namespace
156-
{
157-
static SingletonHolder<UUIDGenerator> sh;
158-
}
159-
160-
161154
UUIDGenerator& UUIDGenerator::defaultGenerator()
162155
{
163-
return *sh.get();
156+
static UUIDGenerator g;
157+
return g;
164158
}
165159

166160

‎Net/src/HTTPSessionFactory.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "Poco/Exception.h"
1818

1919

20-
using Poco::SingletonHolder;
2120
using Poco::FastMutex;
2221
using Poco::NotFoundException;
2322
using Poco::ExistsException;
@@ -137,15 +136,10 @@ void HTTPSessionFactory::setProxyConfig(const HTTPClientSession::ProxyConfig& pr
137136
}
138137

139138

140-
namespace
141-
{
142-
static SingletonHolder<HTTPSessionFactory> singleton;
143-
}
144-
145-
146139
HTTPSessionFactory& HTTPSessionFactory::defaultFactory()
147140
{
148-
return *singleton.get();
141+
static HTTPSessionFactory f;
142+
return f;
149143
}
150144

151145

‎Net/src/SSPINTLMCredentials.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020

2121
#include "Poco/SharedLibrary.h"
22-
#include "Poco/SingletonHolder.h"
2322
#include "Poco/UnicodeConverter.h"
2423
#include <vector>
2524
#define WIN32_LEAN_AND_MEAN
@@ -227,15 +226,10 @@ class SSPINTLMProvider
227226
};
228227

229228

230-
namespace
231-
{
232-
static Poco::SingletonHolder<SSPINTLMProvider> sspintlmProviderHolder;
233-
}
234-
235-
236229
SSPINTLMProvider& SSPINTLMProvider::instance()
237230
{
238-
return *sspintlmProviderHolder.get();
231+
static SSPINTLMProvider p;
232+
return p;
239233
}
240234

241235

‎NetSSL_OpenSSL/src/SSLManager.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "Poco/Net/RejectCertificateHandler.h"
2525
#include "Poco/Crypto/OpenSSLInitializer.h"
2626
#include "Poco/Net/SSLException.h"
27-
#include "Poco/SingletonHolder.h"
2827
#include "Poco/Delegate.h"
2928
#include "Poco/StringTokenizer.h"
3029
#include "Poco/Util/Application.h"
@@ -107,15 +106,10 @@ void SSLManager::shutdown()
107106
}
108107

109108

110-
namespace
111-
{
112-
static Poco::SingletonHolder<SSLManager> singleton;
113-
}
114-
115-
116109
SSLManager& SSLManager::instance()
117110
{
118-
return *singleton.get();
111+
static SSLManager sm;
112+
return sm;
119113
}
120114

121115

‎NetSSL_Win/src/SSLManager.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "Poco/Net/Utility.h"
2323
#include "Poco/Net/PrivateKeyPassphraseHandler.h"
2424
#include "Poco/Net/RejectCertificateHandler.h"
25-
#include "Poco/SingletonHolder.h"
2625
#include "Poco/Delegate.h"
2726
#include "Poco/Util/Application.h"
2827
#include "Poco/Util/OptionException.h"
@@ -81,15 +80,10 @@ SSLManager::~SSLManager()
8180
}
8281

8382

84-
namespace
85-
{
86-
static Poco::SingletonHolder<SSLManager> singleton;
87-
}
88-
89-
9083
SSLManager& SSLManager::instance()
9184
{
92-
return *singleton.get();
85+
static SSLManager sm;
86+
return sm;
9387
}
9488

9589

‎NetSSL_Win/src/SecureSocketImpl.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -1569,15 +1569,10 @@ void SecureSocketImpl::stateMachine()
15691569
}
15701570

15711571

1572-
namespace
1573-
{
1574-
static Poco::SingletonHolder<StateMachine> stateMachineSingleton;
1575-
}
1576-
1577-
15781572
StateMachine& StateMachine::instance()
15791573
{
1580-
return *stateMachineSingleton.get();
1574+
static StateMachine sm;
1575+
return sm;
15811576
}
15821577

15831578

‎Prometheus/src/Registry.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "Poco/Prometheus/Registry.h"
1616
#include "Poco/Prometheus/Collector.h"
1717
#include "Poco/Exception.h"
18-
#include "Poco/SingletonHolder.h"
1918

2019

2120
using namespace std::string_literals;
@@ -90,15 +89,10 @@ void Registry::exportTo(Exporter& exporter) const
9089
}
9190

9291

93-
namespace
94-
{
95-
static SingletonHolder<Registry> sh;
96-
}
97-
98-
9992
Registry& Registry::defaultRegistry()
10093
{
101-
return *sh.get();
94+
static Registry r;
95+
return r;
10296
}
10397

10498

‎XML/src/DOMImplementation.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "Poco/DOM/Document.h"
1818
#include "Poco/DOM/Element.h"
1919
#include "Poco/String.h"
20-
#include "Poco/SingletonHolder.h"
2120

2221

2322
namespace Poco {
@@ -71,15 +70,10 @@ Document* DOMImplementation::createDocument(const XMLString& namespaceURI, const
7170
}
7271

7372

74-
namespace
75-
{
76-
static Poco::SingletonHolder<DOMImplementation> sh;
77-
}
78-
79-
8073
const DOMImplementation& DOMImplementation::instance()
8174
{
82-
return *sh.get();
75+
static DOMImplementation di;
76+
return di;
8377
}
8478

8579

0 commit comments

Comments
 (0)
Please sign in to comment.