MT#59962 DSMChartReader: cover mods with std::lock

Use a manual lock to make read/write operations
to the `std::map<DSMModule*, void*> mods_hdls` safer.

Change-Id: I45fb46bab603e2817bd98cd99267ed813122e548
mr13.3.1
Donat Zenichev 10 months ago
parent 13a8a50d52
commit 65b3eed61c

@ -877,6 +877,7 @@ int DSMFactory::preloadModules(AmConfigReader& cfg, string& res, const string& M
return -1;
}
preload_reader.mods_mutex.lock();
DSMModule* last_loaded = NULL;
modLinkHdl modHdl = preload_reader.mods.back();
@ -885,8 +886,10 @@ int DSMFactory::preloadModules(AmConfigReader& cfg, string& res, const string& M
else
{
res = "Error while preloading '"+*it+"'\n";
preload_reader.mods_mutex.unlock();
return -1;
}
preload_reader.mods_mutex.unlock();
if (last_loaded) {
if (last_loaded->preload()) {
@ -931,6 +934,7 @@ void DSMFactory::preloadModule(const AmArg& args, AmArg& ret) {
return;
}
preload_reader.mods_mutex.lock();
DSMModule* last_loaded = NULL;
modLinkHdl modHdl = preload_reader.mods.back();
@ -940,8 +944,10 @@ void DSMFactory::preloadModule(const AmArg& args, AmArg& ret) {
{
ret.push(500);
ret.push("Error while preloading '"+mod_name+"'");
preload_reader.mods_mutex.unlock();
return;
}
preload_reader.mods_mutex.unlock();
if (last_loaded) {
if (last_loaded->preload()) {

@ -120,6 +120,7 @@ string DSMChartReader::getToken(string str, size_t& pos) {
DSMAction* DSMChartReader::actionFromToken(const string& str) {
mods_mutex.lock();
for (v_modsHdls::iterator it=mods.begin(); it!= mods.end(); it++)
{
DSMModule* mod = (*it).mod;
@ -127,9 +128,12 @@ DSMAction* DSMChartReader::actionFromToken(const string& str) {
continue;
DSMAction* a = mod->getAction(str);
if (a)
if (a) {
mods_mutex.unlock();
return a;
}
}
mods_mutex.unlock();
DSMAction* a = core_mod.getAction(str);
if (a) return a;
@ -208,6 +212,7 @@ bool DSMChartReader::forFromToken(DSMArrayFor& af, const string& token) {
DSMCondition* DSMChartReader::conditionFromToken(const string& str, bool invert) {
mods_mutex.lock();
for (v_modsHdls::iterator it=mods.begin(); it!= mods.end(); it++)
{
DSMModule* mod = (*it).mod;
@ -217,9 +222,11 @@ DSMCondition* DSMChartReader::conditionFromToken(const string& str, bool invert)
DSMCondition* c = mod->getCondition(str);
if (c) {
c->invert = invert;
mods_mutex.unlock();
return c;
}
}
mods_mutex.unlock();
DSMCondition* c = core_mod.getCondition(str);
if (c)
@ -264,8 +271,10 @@ bool DSMChartReader::importModule(const string& mod_cmd, const string& mod_path)
return false;
}
mods_mutex.lock();
modLinkHdl mod_hdl = {mod, h_dl};
mods.push_back(mod_hdl);
mods_mutex.unlock();
DBG("loaded module '%s' from '%s'\n",
params.c_str(), fname.c_str());
@ -749,12 +758,14 @@ bool DSMChartReader::decode(DSMStateDiagram* e, const string& chart,
}
mods_mutex.lock();
for (v_modsHdls::iterator it=mods.begin(); it!= mods.end(); it++)
{
DSMModule* mod = (*it).mod;
if (mod)
out_mods.push_back(mod);
}
mods_mutex.unlock();
return true;
}
@ -762,6 +773,7 @@ bool DSMChartReader::decode(DSMStateDiagram* e, const string& chart,
void DSMChartReader::cleanup() {
mods_mutex.lock();
for (v_modsHdls::iterator it=mods.begin(); it!= mods.end(); it++)
{
DSMModule* mod = (*it).mod;
@ -773,6 +785,7 @@ void DSMChartReader::cleanup() {
if (h_dl)
dlclose(h_dl);
}
mods_mutex.unlock();
mods.clear();
}

@ -103,6 +103,7 @@ class DSMChartReader {
bool importModule(const string& mod_cmd, const string& mod_path);
AmMutex mods_mutex;
v_modsHdls mods;
DSMCoreModule core_mod;

Loading…
Cancel
Save