From 9f39a637117859ffe4a5d2601fde63c5123b28de Mon Sep 17 00:00:00 2001 From: oh_ci Date: Wed, 20 Nov 2024 02:44:34 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!1524=20?= =?UTF-8?q?:=20=20=E5=B0=86=E8=B6=85=E6=97=B6=E6=9C=BA=E5=88=B6=E6=94=B9?= =?UTF-8?q?=E4=B8=BAstd::thread'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../volume/src/external_volume_info.cpp | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/services/storage_daemon/volume/src/external_volume_info.cpp b/services/storage_daemon/volume/src/external_volume_info.cpp index c8af84b8..8ceadb18 100644 --- a/services/storage_daemon/volume/src/external_volume_info.cpp +++ b/services/storage_daemon/volume/src/external_volume_info.cpp @@ -194,30 +194,26 @@ int32_t ExternalVolumeInfo::DoMount(uint32_t mountFlags) return E_MOUNT; } - std::promise promise; - std::future 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 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); -- Gitee