From b4e4075b56fb99e0a1139563cdb2b07b7d0a968b Mon Sep 17 00:00:00 2001 From: mengyiping <1091773127@qq.com> Date: Wed, 8 Nov 2023 15:24:15 +0800 Subject: [PATCH] feature Signed-off-by: mengyiping <1091773127@qq.com> --- bundle.json | 3 +- interfaces/innerkits/frameintf/BUILD.gn | 1 + .../innerkits/frameintf/frame_msg_intf.cpp | 88 +++++++++---------- .../innerkits/frameintf/frame_msg_intf.h | 11 ++- test/BUILD.gn | 2 + test/unittest/phone/frame_msg_intf_test.cpp | 5 +- 6 files changed, 52 insertions(+), 58 deletions(-) diff --git a/bundle.json b/bundle.json index e8be692..fafa4f9 100644 --- a/bundle.json +++ b/bundle.json @@ -24,6 +24,7 @@ "components": [ "c_utils", "eventhandler", + "ffrt", "hitrace", "hilog", "samgr", @@ -85,4 +86,4 @@ ] } } -} +} \ No newline at end of file diff --git a/interfaces/innerkits/frameintf/BUILD.gn b/interfaces/innerkits/frameintf/BUILD.gn index 40c1f1e..be92f22 100644 --- a/interfaces/innerkits/frameintf/BUILD.gn +++ b/interfaces/innerkits/frameintf/BUILD.gn @@ -110,6 +110,7 @@ ohos_shared_library("frame_msg_intf") { external_deps = [ "c_utils:utils", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", ] diff --git a/interfaces/innerkits/frameintf/frame_msg_intf.cpp b/interfaces/innerkits/frameintf/frame_msg_intf.cpp index 33cb728..afd6d4e 100644 --- a/interfaces/innerkits/frameintf/frame_msg_intf.cpp +++ b/interfaces/innerkits/frameintf/frame_msg_intf.cpp @@ -15,7 +15,6 @@ #include "frame_msg_intf.h" #include "intellisense_server.h" -#include "event_handler.h" #include "rme_log_domain.h" namespace OHOS { @@ -28,30 +27,33 @@ FrameMsgIntf& FrameMsgIntf::GetInstance() return instance; } +FrameMsgIntf::~FrameMsgIntf() +{ + if (taskQueue_ != nullptr) { + delete taskQueue_; + taskQueue_ = nullptr; + } +} + bool FrameMsgIntf::Init() { - std::lock_guard autoLock(frameMsgIntfMutex_); + std::lock_guard autoLock(frameMsgIntfMutex_); RME_LOGI("init begin!"); - if (!GetThreadHandler()) { + if (!GetThreadQueue()) { return false; } - threadHandler_->PostTask([] { + taskQueue_->submit([] { IntelliSenseServer::GetInstance().Init(); }); return true; } -bool FrameMsgIntf::GetThreadHandler() +bool FrameMsgIntf::GetThreadQueue() { - if (threadHandler_ == nullptr) { - runner_ = AppExecFwk::EventRunner::Create("frame_aware_sched_msg"); - if (runner_ == nullptr) { - RME_LOGE("failed to create eventRunner!"); - return false; - } - threadHandler_ = std::make_shared(runner_); - if (threadHandler_ == nullptr) { - RME_LOGE("failed to create thread handler!"); + if (taskQueue_ == nullptr) { + taskQueue_ = new (ffrt::queue)("frame_aware_sched_msg"); + if (taskQueue_ == nullptr) { + RME_LOGE("failed to create taskQueue!"); return false; } } @@ -61,76 +63,76 @@ bool FrameMsgIntf::GetThreadHandler() void FrameMsgIntf::ReportWindowFocus(const int pid, const int uid, const int isFocus) { - std::lock_guard autoLock(frameMsgIntfMutex_); - if (threadHandler_ == nullptr) { - RME_LOGE("[ReportWindowFocus]:threandHandler none!"); + std::lock_guard autoLock(frameMsgIntfMutex_); + if (taskQueue_ == nullptr) { + RME_LOGE("[ReportWindowFocus]:taskQueue none!"); return; } - threadHandler_->PostTask([pid, uid, isFocus] { + taskQueue_->submit([pid, uid, isFocus] { IntelliSenseServer::GetInstance().ReportWindowFocus(pid, uid, isFocus); }); } void FrameMsgIntf::ReportRenderThread(const int pid, const int uid, const int renderTid) { - std::lock_guard autoLock(frameMsgIntfMutex_); + std::lock_guard autoLock(frameMsgIntfMutex_); RME_LOGI("[ReportRenderThread]:render get %{public}d with render %{pubilc}d", pid, renderTid); - if (threadHandler_ == nullptr) { - RME_LOGE("[ReportRenderThread]:threandHandler none!"); + if (taskQueue_ == nullptr) { + RME_LOGE("[ReportRenderThread]:taskQueue none!"); return; } - threadHandler_->PostTask([pid, uid, renderTid] { + taskQueue_->submit([pid, uid, renderTid] { IntelliSenseServer::GetInstance().ReportRenderThread(pid, uid, renderTid); }); } void FrameMsgIntf::ReportAppInfo(const int pid, const int uid, const std::string bundleName, ThreadState state) { - std::lock_guard autoLock(frameMsgIntfMutex_); - if (threadHandler_ == nullptr) { - RME_LOGI("[ReportAppInfo]:threandHandler none!"); + std::lock_guard autoLock(frameMsgIntfMutex_); + if (taskQueue_ == nullptr) { + RME_LOGI("[ReportAppInfo]:taskQueue none!"); return; } RME_LOGI("ReportProcessInfo pid is %{public}d, uid is %{public}d", pid, uid); - threadHandler_->PostTask([pid, uid, bundleName, state] { + taskQueue_->submit([pid, uid, bundleName, state] { IntelliSenseServer::GetInstance().ReportAppInfo(pid, uid, bundleName, state); }); } void FrameMsgIntf::ReportProcessInfo(const int pid, const int uid, const std::string bundleName, ThreadState state) { - std::lock_guard autoLock(frameMsgIntfMutex_); - if (threadHandler_ == nullptr) { - RME_LOGI("[ReportProcessInfo]:threandHandler none!"); + std::lock_guard autoLock(frameMsgIntfMutex_); + if (taskQueue_ == nullptr) { + RME_LOGI("[ReportProcessInfo]:taskQueue none!"); return; } - threadHandler_->PostTask([pid, uid, bundleName, state] { + taskQueue_->submit([pid, uid, bundleName, state] { IntelliSenseServer::GetInstance().ReportProcessInfo(pid, uid, bundleName, state); }); } void FrameMsgIntf::ReportCgroupChange(const int pid, const int uid, const int oldGroup, const int newGroup) { - std::lock_guard autoLock(frameMsgIntfMutex_); - if (threadHandler_ == nullptr) { - RME_LOGI("[ReportProcessInfo]:threandHandler none!"); + std::lock_guard autoLock(frameMsgIntfMutex_); + if (taskQueue_ == nullptr) { + RME_LOGI("[ReportProcessInfo]:taskQueue none!"); return; } RME_LOGI("CgroupChanged pid is %{public}d, uid is %{public}d, oldGroup is %{public}d, newGroup is %{public}d", pid, uid, oldGroup, newGroup); - threadHandler_->PostTask([pid, uid, oldGroup, newGroup] { + taskQueue_->submit([pid, uid, oldGroup, newGroup] { IntelliSenseServer::GetInstance().ReportCgroupChange(pid, uid, oldGroup, newGroup); }); } void FrameMsgIntf::ReportContinuousTask(const int pid, const int uid, const int status) { - std::lock_guard autoLock(frameMsgIntfMutex_); - if (threadHandler_ == nullptr) { - RME_LOGI("[ReportProcessInfo]:threandHandler none!"); + std::lock_guard autoLock(frameMsgIntfMutex_); + if (taskQueue_ == nullptr) { + RME_LOGI("[ReportProcessInfo]:taskQueue none!"); return; } - threadHandler_->PostTask([pid, uid, status] { + taskQueue_->submit([pid, uid, status] { IntelliSenseServer::GetInstance().ReportContinuousTask(pid, uid, status); }); } @@ -142,15 +144,7 @@ void FrameMsgIntf::ReportSlideEvent(const int pid, const int uid, const int64_t void FrameMsgIntf::Stop() { - std::lock_guard autoLock(frameMsgIntfMutex_); - if (threadHandler_ != nullptr) { - threadHandler_->RemoveAllEvents(); - threadHandler_ = nullptr; - } - if (runner_ != nullptr) { - runner_->Stop(); - runner_ = nullptr; - } + return; } } // namespace RME } // namespace OHOS diff --git a/interfaces/innerkits/frameintf/frame_msg_intf.h b/interfaces/innerkits/frameintf/frame_msg_intf.h index af867da..df2c650 100644 --- a/interfaces/innerkits/frameintf/frame_msg_intf.h +++ b/interfaces/innerkits/frameintf/frame_msg_intf.h @@ -16,6 +16,7 @@ #ifndef FRAME_MSG_INTF_H #define FRAME_MSG_INTF_H +#include "ffrt.h" #include "rme_constants.h" #include "single_instance.h" #include "event_handler.h" @@ -26,7 +27,7 @@ class FrameMsgIntf { public: static FrameMsgIntf& GetInstance(); bool Init(); - bool GetThreadHandler(); + bool GetThreadQueue(); void ReportAppInfo(const int pid, const int uid, const std::string bundleName, ThreadState state); void ReportProcessInfo(const int pid, const int uid, const std::string bundleName, ThreadState state); void ReportCgroupChange(const int pid, const int uid, const int oldGroup, const int newGroup); @@ -37,12 +38,10 @@ public: void Stop(); protected: FrameMsgIntf() = default; - virtual ~FrameMsgIntf() = default; + ~FrameMsgIntf(); private: - std::mutex frameMsgIntfMutex_; - std::shared_ptr runner_; - std::shared_ptr threadHandler_; - DISALLOW_COPY_AND_MOVE(FrameMsgIntf); + ffrt::mutex frameMsgIntfMutex_; + ffrt::queue* taskQueue_; }; } // namespace RME } // namespace OHOS diff --git a/test/BUILD.gn b/test/BUILD.gn index 9da906e..f082e42 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -50,6 +50,8 @@ ohos_unittest("frame_msg_intf_test") { deps = frame_aware_sched_deps + external_deps = [ "ffrt:libffrt" ] + if (is_standard_system) { public_deps = frame_aware_sched_public_deps } diff --git a/test/unittest/phone/frame_msg_intf_test.cpp b/test/unittest/phone/frame_msg_intf_test.cpp index 34ce492..a3bb1a3 100644 --- a/test/unittest/phone/frame_msg_intf_test.cpp +++ b/test/unittest/phone/frame_msg_intf_test.cpp @@ -53,9 +53,6 @@ void FrameMsgIntfTest::SetUp() void FrameMsgIntfTest::TearDown() { - FrameMsgIntf::GetInstance().Stop(); - std::shared_ptr thread = FrameMsgIntf::GetInstance().threadHandler_; - EXPECT_TRUE(thread == nullptr); } /** @@ -70,7 +67,7 @@ HWTEST_F(FrameMsgIntfTest, ReportContinuousTaskTest, TestSize.Level1) const int uid = 100086; const int status0 = 0; const int status1 = 1; - repCon.GetThreadHandler(); + repCon.GetThreadQueue(); repCon.ReportContinuousTask(pid, uid, status0); repCon.ReportContinuousTask(pid, uid, status1); } -- Gitee