Skip to content

Commit 505b69b

Browse files
committed
Check mutex lock *only* when actually signal was received. Otherwise allow reading config settings in multiple threads at once.
1 parent 66d04e7 commit 505b69b

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/Config.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,19 @@ Config::~Config() {
8787
delete(logger);
8888
}
8989

90-
91-
int Config::get_int_setting(std::string setting_name) {
92-
confMutex.lock();
93-
if(isSigusr1Received){
90+
void Config::reload_on_usr1() {
91+
while (isSigusr1Received) {
92+
confMutex.lock();
93+
if (!isSigusr1Received) break;
9494
Config::loadConfigFileToMap();
9595
Config::printMapContents();
9696
isSigusr1Received = false;
97+
confMutex.unlock();
9798
}
99+
}
100+
101+
int Config::get_int_setting(std::string setting_name) {
102+
reload_on_usr1();
98103
int returnInt = -1;
99104
try {
100105
returnInt = std::stoi(configMap.at(setting_name));
@@ -103,25 +108,17 @@ int Config::get_int_setting(std::string setting_name) {
103108
} catch (invalid_argument){
104109
throw ConfigException("Error parsing config to int, check config file syntax at " + setting_name);
105110
}
106-
confMutex.unlock();
107111
return returnInt;
108112
}
109113

110114

111115
std::string Config::get_str_setting(std::string setting_name) {
112-
confMutex.lock();
113-
if(isSigusr1Received){
114-
Config::loadConfigFileToMap();
115-
Config::printMapContents();
116-
isSigusr1Received = false;
117-
}
116+
reload_on_usr1();
118117
std::string returnString;
119-
120118
try{
121119
returnString = configMap.at(setting_name);
122120
} catch (out_of_range) {
123121
throw ConfigException("Unknown string option passed: " + setting_name);
124122
}
125-
confMutex.unlock();
126123
return returnString;
127124
}

src/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Config {
1616
std::string key;
1717
size_t position;
1818
void loadConfigFileToMap();
19+
void reload_on_usr1();
1920
void printMapContents();
2021
Config();
2122
static Config* configSingleton;

0 commit comments

Comments
 (0)