mirror of
https://gitee.com/openharmony/filemanagement_storage_service
synced 2024-11-23 06:59:59 +00:00
将超时机制改为std::thread
Signed-off-by: s30051537 <sunxiaoqiang7@huawei.com>
This commit is contained in:
parent
b33d1b2dc8
commit
22c3f12d66
@ -194,26 +194,30 @@ int32_t ExternalVolumeInfo::DoMount(uint32_t mountFlags)
|
||||
return E_MOUNT;
|
||||
}
|
||||
|
||||
auto mountTask = [this, mountFlags]() {
|
||||
std::promise<int32_t> promise;
|
||||
std::future<int32_t> future = promise.get_future();
|
||||
std::thread mountThread ([this, mountFlags, p = std::move(promise)]() mutable {
|
||||
LOGI("Ready to mount: external volume fstype is %{public}s, mountflag is %{public}d",
|
||||
fsType_.c_str(), mountFlags);
|
||||
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);
|
||||
};
|
||||
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);
|
||||
});
|
||||
|
||||
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::ready) {
|
||||
ret = future.get();
|
||||
} else {
|
||||
if (status == std::future_status::timeout) {
|
||||
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