diff --git a/src/libYARP_OS/include/yarp/os/Carriers.h b/src/libYARP_OS/include/yarp/os/Carriers.h index 9e03cd6d6f0..4dcd27cbbd5 100644 --- a/src/libYARP_OS/include/yarp/os/Carriers.h +++ b/src/libYARP_OS/include/yarp/os/Carriers.h @@ -104,8 +104,6 @@ class YARP_OS_API yarp::os::Carriers static Carriers& getInstance(); - static void removeInstance(); - static Bottle listCarriers(); private: diff --git a/src/libYARP_OS/include/yarp/os/impl/LogForwarder.h b/src/libYARP_OS/include/yarp/os/impl/LogForwarder.h index 88350d49732..e2d735fffd0 100644 --- a/src/libYARP_OS/include/yarp/os/impl/LogForwarder.h +++ b/src/libYARP_OS/include/yarp/os/impl/LogForwarder.h @@ -24,7 +24,6 @@ class YARP_OS_API LogForwarder { public: static LogForwarder* getInstance(); - static void clearInstance(); void forward (const std::string& message); protected: LogForwarder(); @@ -34,9 +33,8 @@ class YARP_OS_API LogForwarder char logPortName[MAX_STRING_SIZE]; yarp::os::BufferedPort* outputPort; private: - LogForwarder(LogForwarder const&){}; - LogForwarder& operator=(LogForwarder const&){return *this;}; //@@@checkme - static LogForwarder* instance; + LogForwarder(LogForwarder const&){} + LogForwarder& operator=(LogForwarder const&){return *this;} }; } // namespace os diff --git a/src/libYARP_OS/src/Carriers.cpp b/src/libYARP_OS/src/Carriers.cpp index 9019db15141..be3c700b611 100644 --- a/src/libYARP_OS/src/Carriers.cpp +++ b/src/libYARP_OS/src/Carriers.cpp @@ -35,7 +35,6 @@ using namespace yarp::os; class Carriers::Private : public YarpPluginSelector { public: - static Carriers* yarp_carriers_instance; static yarp::os::Mutex mutex; std::vector delegates; @@ -52,7 +51,6 @@ class Carriers::Private : public YarpPluginSelector virtual bool select(Searchable& options) override; }; -Carriers* Carriers::Private::yarp_carriers_instance = nullptr; yarp::os::Mutex Carriers::Private::mutex {}; @@ -326,22 +324,8 @@ bool Carrier::reply(ConnectionState& proto, SizedWriter& writer) Carriers& Carriers::getInstance() { - yarp::os::LockGuard guard(Private::mutex); - if (Private::yarp_carriers_instance == nullptr) { - Private::yarp_carriers_instance = new Carriers(); - yAssert(Private::yarp_carriers_instance != nullptr); - } - return *Private::yarp_carriers_instance; -} - - -void Carriers::removeInstance() -{ - yarp::os::LockGuard guard(Private::mutex); - if (Private::yarp_carriers_instance != nullptr) { - delete Private::yarp_carriers_instance; - Private::yarp_carriers_instance = nullptr; - } + static Carriers instance; + return instance; } diff --git a/src/libYARP_OS/src/LogForwarder.cpp b/src/libYARP_OS/src/LogForwarder.cpp index abb0896918c..0ab227ef065 100644 --- a/src/libYARP_OS/src/LogForwarder.cpp +++ b/src/libYARP_OS/src/LogForwarder.cpp @@ -13,25 +13,13 @@ #include #include -yarp::os::LogForwarder* yarp::os::LogForwarder::instance = nullptr; yarp::os::Semaphore *yarp::os::LogForwarder::sem = nullptr; yarp::os::LogForwarder* yarp::os::LogForwarder::getInstance() { - if (!instance) - { - instance = new LogForwarder; - } - return instance; -}; - -void yarp::os::LogForwarder::clearInstance() -{ - if (instance) - { - delete instance; - }; -}; + static LogForwarder instance; + return &instance; +} void yarp::os::LogForwarder::forward (const std::string& message) { @@ -74,8 +62,7 @@ yarp::os::LogForwarder::LogForwarder() { printf("LogForwarder error while connecting port %s\n", logPortName); } - //yarp::os::Network::connect(logPortName, "/test"); -}; +} yarp::os::LogForwarder::~LogForwarder() { @@ -89,7 +76,6 @@ yarp::os::LogForwarder::~LogForwarder() b.addString("[INFO] Execution terminated\n"); outputPort->write(true); outputPort->waitForWrite(); - //outputPort->interrupt(); outputPort->close(); delete outputPort; outputPort=nullptr; @@ -97,5 +83,4 @@ yarp::os::LogForwarder::~LogForwarder() sem->post(); delete sem; sem = nullptr; -// yarp::os::NetworkBase::finiMinimum(); -}; +} diff --git a/src/libYARP_OS/src/Network.cpp b/src/libYARP_OS/src/Network.cpp index cfe7da18a3b..5bc701aebf3 100644 --- a/src/libYARP_OS/src/Network.cpp +++ b/src/libYARP_OS/src/Network.cpp @@ -801,7 +801,6 @@ void NetworkBase::initMinimum(yarp::os::yarpClockType clockType, yarp::os::Clock void NetworkBase::finiMinimum() { if (__yarp_is_initialized==1) { Time::useSystemClock(); - Carriers::removeInstance(); removeNameSpace(); Bottle::fini(); BottleImpl::fini(); diff --git a/src/libYARP_OS/src/RFModule.cpp b/src/libYARP_OS/src/RFModule.cpp index f1fd503e3b1..d07947810cf 100644 --- a/src/libYARP_OS/src/RFModule.cpp +++ b/src/libYARP_OS/src/RFModule.cpp @@ -145,7 +145,7 @@ class RFModuleThreadedHandler : public Thread { RFModule& owner; public: - RFModuleThreadedHandler(RFModule& owner) : owner(owner) {}; + RFModuleThreadedHandler(RFModule& owner) : owner(owner) {} void run() override { owner.runModule(); } }; diff --git a/src/libYARP_init/src/CustomInit.cpp b/src/libYARP_init/src/CustomInit.cpp index ac5e61970a5..7f782b1f2f5 100644 --- a/src/libYARP_init/src/CustomInit.cpp +++ b/src/libYARP_init/src/CustomInit.cpp @@ -38,10 +38,8 @@ extern "C" int __yarp_is_initialized; extern "C" void yarpCustomFini() { - yarp::os::LogForwarder::clearInstance(); } - yarp::os::Network::Network() { Network::init(); } diff --git a/src/libYARP_manager/include/yarp/manager/utility.h b/src/libYARP_manager/include/yarp/manager/utility.h index cb18eb9da48..ed7b769ab60 100644 --- a/src/libYARP_manager/include/yarp/manager/utility.h +++ b/src/libYARP_manager/include/yarp/manager/utility.h @@ -76,9 +76,8 @@ class ErrorLogger int warningCount(void); private: - ErrorLogger(){}; - ErrorLogger(ErrorLogger const&){}; - static ErrorLogger* pInstance; + ErrorLogger(){} + ErrorLogger(ErrorLogger const&){} std::vector errors; std::vector warnings; }; diff --git a/src/libYARP_manager/src/utility.cpp b/src/libYARP_manager/src/utility.cpp index 5751c503dbd..240eda261c2 100644 --- a/src/libYARP_manager/src/utility.cpp +++ b/src/libYARP_manager/src/utility.cpp @@ -99,14 +99,10 @@ std::ostream& operator << (std::ostream &os , StrStream& sstr) * Singleton class ErrorLogger */ -// Global static pointer used to ensure a single instance of the class. -ErrorLogger* ErrorLogger::pInstance = nullptr; - ErrorLogger* ErrorLogger::Instance() { - if (!pInstance) - pInstance = new ErrorLogger; - return pInstance; + static ErrorLogger instance; + return &instance; } void ErrorLogger::addWarning(const char* szWarning) { diff --git a/src/yarpscope/plugin/plotmanager.cpp b/src/yarpscope/plugin/plotmanager.cpp index 4da518503b2..7c00b09ab4f 100644 --- a/src/yarpscope/plugin/plotmanager.cpp +++ b/src/yarpscope/plugin/plotmanager.cpp @@ -10,12 +10,9 @@ #include "plotmanager.h" -PlotManager *PlotManager::self = nullptr; - PlotManager::PlotManager(QObject *parent) : QObject(parent) { - self = this; timer.setTimerType(Qt::PreciseTimer); connect(&timer,SIGNAL(timeout()),this,SLOT(onTimeout()),Qt::DirectConnection); } @@ -35,10 +32,8 @@ PlotManager::~PlotManager() /*! \brief Returns an instance of the class (Singleton). */ PlotManager * PlotManager::instance() { - if(self == nullptr){ - return new PlotManager(); - } - return self; + static PlotManager instance; + return &instance; } /*! \brief Returns a list of all plotters. */ diff --git a/src/yarpscope/plugin/plotmanager.h b/src/yarpscope/plugin/plotmanager.h index 560e2970cca..1f10b00baab 100644 --- a/src/yarpscope/plugin/plotmanager.h +++ b/src/yarpscope/plugin/plotmanager.h @@ -51,7 +51,6 @@ class PlotManager : public QObject private: QList plotterList; - static PlotManager *self; QTimer timer; signals: