Skip to content
Snippets Groups Projects
Commit fbbef962 authored by Joscha Schmiedt's avatar Joscha Schmiedt
Browse files

Move static singletons to namespace level

The singleton instances of ConfigurationManager and ConnectionManager
were stored as static variables in the static GetInstance methods.

This causes weird errors on Windows where the singleton instance is not
initialized in time and remains empty. This could be due to
undefined behavior?

Moving them to the namespace level fixes the unit test errors.
parent 0e743b98
No related branches found
No related tags found
2 merge requests!61Release 0.3.0,!56Resolve "Unit tests unter Windows"
Pipeline #55181 canceled
......@@ -103,10 +103,8 @@ public:
*/
class ConfigurationManager {
public:
static ConfigurationManager &GetInstance() {
static ConfigurationManager instance;
return instance;
};
static ConfigurationManager &GetInstance();
;
/**
* See mReset.
......@@ -156,6 +154,7 @@ public:
private:
Arena arena;
JsonValue json_configuration;
static ConfigurationManager mInstance;
inline ConfigurationManager()
: json_configuration(nullptr){
......
......@@ -170,6 +170,9 @@ class ConnectionManager {
private:
mutable std::map<std::string, std::shared_ptr<Connection>> connections;
mutable std::string default_connection_name;
static ConnectionManager instance;
inline ConnectionManager(){};
auto mHasConnection(const std::string &name) const -> bool;
......@@ -184,10 +187,7 @@ private:
}
public:
static ConnectionManager &GetInstance() {
static ConnectionManager instance;
return instance;
};
static ConnectionManager &GetInstance();
inline static auto HasConnection(const std::string &name) -> bool {
return ConnectionManager::GetInstance().mHasConnection(name);
......
......@@ -70,6 +70,9 @@
}
namespace linkahead::configuration {
ConfigurationManager ConfigurationManager::mInstance;
using boost::json::object;
using boost::json::value;
using grpc::InsecureChannelCredentials;
......@@ -424,6 +427,8 @@ auto ConfigurationManager::mGetDefaultConnectionName() const -> std::string {
throw ConfigurationError("Could not determine the default connection.");
}
inline ConfigurationManager &ConfigurationManager::GetInstance() { return mInstance; }
// TODO(tf) This has apparently a cognitive complexity of 34>25 (threshold).
auto ConfigurationManager::InitializeDefaults() -> int { // NOLINT
......
......@@ -66,6 +66,13 @@ using linkahead::info::VersionInfo;
using linkahead::transaction::Transaction;
using linkahead::transaction::TransactionStatus;
ConnectionManager ConnectionManager::instance;
ConnectionManager &ConnectionManager::GetInstance() {
return instance;
}
Connection::Connection(const ConnectionConfiguration &configuration) {
const std::string target =
configuration.GetHost() + ":" + std::to_string(configuration.GetPort());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment