From 5db0721499096616ebbab790a62d185de3e15161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Thu, 12 Sep 2024 10:50:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- ext/pin_auth/BUILD.gn | 1 + .../authenticatedeviceservice_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 1 + .../dmauthmanager_fuzzer/BUILD.gn | 1 + .../dmdiscoverymanager_fuzzer/BUILD.gn | 1 + .../hichainconnector_fuzzer/BUILD.gn | 1 + .../ondatareceived_fuzzer/BUILD.gn | 1 + test/commonfuzztest/onfinish_fuzzer/BUILD.gn | 1 + test/commonfuzztest/onrequest_fuzzer/BUILD.gn | 1 + .../devicemanagerservice_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 1 + .../shiftlnngeardeviceservice_fuzzer/BUILD.gn | 1 + utils/BUILD.gn | 1 - utils/include/timer/dm_timer.h | 9 ++-- utils/src/timer/dm_timer.cpp | 43 +++++++++---------- 15 files changed, 35 insertions(+), 30 deletions(-) diff --git a/ext/pin_auth/BUILD.gn b/ext/pin_auth/BUILD.gn index 740e11e1b..f82d51102 100644 --- a/ext/pin_auth/BUILD.gn +++ b/ext/pin_auth/BUILD.gn @@ -79,6 +79,7 @@ ohos_shared_library("devicemanagerext_pin_auth") { "device_info_manager:distributed_device_profile_sdk", "dsoftbus:softbus_client", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbegetutil", "ipc:ipc_single", diff --git a/test/commonfuzztest/authenticatedeviceservice_fuzzer/BUILD.gn b/test/commonfuzztest/authenticatedeviceservice_fuzzer/BUILD.gn index ffa5905f4..249999789 100644 --- a/test/commonfuzztest/authenticatedeviceservice_fuzzer/BUILD.gn +++ b/test/commonfuzztest/authenticatedeviceservice_fuzzer/BUILD.gn @@ -74,6 +74,7 @@ ohos_fuzztest("AuthenticateDeviceServiceFuzzTest") { "device_auth:deviceauth_sdk", "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", + "ffrt:libffrt", "ipc:ipc_single", "safwk:system_ability_fwk", ] diff --git a/test/commonfuzztest/authenticatedeviceserviceimpl_fuzzer/BUILD.gn b/test/commonfuzztest/authenticatedeviceserviceimpl_fuzzer/BUILD.gn index a0e8afe72..1d73370a7 100644 --- a/test/commonfuzztest/authenticatedeviceserviceimpl_fuzzer/BUILD.gn +++ b/test/commonfuzztest/authenticatedeviceserviceimpl_fuzzer/BUILD.gn @@ -75,6 +75,7 @@ ohos_fuzztest("AuthenticateDeviceServiceImplFuzzTest") { "device_auth:deviceauth_sdk", "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", + "ffrt:libffrt", "ipc:ipc_single", "safwk:system_ability_fwk", ] diff --git a/test/commonfuzztest/dmauthmanager_fuzzer/BUILD.gn b/test/commonfuzztest/dmauthmanager_fuzzer/BUILD.gn index 17166fbd3..211997de6 100644 --- a/test/commonfuzztest/dmauthmanager_fuzzer/BUILD.gn +++ b/test/commonfuzztest/dmauthmanager_fuzzer/BUILD.gn @@ -53,6 +53,7 @@ ohos_fuzztest("DmAuthManagerFuzzTest") { "device_auth:deviceauth_sdk", "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", + "ffrt:libffrt", "ipc:ipc_single", "safwk:system_ability_fwk", ] diff --git a/test/commonfuzztest/dmdiscoverymanager_fuzzer/BUILD.gn b/test/commonfuzztest/dmdiscoverymanager_fuzzer/BUILD.gn index ff9e6e54d..20d05de72 100644 --- a/test/commonfuzztest/dmdiscoverymanager_fuzzer/BUILD.gn +++ b/test/commonfuzztest/dmdiscoverymanager_fuzzer/BUILD.gn @@ -57,6 +57,7 @@ ohos_fuzztest("DmDiscoveryManagerFuzzTest") { external_deps = [ "device_auth:deviceauth_sdk", + "ffrt:libffrt", "safwk:system_ability_fwk", ] } diff --git a/test/commonfuzztest/hichainconnector_fuzzer/BUILD.gn b/test/commonfuzztest/hichainconnector_fuzzer/BUILD.gn index 77b80dd28..ef286102d 100644 --- a/test/commonfuzztest/hichainconnector_fuzzer/BUILD.gn +++ b/test/commonfuzztest/hichainconnector_fuzzer/BUILD.gn @@ -53,6 +53,7 @@ ohos_fuzztest("HichainConnectorFuzzTest") { "device_auth:deviceauth_sdk", "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", + "ffrt:libffrt", "ipc:ipc_single", "safwk:system_ability_fwk", ] diff --git a/test/commonfuzztest/ondatareceived_fuzzer/BUILD.gn b/test/commonfuzztest/ondatareceived_fuzzer/BUILD.gn index af93d673e..3c10d43a4 100644 --- a/test/commonfuzztest/ondatareceived_fuzzer/BUILD.gn +++ b/test/commonfuzztest/ondatareceived_fuzzer/BUILD.gn @@ -53,6 +53,7 @@ ohos_fuzztest("OnDataReceivedFuzzTest") { "device_auth:deviceauth_sdk", "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", + "ffrt:libffrt", "ipc:ipc_single", "safwk:system_ability_fwk", ] diff --git a/test/commonfuzztest/onfinish_fuzzer/BUILD.gn b/test/commonfuzztest/onfinish_fuzzer/BUILD.gn index 4a69a47c2..9be7418d3 100644 --- a/test/commonfuzztest/onfinish_fuzzer/BUILD.gn +++ b/test/commonfuzztest/onfinish_fuzzer/BUILD.gn @@ -52,6 +52,7 @@ ohos_fuzztest("OnFinishFuzzTest") { "device_auth:deviceauth_sdk", "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", + "ffrt:libffrt", "ipc:ipc_single", "safwk:system_ability_fwk", ] diff --git a/test/commonfuzztest/onrequest_fuzzer/BUILD.gn b/test/commonfuzztest/onrequest_fuzzer/BUILD.gn index 75ebd763e..0607ba065 100644 --- a/test/commonfuzztest/onrequest_fuzzer/BUILD.gn +++ b/test/commonfuzztest/onrequest_fuzzer/BUILD.gn @@ -53,6 +53,7 @@ ohos_fuzztest("OnRequestFuzzTest") { "device_auth:deviceauth_sdk", "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", + "ffrt:libffrt", "ipc:ipc_single", "safwk:system_ability_fwk", ] diff --git a/test/servicesfuzztest/devicemanagerservice_fuzzer/BUILD.gn b/test/servicesfuzztest/devicemanagerservice_fuzzer/BUILD.gn index 0b4beb80c..a351472f6 100644 --- a/test/servicesfuzztest/devicemanagerservice_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/devicemanagerservice_fuzzer/BUILD.gn @@ -72,6 +72,7 @@ ohos_fuzztest("DeviceManagerServiceFuzzTest") { "device_auth:deviceauth_sdk", "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", + "ffrt:libffrt", "ipc:ipc_single", "safwk:system_ability_fwk", ] diff --git a/test/servicesfuzztest/gettrusteddevicelistservice_fuzzer/BUILD.gn b/test/servicesfuzztest/gettrusteddevicelistservice_fuzzer/BUILD.gn index ea08d678c..68dbf9b50 100644 --- a/test/servicesfuzztest/gettrusteddevicelistservice_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/gettrusteddevicelistservice_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("GetTrustedDeviceListServiceFuzzTest") { "device_auth:deviceauth_sdk", "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", + "ffrt:libffrt", "ipc:ipc_single", "safwk:system_ability_fwk", ] diff --git a/test/servicesfuzztest/shiftlnngeardeviceservice_fuzzer/BUILD.gn b/test/servicesfuzztest/shiftlnngeardeviceservice_fuzzer/BUILD.gn index 51f7c3fcb..d7de12214 100644 --- a/test/servicesfuzztest/shiftlnngeardeviceservice_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/shiftlnngeardeviceservice_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("ShiftLNNGearDeviceServiceFuzzTest") { "device_auth:deviceauth_sdk", "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", + "ffrt:libffrt", "ipc:ipc_single", "safwk:system_ability_fwk", ] diff --git a/utils/BUILD.gn b/utils/BUILD.gn index d3680dcd8..e24c1d0c8 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -122,7 +122,6 @@ if (defined(ohos_lite)) { "bundle_framework:appexecfwk_core", "cJSON:cjson", "c_utils:utils", - "eventhandler:libeventhandler", "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", diff --git a/utils/include/timer/dm_timer.h b/utils/include/timer/dm_timer.h index ae732a6a9..1472ca2ac 100644 --- a/utils/include/timer/dm_timer.h +++ b/utils/include/timer/dm_timer.h @@ -19,15 +19,12 @@ #include #include #include -#include #include #include #include -#include -#include -#include +#include -#include "event_handler.h" +#include "ffrt" namespace OHOS { namespace DistributedHardware { @@ -73,7 +70,7 @@ public: private: mutable std::mutex timerMutex_; std::unordered_map timerVec_ = {}; - std::shared_ptr queue_; + ffrt::queue queue_; }; } } diff --git a/utils/src/timer/dm_timer.cpp b/utils/src/timer/dm_timer.cpp index ea482925c..3d79ccd6e 100644 --- a/utils/src/timer/dm_timer.cpp +++ b/utils/src/timer/dm_timer.cpp @@ -27,11 +27,6 @@ constexpr const char* TIMER_TASK = "TimerTask"; DmTimer::DmTimer() { LOGI("DmTimer constructor"); - if (queue_ != nullptr) { - LOGI("DmTimer already init."); - return; - } - queue_ = std::make_shared(TIMER_TASK); } DmTimer::~DmTimer() @@ -43,19 +38,19 @@ DmTimer::~DmTimer() int32_t DmTimer::StartTimer(std::string name, int32_t timeOut, TimerCallback callback) { if (name.empty() || timeOut <= MIN_TIME_OUT || timeOut > MAX_TIME_OUT || callback == nullptr) { - LOGI("DmTimer StartTimer input value invalid"); + LOGE("DmTimer StartTimer input value invalid"); return ERR_DM_INPUT_PARA_INVALID; } LOGI("DmTimer StartTimer start name: %{public}s", name.c_str()); std::lock_guard locker(timerMutex_); auto taskFunc = [callback, name] () { callback(name); }; - if (queue_ != nullptr) { - ffrt::task_handle h = queue_->submit_h(taskFunc, ffrt::task_attr().delay(timeOut * MILLISECOND_TO_SECOND)); - if (h != nullptr) { - timerVec_.insert(name, h); - } + ffrt::task_handle handle = queue_.submit_h(taskFunc, ffrt::task_attr().delay(timeOut * MILLISECOND_TO_SECOND)); + if (handle == nullptr) { + LOGE("handle is nullptr."); + return ERR_DM_FAILED; } + timerVec_[name] = std::move(handle); return DM_OK; } @@ -67,13 +62,16 @@ int32_t DmTimer::DeleteTimer(std::string timerName) } LOGI("DmTimer DeleteTimer start name: %{public}s", timerName.c_str()); std::lock_guard locker(timerMutex_); - if (timerVec_.empty() || timerVec_.find(timerName) == timerVec_.end()) { - LOGI("DmTimer DeleteTimer is not exist."); + auto item = timerVec_.find(timerName); + if (item == timerVec_.end()) { + LOGI("Invalid task."); return ERR_DM_FAILED; } - ffrt::task_handle h = timerVec_.find(timerName); - if (queue_ != nullptr && h != nullptr) { - queue_->skip(h); + if (item->second != nullptr) { + int32_t ret = queue_.cancel(item->second); + if (ret != 0) { + LOGE("Cancel failed, errCode: %{public}d.", ret); + } } timerVec_.erase(timerName); return DM_OK; @@ -83,17 +81,16 @@ int32_t DmTimer::DeleteAll() { LOGI("DmTimer DeleteAll start"); std::lock_guard locker(timerMutex_); - if (queue_ == nullptr) { - return ERR_DM_FAILED; - } if (timerVec_.empty()) { LOGI("DmTimer is empty"); return DM_OK; } - for (auto name : timerVec_) { - ffrt::task_handle h = timerVec_.find(name); - if (queue_ != nullptr && h != nullptr) { - queue_->skip(h); + for (const auto &name : timerVec_) { + if (name.second != nullptr) { + int32_t ret = queue_.cancel(name.second); + if (ret != 0) { + LOGE("Cancel failed, errCode: %{public}d.", ret); + } } } timerVec_.clear();