@@ -17,9 +17,6 @@ using namespace std::chrono;
17
17
18
18
namespace configcat {
19
19
20
- std::mutex ConfigCatClient::instancesMutex;
21
- std::unordered_map<std::string, std::shared_ptr<ConfigCatClient>> ConfigCatClient::instances;
22
-
23
20
bool isValidSdkKey (const string& sdkKey, bool customBaseUrl) {
24
21
static constexpr char proxyPrefix[] = " configcat-proxy/" ;
25
22
@@ -53,7 +50,8 @@ std::shared_ptr<ConfigCatClient> ConfigCatClient::get(const std::string& sdkKey,
53
50
}
54
51
}
55
52
56
- lock_guard<mutex> lock (instancesMutex);
53
+ lock_guard<mutex> lock (getInstancesMutex ());
54
+ auto & instances = getInstances ();
57
55
auto client = instances.find (sdkKey);
58
56
if (client == instances.end ()) {
59
57
client = instances.insert ({sdkKey, make_shared<ConfigCatClient::MakeSharedEnabler>(sdkKey, actualOptions)}).first ;
@@ -72,7 +70,8 @@ void ConfigCatClient::close(const std::shared_ptr<ConfigCatClient>& client) {
72
70
}
73
71
74
72
{
75
- lock_guard<mutex> lock (instancesMutex);
73
+ lock_guard<mutex> lock (getInstancesMutex ());
74
+ auto & instances = getInstances ();
76
75
77
76
client->closeResources ();
78
77
@@ -89,7 +88,8 @@ void ConfigCatClient::close(const std::shared_ptr<ConfigCatClient>& client) {
89
88
}
90
89
91
90
void ConfigCatClient::closeAll () {
92
- lock_guard<mutex> lock (instancesMutex);
91
+ lock_guard<mutex> lock (getInstancesMutex ());
92
+ auto & instances = getInstances ();
93
93
94
94
for (const auto & [_, instance] : instances) {
95
95
instance->closeResources ();
@@ -99,7 +99,8 @@ void ConfigCatClient::closeAll() {
99
99
}
100
100
101
101
size_t ConfigCatClient::instanceCount () {
102
- lock_guard<mutex> lock (instancesMutex);
102
+ lock_guard<mutex> lock (getInstancesMutex ());
103
+ auto & instances = getInstances ();
103
104
104
105
return instances.size ();
105
106
}
0 commit comments