diff --git a/arangod/Cluster/ClusterComm.cpp b/arangod/Cluster/ClusterComm.cpp index 8de805fd52..3966734612 100644 --- a/arangod/Cluster/ClusterComm.cpp +++ b/arangod/Cluster/ClusterComm.cpp @@ -47,8 +47,7 @@ using namespace triagens::arango; //////////////////////////////////////////////////////////////////////////////// void triagens::arango::ClusterCommRestCallback(string& coordinator, - triagens::rest::HttpResponse* response) -{ + triagens::rest::HttpResponse* response) { ClusterComm::instance()->asyncAnswer(coordinator, response); } @@ -80,22 +79,13 @@ ClusterComm::~ClusterComm () { cleanupAllQueues(); } -//////////////////////////////////////////////////////////////////////////////// -/// @brief the actual singleton instance -//////////////////////////////////////////////////////////////////////////////// - -ClusterComm* ClusterComm::_theinstance = 0; - //////////////////////////////////////////////////////////////////////////////// /// @brief getter for our singleton instance //////////////////////////////////////////////////////////////////////////////// ClusterComm* ClusterComm::instance () { - // This does not have to be thread-safe, because we guarantee that - // this is called very early in the startup phase when there is still - // a single thread. - assert(_theinstance != 0); - return _theinstance; + static ClusterComm* Instance = new ClusterComm(); + return Instance; } //////////////////////////////////////////////////////////////////////////////// @@ -103,10 +93,19 @@ ClusterComm* ClusterComm::instance () { //////////////////////////////////////////////////////////////////////////////// void ClusterComm::initialise () { - assert(_theinstance == 0); - _theinstance = new ClusterComm(); // this now happens exactly once - - _theinstance->startBackgroundThread(); + auto* i = instance(); + i->startBackgroundThread(); +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief cleanup function to call once when shutting down +//////////////////////////////////////////////////////////////////////////////// + +void ClusterComm::cleanup () { + auto i = instance(); + assert(i != nullptr); + + delete i; } //////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/Cluster/ClusterComm.h b/arangod/Cluster/ClusterComm.h index 6aba0a732f..d7ce9b587c 100644 --- a/arangod/Cluster/ClusterComm.h +++ b/arangod/Cluster/ClusterComm.h @@ -254,10 +254,7 @@ void ClusterCommRestCallback(string& coordinator, rest::HttpResponse* response); /// @brief cleanup function to call once when shutting down //////////////////////////////////////////////////////////////////////////////// - static void cleanup () { - delete _theinstance; - _theinstance = 0; - } + static void cleanup (); //////////////////////////////////////////////////////////////////////////////// /// @brief whether or not connection errors should be logged as errors diff --git a/arangod/Cluster/ClusterInfo.cpp b/arangod/Cluster/ClusterInfo.cpp index 97d88a446a..6cbe9ac18e 100644 --- a/arangod/Cluster/ClusterInfo.cpp +++ b/arangod/Cluster/ClusterInfo.cpp @@ -236,18 +236,13 @@ void CollectionInfoCurrent::copyAllJsons () { // --SECTION-- private methods // ----------------------------------------------------------------------------- -ClusterInfo* ClusterInfo::_theinstance = 0; - //////////////////////////////////////////////////////////////////////////////// /// @brief returns an instance of the cluster info class //////////////////////////////////////////////////////////////////////////////// ClusterInfo* ClusterInfo::instance () { - // This does not have to be thread-safe, because we guarantee that - // this is called very early in the startup phase when there is still - // a single thread. - assert(_theinstance != 0); - return _theinstance; + static ClusterInfo* Instance = new ClusterInfo(); + return Instance; } //////////////////////////////////////////////////////////////////////////////// @@ -255,8 +250,18 @@ ClusterInfo* ClusterInfo::instance () { //////////////////////////////////////////////////////////////////////////////// void ClusterInfo::initialise () { - assert(_theinstance == 0); - _theinstance = new ClusterInfo(); // this now happens exactly once + instance(); +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief cleanup function to call once when shutting down +//////////////////////////////////////////////////////////////////////////////// + +void ClusterInfo::cleanup () { + auto i = instance(); + assert(i != nullptr); + + delete i; } //////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/Cluster/ClusterInfo.h b/arangod/Cluster/ClusterInfo.h index a1f039b734..d962d7ddd2 100644 --- a/arangod/Cluster/ClusterInfo.h +++ b/arangod/Cluster/ClusterInfo.h @@ -751,10 +751,7 @@ namespace triagens { /// @brief cleanup function to call once when shutting down //////////////////////////////////////////////////////////////////////////////// - static void cleanup () { - delete _theinstance; - _theinstance = 0; - } + static void cleanup (); // ----------------------------------------------------------------------------- // --SECTION-- public methods diff --git a/arangod/Cluster/ServerState.cpp b/arangod/Cluster/ServerState.cpp index a14ce8149e..41799362e7 100644 --- a/arangod/Cluster/ServerState.cpp +++ b/arangod/Cluster/ServerState.cpp @@ -65,19 +65,13 @@ ServerState::~ServerState () { // --SECTION-- public static methods // ----------------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// -/// @brief the actual singleton instance -//////////////////////////////////////////////////////////////////////////////// - -ServerState* ServerState::_theinstance = 0; - //////////////////////////////////////////////////////////////////////////////// /// @brief create the (sole) instance //////////////////////////////////////////////////////////////////////////////// ServerState* ServerState::instance () { - assert(_theinstance != 0); - return _theinstance; + static ServerState* Instance = new ServerState(); + return Instance; } //////////////////////////////////////////////////////////////////////////////// @@ -85,8 +79,18 @@ ServerState* ServerState::instance () { //////////////////////////////////////////////////////////////////////////////// void ServerState::initialise () { - assert(_theinstance == 0); - _theinstance = new ServerState(); // this now happens exactly once + instance(); +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief cleanup function to call once when shutting down +//////////////////////////////////////////////////////////////////////////////// + +void ServerState::cleanup () { + auto i = instance(); + assert(i != nullptr); + + delete i; } //////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/Cluster/ServerState.h b/arangod/Cluster/ServerState.h index fcf52d1bf9..ef4c93aac7 100644 --- a/arangod/Cluster/ServerState.h +++ b/arangod/Cluster/ServerState.h @@ -117,10 +117,7 @@ namespace triagens { /// @brief cleanup function to call once when shutting down //////////////////////////////////////////////////////////////////////////////// - static void cleanup () { - delete _theinstance; - _theinstance = 0; - } + static void cleanup (); //////////////////////////////////////////////////////////////////////////////// /// @brief get the string representation of a role