!694 fix map mutex

Merge pull request !694 from 张文迪/gid
This commit is contained in:
openharmony_ci 2023-12-04 06:49:58 +00:00 committed by Gitee
commit 005aa98640
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 13 additions and 9 deletions

View File

@ -28,6 +28,10 @@ public:
StorageRlMap() {}
~StorageRlMap() {}
V& operator[](const K& key)
{
return map_[key];
}
V ReadVal(const K& key)
{
Utils::UniqueWriteGuard<Utils::RWLock> mapGuard(this->rl_);
return map_[key];

View File

@ -29,7 +29,7 @@ std::shared_ptr<Disk> DiskManagerService::GetDiskById(std::string diskId)
if (!diskMap_.Contains(diskId)) {
return nullptr;
}
return diskMap_[diskId];
return diskMap_.ReadVal(diskId);
}
void DiskManagerService::OnDiskCreated(Disk disk)
@ -76,7 +76,7 @@ std::vector<Disk> DiskManagerService::GetAllDisks()
int32_t DiskManagerService::GetDiskById(std::string diskId, Disk &disk)
{
if (diskMap_.Contains(diskId)) {
disk = *diskMap_[diskId];
disk = *diskMap_.ReadVal(diskId);
return E_OK;
}
return E_NON_EXIST;

View File

@ -48,7 +48,7 @@ namespace StorageManager {
LOGE("VolumeManagerService::OnVolumeDestroyed volumeId %{public}s not exists", volumeId.c_str());
return;
}
std::shared_ptr<VolumeExternal> volumePtr = volumeMap_[volumeId];
std::shared_ptr<VolumeExternal> volumePtr = volumeMap_.ReadVal(volumeId);
VolumeStateNotify(state, volumePtr);
if (state == VolumeState::REMOVED || state == VolumeState::BAD_REMOVAL) {
volumeMap_.Erase(volumeId);
@ -62,7 +62,7 @@ namespace StorageManager {
LOGE("VolumeManagerService::OnVolumeMounted volumeId %{public}s not exists", volumeId.c_str());
return;
}
std::shared_ptr<VolumeExternal> volumePtr = volumeMap_[volumeId];
std::shared_ptr<VolumeExternal> volumePtr = volumeMap_.ReadVal(volumeId);
volumePtr->SetFsType(fsType);
volumePtr->SetFsUuid(fsUuid);
volumePtr->SetPath(path);
@ -90,7 +90,7 @@ namespace StorageManager {
LOGE("VolumeManagerService::Mount volumeId %{public}s not exists", volumeId.c_str());
return E_NON_EXIST;
}
std::shared_ptr<VolumeExternal> volumePtr = volumeMap_[volumeId];
std::shared_ptr<VolumeExternal> volumePtr = volumeMap_.ReadVal(volumeId);
if (volumePtr->GetState() != VolumeState::UNMOUNTED) {
LOGE("VolumeManagerService::The type of volume(Id %{public}s) is not unmounted", volumeId.c_str());
return E_MOUNT;
@ -115,7 +115,7 @@ namespace StorageManager {
LOGE("VolumeManagerService::Unmount volumeId %{public}s not exists", volumeId.c_str());
return E_NON_EXIST;
}
std::shared_ptr<VolumeExternal> volumePtr = volumeMap_[volumeId];
std::shared_ptr<VolumeExternal> volumePtr = volumeMap_.ReadVal(volumeId);
if (volumePtr->GetState() != VolumeState::MOUNTED) {
LOGE("VolumeManagerService::The type of volume(Id %{public}s) is not mounted", volumeId.c_str());
return E_UMOUNT;
@ -135,7 +135,7 @@ namespace StorageManager {
int32_t VolumeManagerService::Check(std::string volumeId)
{
std::shared_ptr<VolumeExternal> volumePtr = volumeMap_[volumeId];
std::shared_ptr<VolumeExternal> volumePtr = volumeMap_.ReadVal(volumeId);
std::shared_ptr<StorageDaemonCommunication> sdCommunication;
sdCommunication = DelayedSingleton<StorageDaemonCommunication>::GetInstance();
volumePtr->SetState(VolumeState::CHECKING);
@ -181,7 +181,7 @@ namespace StorageManager {
int32_t VolumeManagerService::GetVolumeById(std::string volumeId, VolumeExternal &vc)
{
if (volumeMap_.Contains(volumeId)) {
vc = *volumeMap_[volumeId];
vc = *volumeMap_.ReadVal(volumeId);
return E_OK;
}
return E_NON_EXIST;
@ -210,7 +210,7 @@ namespace StorageManager {
if (volumeMap_.Find(volumeId) == volumeMap_.End()) {
return E_NON_EXIST;
}
if (volumeMap_[volumeId]->GetState() != VolumeState::UNMOUNTED) {
if (volumeMap_.ReadVal(volumeId)->GetState() != VolumeState::UNMOUNTED) {
LOGE("VolumeManagerService::SetVolumeDescription volume state is not unmounted!");
return E_VOL_STATE;
}