Description:add lock

Match-id-cf7f91e9d8a9de01b83053f8913791e262ba8584
This commit is contained in:
xxxx
2022-07-01 11:31:21 +08:00
parent f0d00f0566
commit c836c8f730
4 changed files with 17 additions and 5 deletions
+1
View File
@@ -76,6 +76,7 @@ private:
// the unordered_map's key is remoteDevId.
std::unordered_map<std::string, SessionInfo> sessionInfos_;
std::mutex sessionMutex_;
std::mutex operationMutex_;
};
}
}
+11 -5
View File
@@ -62,12 +62,18 @@ int32_t HiDumper::ProcessDump(const std::string& args, std::string& result)
DHLOGI("ProcessDump Dump.");
int32_t ret = ERR_DH_INPUT_HIDUMP_INVALID_ARGS;
result.clear();
auto operatorIter = ARGS_MAP.find(args);
if (operatorIter == ARGS_MAP.end()) {
result.append("unknown command");
DHLOGI("ProcessDump");
return ret;
std::map<std::string, HiDumperFlag>::const_iterator operatorIter;
{
std::lock_guard<std::mutex> lock(operationMutex_);
operatorIter = ARGS_MAP.find(args);
if (operatorIter == ARGS_MAP.end()) {
result.append("unknown command");
DHLOGI("ProcessDump");
return ret;
}
}
HiDumperFlag hidumperFlag = operatorIter->second;
switch (hidumperFlag) {
case HiDumperFlag::GET_HELP: {
@@ -142,6 +142,7 @@ private:
std::vector<DHardWareFwkRegistInfo> dHardWareFwkRstInfos;
std::vector<DHardWareFwkUnRegistInfo> dHardWareFwkUnRstInfos;
std::mutex operationMutex_;
};
} // namespace DistributedInput
} // namespace DistributedHardware
@@ -44,6 +44,7 @@ DistributedInputClient &DistributedInputClient::GetInstance()
void DistributedInputClient::RegisterDInputCb::OnResult(
const std::string& devId, const std::string& dhId, const int32_t& status)
{
std::lock_guard<std::mutex> lock(DistributedInputClient::GetInstance().operationMutex_);
for (std::vector<DHardWareFwkRegistInfo>::iterator iter =
DistributedInputClient::GetInstance().dHardWareFwkRstInfos.begin();
iter != DistributedInputClient::GetInstance().dHardWareFwkRstInfos.end();
@@ -59,6 +60,7 @@ void DistributedInputClient::RegisterDInputCb::OnResult(
void DistributedInputClient::UnregisterDInputCb::OnResult(
const std::string& devId, const std::string& dhId, const int32_t& status)
{
std::lock_guard<std::mutex> lock(DistributedInputClient::GetInstance().operationMutex_);
for (std::vector<DHardWareFwkUnRegistInfo>::iterator iter =
DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.begin();
iter != DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.end();
@@ -160,6 +162,7 @@ int32_t DistributedInputClient::RegisterDistributedHardware(const std::string& d
return ERR_DH_INPUT_CLIENT_REGISTER_FAIL;
}
std::lock_guard<std::mutex> lock(DistributedInputClient::GetInstance().operationMutex_);
for (auto iter : dHardWareFwkRstInfos) {
if (iter.devId == devId && iter.dhId == dhId) {
return ERR_DH_INPUT_CLIENT_REGISTER_FAIL;
@@ -192,6 +195,7 @@ int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string&
return ERR_DH_INPUT_CLIENT_UNREGISTER_FAIL;
}
std::lock_guard<std::mutex> lock(DistributedInputClient::GetInstance().operationMutex_);
for (auto iter : dHardWareFwkUnRstInfos) {
if (iter.devId == devId && iter.dhId == dhId) {
return ERR_DH_INPUT_CLIENT_UNREGISTER_FAIL;