diff --git a/services/distributedhardwarefwkserviceimpl/include/task/monitor_task_timer.h b/services/distributedhardwarefwkserviceimpl/include/task/monitor_task_timer.h index c0f8787ce32765d8405b58642c0b51a68ec7638e..c3942035177ee86b6811f018672817b165567bea 100644 --- a/services/distributedhardwarefwkserviceimpl/include/task/monitor_task_timer.h +++ b/services/distributedhardwarefwkserviceimpl/include/task/monitor_task_timer.h @@ -39,6 +39,8 @@ public: private: MonitorTaskTimer(); void Execute(const std::shared_ptr eventHandler); + void InitTimer(); + void ReleaseTimer(); private: std::thread eventHandlerThread_; diff --git a/services/distributedhardwarefwkserviceimpl/src/task/monitor_task_timer.cpp b/services/distributedhardwarefwkserviceimpl/src/task/monitor_task_timer.cpp index 24670683d9026cd28931bb2bbbc38172f5fa6e0d..3f69e276505819ad4d6f44992b1d18cb59d5f8d9 100644 --- a/services/distributedhardwarefwkserviceimpl/src/task/monitor_task_timer.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/task/monitor_task_timer.cpp @@ -36,23 +36,37 @@ namespace { MonitorTaskTimer::MonitorTaskTimer() { DHLOGI("MonitorTaskTimer construction"); - if (!eventHandler_) { +} + +MonitorTaskTimer::~MonitorTaskTimer() +{ + DHLOGI("MonitorTaskTimer destruction"); + ReleaseTimer(); +} + +void MonitorTaskTimer::InitTimer() +{ + DHLOGI("start"); + std::unique_lock lock(monitorTaskTimerMutex_); + if (eventHandler_ == nullptr) { eventHandlerThread_ = std::thread(&MonitorTaskTimer::StartEventRunner, this); - std::unique_lock lock(monitorTaskTimerMutex_); monitorTaskTimerCond_.wait(lock, [this] { return eventHandler_ != nullptr; }); } + DHLOGI("end"); } -MonitorTaskTimer::~MonitorTaskTimer() +void MonitorTaskTimer::ReleaseTimer() { - DHLOGI("MonitorTaskTimer destruction"); + DHLOGI("start"); StopTimer(); + DHLOGI("end"); } void MonitorTaskTimer::StartEventRunner() { + DHLOGI("start"); auto busRunner = AppExecFwk::EventRunner::Create(false); { std::lock_guard lock(monitorTaskTimerMutex_); @@ -60,11 +74,13 @@ void MonitorTaskTimer::StartEventRunner() } monitorTaskTimerCond_.notify_all(); busRunner->Run(); + DHLOGI("end"); } void MonitorTaskTimer::StartTimer() { DHLOGI("start"); + InitTimer(); std::lock_guard lock(monitorTaskTimerMutex_); if (eventHandler_ == nullptr) { DHLOGE("eventHandler is nullptr!");