From b2fcb192a83a11e8fb87de220c34463b7c82e490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Santos?= Date: Tue, 24 Apr 2018 15:41:33 +0100 Subject: [PATCH] Replaced DCL pattern with static variable. Fixes #1364 (#1365) --- clients/roscpp/src/libros/connection_manager.cpp | 14 ++------------ clients/roscpp/src/libros/poll_manager.cpp | 14 ++------------ clients/roscpp/src/libros/xmlrpc_manager.cpp | 14 ++------------ 3 files changed, 6 insertions(+), 36 deletions(-) diff --git a/clients/roscpp/src/libros/connection_manager.cpp b/clients/roscpp/src/libros/connection_manager.cpp index 98789b66ae..19fdb90cce 100644 --- a/clients/roscpp/src/libros/connection_manager.cpp +++ b/clients/roscpp/src/libros/connection_manager.cpp @@ -40,20 +40,10 @@ namespace ros { -ConnectionManagerPtr g_connection_manager; -boost::mutex g_connection_manager_mutex; const ConnectionManagerPtr& ConnectionManager::instance() { - if (!g_connection_manager) - { - boost::mutex::scoped_lock lock(g_connection_manager_mutex); - if (!g_connection_manager) - { - g_connection_manager = boost::make_shared(); - } - } - - return g_connection_manager; + static ConnectionManagerPtr connection_manager = boost::make_shared(); + return connection_manager; } ConnectionManager::ConnectionManager() diff --git a/clients/roscpp/src/libros/poll_manager.cpp b/clients/roscpp/src/libros/poll_manager.cpp index 569b9c53c7..4910d24c50 100644 --- a/clients/roscpp/src/libros/poll_manager.cpp +++ b/clients/roscpp/src/libros/poll_manager.cpp @@ -33,20 +33,10 @@ namespace ros { -PollManagerPtr g_poll_manager; -boost::mutex g_poll_manager_mutex; const PollManagerPtr& PollManager::instance() { - if (!g_poll_manager) - { - boost::mutex::scoped_lock lock(g_poll_manager_mutex); - if (!g_poll_manager) - { - g_poll_manager.reset(new PollManager); - } - } - - return g_poll_manager; + static PollManagerPtr poll_manager = boost::make_shared(); + return poll_manager; } PollManager::PollManager() diff --git a/clients/roscpp/src/libros/xmlrpc_manager.cpp b/clients/roscpp/src/libros/xmlrpc_manager.cpp index 1aee46b1a5..15175ff5e7 100644 --- a/clients/roscpp/src/libros/xmlrpc_manager.cpp +++ b/clients/roscpp/src/libros/xmlrpc_manager.cpp @@ -95,20 +95,10 @@ void getPid(const XmlRpcValue& params, XmlRpcValue& result) const ros::WallDuration CachedXmlRpcClient::s_zombie_time_(30.0); // reap after 30 seconds -XMLRPCManagerPtr g_xmlrpc_manager; -boost::mutex g_xmlrpc_manager_mutex; const XMLRPCManagerPtr& XMLRPCManager::instance() { - if (!g_xmlrpc_manager) - { - boost::mutex::scoped_lock lock(g_xmlrpc_manager_mutex); - if (!g_xmlrpc_manager) - { - g_xmlrpc_manager.reset(new XMLRPCManager); - } - } - - return g_xmlrpc_manager; + static XMLRPCManagerPtr xmlrpc_manager = boost::make_shared(); + return xmlrpc_manager; } XMLRPCManager::XMLRPCManager()