1
0
Fork 0

fixed startup race conditions

This commit is contained in:
Jan Steemann 2014-06-04 15:18:20 +02:00
parent a43d5c3f7d
commit f7049b8922
6 changed files with 47 additions and 48 deletions

View File

@ -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;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -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

View File

@ -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;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -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

View File

@ -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;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -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