summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2014-06-29 00:06:23 (GMT)
committerChristian Pointner <equinox@anytun.org>2014-06-29 00:06:23 (GMT)
commit92a551b96e625257def26771155ebd64c6d8757e (patch)
tree7d5b2d0a043f746bfb10ccc9679ac59646a95b72
parentb35d79b1feee163600305db7dcde9b4a7150f1cc (diff)
fixed not working singletons - still not threadsafe but at least they don't pretend to be
-rw-r--r--ChangeLog4
-rw-r--r--src/connectionList.cpp12
-rw-r--r--src/connectionList.h13
-rw-r--r--src/log.cpp11
-rw-r--r--src/log.h15
-rw-r--r--src/options.cpp11
-rw-r--r--src/options.h14
-rw-r--r--src/resolver.cpp11
-rw-r--r--src/resolver.h13
-rw-r--r--src/routingTable.cpp12
-rw-r--r--src/routingTable.h11
-rw-r--r--src/signalController.cpp12
-rw-r--r--src/signalController.h13
-rw-r--r--src/syncQueue.cpp14
-rw-r--r--src/syncQueue.h11
15 files changed, 21 insertions, 156 deletions
diff --git a/ChangeLog b/ChangeLog
index 190adc9..106374d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,7 @@
-201?.??.?? -- Version 0.?.?
+2014.??.?? -- Version 0.3.5
* added support for clang
-* added libnettle as additional crypot library option
+* added libnettle as additional crypto library option
2011.12.30 -- Version 0.3.4
diff --git a/src/connectionList.cpp b/src/connectionList.cpp
index f5236e1..804aa6e 100644
--- a/src/connectionList.cpp
+++ b/src/connectionList.cpp
@@ -38,20 +38,12 @@
#include "connectionList.h"
-ConnectionList* ConnectionList::inst = NULL;
-Mutex ConnectionList::instMutex;
ConnectionList& gConnectionList = ConnectionList::instance();
-
ConnectionList& ConnectionList::instance()
{
- Lock lock(instMutex);
- static instanceCleaner c;
- if(!inst) {
- inst = new ConnectionList();
- }
-
- return *inst;
+ static ConnectionList instance;
+ return instance;
}
ConnectionList::ConnectionList()
diff --git a/src/connectionList.h b/src/connectionList.h
index e0adf55..46bb998 100644
--- a/src/connectionList.h
+++ b/src/connectionList.h
@@ -47,7 +47,9 @@ class ConnectionList
public:
ConnectionList();
~ConnectionList();
+
static ConnectionList& instance();
+
void addConnection(ConnectionParam& conn, uint16_t mux);
const ConnectionMap::iterator getConnection(uint16_t mux);
const ConnectionMap::iterator getEnd();
@@ -60,17 +62,6 @@ public:
Mutex& getMutex();
private:
- static Mutex instMutex;
- static ConnectionList* inst;
- class instanceCleaner
- {
- public:
- ~instanceCleaner() {
- if(ConnectionList::inst != 0) {
- delete ConnectionList::inst;
- }
- }
- };
ConnectionList(const ConnectionList& s);
void operator=(const ConnectionList& s);
ConnectionMap connections_;
diff --git a/src/log.cpp b/src/log.cpp
index 0851444..3b162cf 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -36,8 +36,6 @@
#include "threadUtils.hpp"
-Log* Log::inst = NULL;
-Mutex Log::instMutex;
Log& cLog = Log::instance();
LogStringBuilder::LogStringBuilder(LogStringBuilder const& src) : log(src.log), prio(src.prio)
@@ -57,13 +55,8 @@ LogStringBuilder::~LogStringBuilder()
Log& Log::instance()
{
- Lock lock(instMutex);
- static instanceCleaner c;
- if(!inst) {
- inst = new Log();
- }
-
- return *inst;
+ static Log instance;
+ return instance;
}
void Log::addTarget(std::string conf)
diff --git a/src/log.h b/src/log.h
index e45ee8e..5ab82fe 100644
--- a/src/log.h
+++ b/src/log.h
@@ -77,27 +77,14 @@ public:
private:
Log() {};
~Log() {};
+
Log(const Log& l);
void operator=(const Log& l);
- static Log* inst;
- static Mutex instMutex;
- class instanceCleaner
- {
- public:
- ~instanceCleaner() {
- if(Log::inst != 0) {
- delete Log::inst;
- }
- }
- };
- friend class instanceCleaner;
-
void log(std::string msg, int prio);
Mutex mutex;
friend class LogStringBuilder;
-
LogTargetList targets;
};
diff --git a/src/options.cpp b/src/options.cpp
index 199ef04..815cee0 100644
--- a/src/options.cpp
+++ b/src/options.cpp
@@ -150,19 +150,12 @@ std::istream& operator>>(std::istream& stream, OptionNetwork& network)
return stream;
}
-Options* Options::inst = NULL;
-Mutex Options::instMutex;
Options& gOpt = Options::instance();
Options& Options::instance()
{
- Lock lock(instMutex);
- static instanceCleaner c;
- if(!inst) {
- inst = new Options();
- }
-
- return *inst;
+ static Options instance;
+ return instance;
}
Options::Options() : key_(uint32_t(0)), salt_(uint32_t(0))
diff --git a/src/options.h b/src/options.h
index 6ca9e5b..bafdf5e 100644
--- a/src/options.h
+++ b/src/options.h
@@ -174,22 +174,8 @@ private:
Options(const Options& l);
void operator=(const Options& l);
- static Options* inst;
- static ::Mutex instMutex;
- class instanceCleaner
- {
- public:
- ~instanceCleaner() {
- if(Options::inst != 0) {
- delete Options::inst;
- }
- }
- };
- friend class instanceCleaner;
-
::SharedMutex mutex;
-
bool cluster_opts;
bool connection_opts;
diff --git a/src/resolver.cpp b/src/resolver.cpp
index afca093..aae1f5f 100644
--- a/src/resolver.cpp
+++ b/src/resolver.cpp
@@ -80,19 +80,12 @@ void ResolveHandler<Proto>::operator()(const boost::system::error_code& e, boost
}
}
-Resolver* Resolver::inst = NULL;
-Mutex Resolver::instMutex;
Resolver& gResolver = Resolver::instance();
Resolver& Resolver::instance()
{
- Lock lock(instMutex);
- static instanceCleaner c;
- if(!inst) {
- inst = new Resolver();
- }
-
- return *inst;
+ static Resolver instance;
+ return instance;
}
Resolver::Resolver() : udp_resolver_(io_service_), tcp_resolver_(io_service_), thread_(NULL)
diff --git a/src/resolver.h b/src/resolver.h
index 5a08f90..4abca9b 100644
--- a/src/resolver.h
+++ b/src/resolver.h
@@ -79,19 +79,6 @@ private:
Resolver(const Resolver& r);
void operator=(const Resolver& r);
- static Resolver* inst;
- static ::Mutex instMutex;
- class instanceCleaner
- {
- public:
- ~instanceCleaner() {
- if(Resolver::inst != 0) {
- delete Resolver::inst;
- }
- }
- };
- friend class instanceCleaner;
-
boost::asio::io_service io_service_;
boost::asio::ip::udp::resolver udp_resolver_;
boost::asio::ip::tcp::resolver tcp_resolver_;
diff --git a/src/routingTable.cpp b/src/routingTable.cpp
index 82b302a..a802ecf 100644
--- a/src/routingTable.cpp
+++ b/src/routingTable.cpp
@@ -37,20 +37,12 @@
#include "routingTable.h"
#include "routingTree.hpp"
-RoutingTable* RoutingTable::inst = NULL;
-Mutex RoutingTable::instMutex;
RoutingTable& gRoutingTable = RoutingTable::instance();
-
RoutingTable& RoutingTable::instance()
{
- Lock lock(instMutex);
- static instanceCleaner c;
- if(!inst) {
- inst = new RoutingTable();
- }
-
- return *inst;
+ static RoutingTable instance;
+ return instance;
}
RoutingTable::RoutingTable()
diff --git a/src/routingTable.h b/src/routingTable.h
index c7e68e4..3171930 100644
--- a/src/routingTable.h
+++ b/src/routingTable.h
@@ -63,17 +63,6 @@ public:
RoutingMap::iterator getEndUnlocked(network_address_type_t type);
private:
- static Mutex instMutex;
- static RoutingTable* inst;
- class instanceCleaner
- {
- public:
- ~instanceCleaner() {
- if(RoutingTable::inst != 0) {
- delete RoutingTable::inst;
- }
- }
- };
RoutingTable(const RoutingTable& s);
void operator=(const RoutingTable& s);
boost::array<RoutingMap,3> routes_;
diff --git a/src/signalController.cpp b/src/signalController.cpp
index f4ae059..b9e2f25 100644
--- a/src/signalController.cpp
+++ b/src/signalController.cpp
@@ -39,19 +39,13 @@
#include "anytunError.h"
#include "threadUtils.hpp"
-SignalController* SignalController::inst = NULL;
-Mutex SignalController::instMutex;
+
SignalController& gSignalController = SignalController::instance();
SignalController& SignalController::instance()
{
- Lock lock(instMutex);
- static instanceCleaner c;
- if(!inst) {
- inst = new SignalController();
- }
-
- return *inst;
+ static SignalController instance;
+ return instance;
}
int SigErrorHandler(int /*sig*/, const std::string& msg)
diff --git a/src/signalController.h b/src/signalController.h
index a0d417b..ebd2942 100644
--- a/src/signalController.h
+++ b/src/signalController.h
@@ -69,19 +69,6 @@ private:
SignalController(const SignalController& s);
void operator=(const SignalController& s);
- static SignalController* inst;
- static Mutex instMutex;
- class instanceCleaner
- {
- public:
- ~instanceCleaner() {
- if(SignalController::inst != NULL) {
- delete SignalController::inst;
- }
- }
- };
- friend class instanceCleaner;
-
typedef std::pair<int, std::string> SigPair;
std::queue<SigPair> sigQueue;
Mutex sigQueueMutex;
diff --git a/src/syncQueue.cpp b/src/syncQueue.cpp
index 9e9cef5..338637c 100644
--- a/src/syncQueue.cpp
+++ b/src/syncQueue.cpp
@@ -43,20 +43,12 @@
#include "syncQueue.h"
-SyncQueue* SyncQueue::inst = NULL;
-Mutex SyncQueue::instMutex;
SyncQueue& gSyncQueue = SyncQueue::instance();
-
SyncQueue& SyncQueue::instance()
{
- Lock lock(instMutex);
- static instanceCleaner c;
- if(!inst) {
- inst = new SyncQueue();
- }
-
- return *inst;
+ static SyncQueue instance;
+ return instance;
}
void SyncQueue::push(const SyncCommand& scom)
@@ -73,7 +65,7 @@ void SyncQueue::push(const SyncCommand& scom)
void SyncQueue::push(const std::string& str)
{
Lock lock(mutex_);
- // std::cout << "Debug" << std:endl;
+ // std::cout << "Debug" << std:endl;
if(syncServer_) {
syncServer_->send(str);
}
diff --git a/src/syncQueue.h b/src/syncQueue.h
index fb01a40..d95519f 100644
--- a/src/syncQueue.h
+++ b/src/syncQueue.h
@@ -55,17 +55,6 @@ public:
bool empty();
private:
- static Mutex instMutex;
- static SyncQueue* inst;
- class instanceCleaner
- {
- public:
- ~instanceCleaner() {
- if(SyncQueue::inst != 0) {
- delete SyncQueue::inst;
- }
- }
- };
SyncQueue(const SyncQueue& s);
void operator=(const SyncQueue& s);
Mutex mutex_;