!765 删除无用锁,修改napi回调方法

Merge pull request !765 from BrainL/afs0323
This commit is contained in:
openharmony_ci 2024-04-02 02:02:45 +00:00 committed by Gitee
commit 0241eb5110
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 2 additions and 17 deletions

View File

@ -153,8 +153,6 @@ private:
std::shared_mutex lock_; std::shared_mutex lock_;
std::shared_ptr<ExtBackup> extension_; std::shared_ptr<ExtBackup> extension_;
std::vector<std::string> tars_; std::vector<std::string> tars_;
std::mutex getExtInfoMtx_;
std::condition_variable getExtInfoCondition_;
std::string backupInfo_; std::string backupInfo_;
OHOS::ThreadPool threadPool_; OHOS::ThreadPool threadPool_;
}; };

View File

@ -69,7 +69,6 @@ using namespace std;
namespace { namespace {
const int64_t DEFAULT_SLICE_SIZE = 100 * 1024 * 1024; // 分片文件大小为100M const int64_t DEFAULT_SLICE_SIZE = 100 * 1024 * 1024; // 分片文件大小为100M
const uint32_t MAX_FILE_COUNT = 6000; // 单个tar包最多包含6000个文件 const uint32_t MAX_FILE_COUNT = 6000; // 单个tar包最多包含6000个文件
const int32_t CONNECT_WAIT_TIME_S = 15;
} // namespace } // namespace
void BackupExtExtension::VerifyCaller() void BackupExtExtension::VerifyCaller()
@ -1618,18 +1617,13 @@ ErrCode BackupExtExtension::GetBackupInfo(std::string &result)
auto callBackup = [ptr](std::string result) { auto callBackup = [ptr](std::string result) {
HILOGI("GetBackupInfo callBackup start. result = %{public}s", result.c_str()); HILOGI("GetBackupInfo callBackup start. result = %{public}s", result.c_str());
ptr->backupInfo_ = result; ptr->backupInfo_ = result;
ptr->getExtInfoCondition_.notify_one();
}; };
auto ret = ptr->extension_->GetBackupInfo(callBackup); auto ret = ptr->extension_->GetBackupInfo(callBackup);
if (ret != ERR_OK) { if (ret != ERR_OK) {
HILOGE("Failed to notify the app done. err = %{public}d", ret); HILOGE("Failed to notify the app done. err = %{public}d", ret);
return BError(BError::Codes::EXT_INVAL_ARG, "extension getBackupInfo exception").GetCode(); return BError(BError::Codes::EXT_INVAL_ARG, "extension getBackupInfo exception").GetCode();
} }
HILOGD("GetBackupInfo getExtInfoMtx_ lock."); HILOGD("GetBackupInfo lby, backupInfo = %s", backupInfo_.c_str());
std::unique_lock<std::mutex> lock(getExtInfoMtx_);
getExtInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME_S));
HILOGD("GetBackupInfo getExtInfoMtx_ unlock.");
result = backupInfo_; result = backupInfo_;
backupInfo_.clear(); backupInfo_.clear();

View File

@ -265,14 +265,7 @@ static void onResultReport(weak_ptr<GeneralCallbacks> pCallbacks, const std::str
} }
auto cbCompl = [result {result}](napi_env env, NError err) -> NVal { auto cbCompl = [result {result}](napi_env env, NError err) -> NVal {
NVal resultStr = NVal::CreateUTF8String(env, result); return NVal::CreateUTF8String(env, result);
NVal res;
napi_status status = napi_set_named_property(env, res.val_, FILEIO_TAG_ERR_DATA.c_str(), resultStr.val_);
if (status != napi_ok) {
HILOGE("Failed to set data property, status %{public}d, bundleName %{public}s", status, result.c_str());
}
return res;
}; };
callbacks->onResultReport.ThreadSafeSchedule(cbCompl); callbacks->onResultReport.ThreadSafeSchedule(cbCompl);