mirror of
https://gitee.com/openharmony/filemanagement_storage_service
synced 2024-11-26 16:53:57 +00:00
回退 'Pull Request !1524 : 将超时机制改为std::thread'
This commit is contained in:
parent
28f91bbe6b
commit
9f39a63711
@ -194,30 +194,26 @@ int32_t ExternalVolumeInfo::DoMount(uint32_t mountFlags)
|
||||
return E_MOUNT;
|
||||
}
|
||||
|
||||
std::promise<int32_t> promise;
|
||||
std::future<int32_t> future = promise.get_future();
|
||||
std::thread mountThread ([this, mountFlags, p = std::move(promise)]() mutable {
|
||||
auto mountTask = [this, mountFlags]() {
|
||||
LOGI("Ready to mount: external volume fstype is %{public}s, mountflag is %{public}d",
|
||||
fsType_.c_str(), mountFlags);
|
||||
int retValue = E_MOUNT;
|
||||
if (fsType_ == "ext2" || fsType_ == "ext3" || fsType_ == "ext4") retValue = DoMount4Ext(mountFlags);
|
||||
else if (fsType_ == "hmfs" || fsType_ == "f2fs") retValue = DoMount4Hmfs(mountFlags);
|
||||
else if (fsType_ == "ntfs") retValue = DoMount4Ntfs(mountFlags);
|
||||
else if (fsType_ == "exfat") retValue = DoMount4Exfat(mountFlags);
|
||||
else if (fsType_ == "vfat" || fsType_ == "fat32") retValue = DoMount4Vfat(mountFlags);
|
||||
else retValue = DoMount4OtherType(mountFlags);
|
||||
p.set_value(retValue);
|
||||
});
|
||||
if (fsType_ == "ext2" || fsType_ == "ext3" || fsType_ == "ext4") return DoMount4Ext(mountFlags);
|
||||
if (fsType_ == "hmfs" || fsType_ == "f2fs") return DoMount4Hmfs(mountFlags);
|
||||
if (fsType_ == "ntfs") return DoMount4Ntfs(mountFlags);
|
||||
if (fsType_ == "exfat") return DoMount4Exfat(mountFlags);
|
||||
if (fsType_ == "vfat" || fsType_ == "fat32") return DoMount4Vfat(mountFlags);
|
||||
return DoMount4OtherType(mountFlags);
|
||||
};
|
||||
|
||||
std::future<int32_t> future = std::async(std::launch::async, mountTask);
|
||||
auto status = future.wait_for(std::chrono::seconds(WAIT_THREAD_TIMEOUT_S));
|
||||
if (status == std::future_status::timeout) {
|
||||
if (status == std::future_status::ready) {
|
||||
ret = future.get();
|
||||
} else {
|
||||
LOGE("Mount timed out");
|
||||
remove(mountPath_.c_str());
|
||||
mountThread.detach();
|
||||
return E_MOUNT;
|
||||
}
|
||||
ret = future.get();
|
||||
mountThread.join();
|
||||
|
||||
if (ret) {
|
||||
LOGE("External volume DoMount error, errno = %{public}d", errno);
|
||||
|
Loading…
Reference in New Issue
Block a user