Description:add lock

Match-id-5409e3dbc2daefd72b58630d7dff399034a18978
This commit is contained in:
xxxx
2022-07-02 16:20:26 +08:00
parent ab62c6d642
commit 5260162c53
4 changed files with 41 additions and 31 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: {
@@ -121,8 +121,6 @@ private:
DInputServerType serverType = DInputServerType::NULL_SERVER_TYPE;
DInputDeviceType inputTypes_ = DInputDeviceType::NONE;
sptr<RegisterDInputCb> callbackRegister = nullptr;
sptr<UnregisterDInputCb> callbackUnregister = nullptr;
sptr<StartDInputServerCb> sinkTypeCallback = nullptr;
sptr<StartDInputServerCb> sourceTypeCallback = nullptr;
sptr<AddWhiteListInfosCb> addWhiteListCallback = nullptr;
@@ -142,6 +140,7 @@ private:
std::vector<DHardWareFwkRegistInfo> dHardWareFwkRstInfos;
std::vector<DHardWareFwkUnRegistInfo> dHardWareFwkUnRstInfos;
std::mutex operationMutex_;
};
} // namespace DistributedInput
} // namespace DistributedHardware
+28 -24
View File
@@ -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();
@@ -122,8 +124,6 @@ int32_t DistributedInputClient::ReleaseSource()
serverType = DInputServerType::NULL_SERVER_TYPE;
inputTypes_ = DInputDeviceType::NONE;
m_bIsAlreadyInitWhiteList = false;
callbackRegister = nullptr;
callbackUnregister = nullptr;
sinkTypeCallback = nullptr;
sourceTypeCallback = nullptr;
addWhiteListCallback = nullptr;
@@ -160,21 +160,23 @@ int32_t DistributedInputClient::RegisterDistributedHardware(const std::string& d
return ERR_DH_INPUT_CLIENT_REGISTER_FAIL;
}
for (auto iter : dHardWareFwkRstInfos) {
if (iter.devId == devId && iter.dhId == dhId) {
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;
}
}
DHardWareFwkRegistInfo info;
info.devId = devId;
info.dhId = dhId;
info.callback = callback;
dHardWareFwkRstInfos.push_back(info);
}
DHardWareFwkRegistInfo info;
info.devId = devId;
info.dhId = dhId;
info.callback = callback;
dHardWareFwkRstInfos.push_back(info);
callbackRegister = new(std::nothrow) RegisterDInputCb();
return DinputSAManager::GetInstance().dInputSourceProxy_->RegisterDistributedHardware(devId, dhId, parameters,
callbackRegister);
new(std::nothrow) RegisterDInputCb());
}
int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string& devId, const std::string& dhId,
@@ -192,21 +194,23 @@ int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string&
return ERR_DH_INPUT_CLIENT_UNREGISTER_FAIL;
}
for (auto iter : dHardWareFwkUnRstInfos) {
if (iter.devId == devId && iter.dhId == dhId) {
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;
}
}
DHardWareFwkUnRegistInfo info;
info.devId = devId;
info.dhId = dhId;
info.callback = callback;
dHardWareFwkUnRstInfos.push_back(info);
}
DHardWareFwkUnRegistInfo info;
info.devId = devId;
info.dhId = dhId;
info.callback = callback;
dHardWareFwkUnRstInfos.push_back(info);
callbackUnregister = new(std::nothrow) UnregisterDInputCb();
return DinputSAManager::GetInstance().dInputSourceProxy_->UnregisterDistributedHardware(devId, dhId,
callbackUnregister);
new(std::nothrow) UnregisterDInputCb());
}
int32_t DistributedInputClient::PrepareRemoteInput(