Lock mapArgs/mapMultiArgs access in util
zcash: cherry picked from commit 4e048142a5e45d622355dad92ade192ad4769ca3 zcash: https://github.com/bitcoin/bitcoin/pull/9243
This commit is contained in:
parent
cafc3f845d
commit
f60964c374
16
src/util.cpp
16
src/util.cpp
|
@ -87,6 +87,7 @@ using namespace std;
|
||||||
const char * const BITCOIN_CONF_FILENAME = "zcash.conf";
|
const char * const BITCOIN_CONF_FILENAME = "zcash.conf";
|
||||||
const char * const BITCOIN_PID_FILENAME = "zcashd.pid";
|
const char * const BITCOIN_PID_FILENAME = "zcashd.pid";
|
||||||
|
|
||||||
|
CCriticalSection cs_args;
|
||||||
map<string, string> mapArgs;
|
map<string, string> mapArgs;
|
||||||
map<string, vector<string> > mapMultiArgs;
|
map<string, vector<string> > mapMultiArgs;
|
||||||
bool fDebug = false;
|
bool fDebug = false;
|
||||||
|
@ -113,6 +114,7 @@ static void InterpretNegativeSetting(std::string& strKey, std::string& strValue)
|
||||||
|
|
||||||
void ParseParameters(int argc, const char* const argv[])
|
void ParseParameters(int argc, const char* const argv[])
|
||||||
{
|
{
|
||||||
|
LOCK(cs_args);
|
||||||
mapArgs.clear();
|
mapArgs.clear();
|
||||||
mapMultiArgs.clear();
|
mapMultiArgs.clear();
|
||||||
|
|
||||||
|
@ -148,6 +150,7 @@ void ParseParameters(int argc, const char* const argv[])
|
||||||
|
|
||||||
std::string GetArg(const std::string& strArg, const std::string& strDefault)
|
std::string GetArg(const std::string& strArg, const std::string& strDefault)
|
||||||
{
|
{
|
||||||
|
LOCK(cs_args);
|
||||||
if (mapArgs.count(strArg))
|
if (mapArgs.count(strArg))
|
||||||
return mapArgs[strArg];
|
return mapArgs[strArg];
|
||||||
return strDefault;
|
return strDefault;
|
||||||
|
@ -155,6 +158,7 @@ std::string GetArg(const std::string& strArg, const std::string& strDefault)
|
||||||
|
|
||||||
int64_t GetArg(const std::string& strArg, int64_t nDefault)
|
int64_t GetArg(const std::string& strArg, int64_t nDefault)
|
||||||
{
|
{
|
||||||
|
LOCK(cs_args);
|
||||||
if (mapArgs.count(strArg))
|
if (mapArgs.count(strArg))
|
||||||
return atoi64(mapArgs[strArg]);
|
return atoi64(mapArgs[strArg]);
|
||||||
return nDefault;
|
return nDefault;
|
||||||
|
@ -162,6 +166,7 @@ int64_t GetArg(const std::string& strArg, int64_t nDefault)
|
||||||
|
|
||||||
bool GetBoolArg(const std::string& strArg, bool fDefault)
|
bool GetBoolArg(const std::string& strArg, bool fDefault)
|
||||||
{
|
{
|
||||||
|
LOCK(cs_args);
|
||||||
if (mapArgs.count(strArg))
|
if (mapArgs.count(strArg))
|
||||||
return InterpretBool(mapArgs[strArg]);
|
return InterpretBool(mapArgs[strArg]);
|
||||||
return fDefault;
|
return fDefault;
|
||||||
|
@ -169,6 +174,7 @@ bool GetBoolArg(const std::string& strArg, bool fDefault)
|
||||||
|
|
||||||
bool SoftSetArg(const std::string& strArg, const std::string& strValue)
|
bool SoftSetArg(const std::string& strArg, const std::string& strValue)
|
||||||
{
|
{
|
||||||
|
LOCK(cs_args);
|
||||||
if (mapArgs.count(strArg))
|
if (mapArgs.count(strArg))
|
||||||
return false;
|
return false;
|
||||||
mapArgs[strArg] = strValue;
|
mapArgs[strArg] = strValue;
|
||||||
|
@ -286,7 +292,7 @@ static fs::path ZC_GetDefaultBaseParamsDir()
|
||||||
|
|
||||||
const fs::path &ZC_GetParamsDir()
|
const fs::path &ZC_GetParamsDir()
|
||||||
{
|
{
|
||||||
LOCK(csPathCached); // Reuse the same lock as upstream.
|
LOCK2(cs_args, csPathCached);
|
||||||
|
|
||||||
fs::path &path = zc_paramsPathCached;
|
fs::path &path = zc_paramsPathCached;
|
||||||
|
|
||||||
|
@ -313,6 +319,7 @@ const fs::path &ZC_GetParamsDir()
|
||||||
const fs::path GetExportDir()
|
const fs::path GetExportDir()
|
||||||
{
|
{
|
||||||
fs::path path;
|
fs::path path;
|
||||||
|
LOCK(cs_args);
|
||||||
if (mapArgs.count("-exportdir")) {
|
if (mapArgs.count("-exportdir")) {
|
||||||
path = fs::system_complete(mapArgs["-exportdir"]);
|
path = fs::system_complete(mapArgs["-exportdir"]);
|
||||||
if (fs::exists(path) && !fs::is_directory(path)) {
|
if (fs::exists(path) && !fs::is_directory(path)) {
|
||||||
|
@ -328,8 +335,7 @@ const fs::path GetExportDir()
|
||||||
|
|
||||||
const fs::path &GetDataDir(bool fNetSpecific)
|
const fs::path &GetDataDir(bool fNetSpecific)
|
||||||
{
|
{
|
||||||
|
LOCK2(cs_args, csPathCached);
|
||||||
LOCK(csPathCached);
|
|
||||||
|
|
||||||
fs::path &path = fNetSpecific ? pathCachedNetSpecific : pathCached;
|
fs::path &path = fNetSpecific ? pathCachedNetSpecific : pathCached;
|
||||||
|
|
||||||
|
@ -357,6 +363,7 @@ const fs::path &GetDataDir(bool fNetSpecific)
|
||||||
|
|
||||||
void ClearDatadirCache()
|
void ClearDatadirCache()
|
||||||
{
|
{
|
||||||
|
LOCK(csPathCached);
|
||||||
pathCached = fs::path();
|
pathCached = fs::path();
|
||||||
pathCachedNetSpecific = fs::path();
|
pathCachedNetSpecific = fs::path();
|
||||||
}
|
}
|
||||||
|
@ -402,6 +409,8 @@ void ReadConfigFile(const std::string& confPath,
|
||||||
};
|
};
|
||||||
set<string> unique_options;
|
set<string> unique_options;
|
||||||
|
|
||||||
|
{
|
||||||
|
LOCK(cs_args);
|
||||||
for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it)
|
for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it)
|
||||||
{
|
{
|
||||||
string strKey = string("-") + it->string_key;
|
string strKey = string("-") + it->string_key;
|
||||||
|
@ -420,6 +429,7 @@ void ReadConfigFile(const std::string& confPath,
|
||||||
mapSettingsRet[strKey] = strValue;
|
mapSettingsRet[strKey] = strValue;
|
||||||
mapMultiSettingsRet[strKey].push_back(strValue);
|
mapMultiSettingsRet[strKey].push_back(strValue);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// If datadir is changed in .conf file:
|
// If datadir is changed in .conf file:
|
||||||
ClearDatadirCache();
|
ClearDatadirCache();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue