From afc5c1c869ccee58f5f83edd32ab8425edf4143f Mon Sep 17 00:00:00 2001 From: ChunelFeng Date: Fri, 22 Mar 2024 21:59:34 +0800 Subject: [PATCH] [perf] simply some code, simple change parallel strategy --- src/GraphCtrl/GraphDaemon/GDaemonManager.cpp | 17 +---------------- src/GraphCtrl/GraphDaemon/GDaemonManager.h | 4 +--- .../_GEngine/GDynamicEngine/GDynamicEngine.cpp | 9 ++++----- src/GraphCtrl/GraphEvent/GEvent.cpp | 12 ++++-------- src/UtilsCtrl/ThreadPool/Task/UTask.h | 2 +- 5 files changed, 11 insertions(+), 33 deletions(-) diff --git a/src/GraphCtrl/GraphDaemon/GDaemonManager.cpp b/src/GraphCtrl/GraphDaemon/GDaemonManager.cpp index 1220855d..0f61a836 100644 --- a/src/GraphCtrl/GraphDaemon/GDaemonManager.cpp +++ b/src/GraphCtrl/GraphDaemon/GDaemonManager.cpp @@ -68,22 +68,7 @@ CStatus GDaemonManager::clear() { CSize GDaemonManager::getSize() const { - CSize size = daemons_.size(); - return size; -} - - -GDaemonManagerPtr GDaemonManager::setInterval(CMSec interval) { - if (0 == interval) { - return this; - } - - for (auto daemon : daemons_) { - CGRAPH_ASSERT_NOT_NULL_THROW_ERROR(daemon) - daemon->setInterval(interval); - } - - return this; + return daemons_.size(); } CGRAPH_NAMESPACE_END diff --git a/src/GraphCtrl/GraphDaemon/GDaemonManager.h b/src/GraphCtrl/GraphDaemon/GDaemonManager.h index 59be2343..d3fb33f8 100644 --- a/src/GraphCtrl/GraphDaemon/GDaemonManager.h +++ b/src/GraphCtrl/GraphDaemon/GDaemonManager.h @@ -21,8 +21,6 @@ class GDaemonManager : public GDaemonObject, ~GDaemonManager() override; - GDaemonManager* setInterval(CMSec interval) override; - CStatus init() final; CStatus destroy() final; @@ -40,7 +38,7 @@ class GDaemonManager : public GDaemonObject, CGRAPH_NO_ALLOWED_COPY(GDaemonManager) private: - GDaemonSet daemons_; // daemon信息集合 + GDaemonSet daemons_ {}; // daemon信息集合 }; using GDaemonManagerPtr = GDaemonManager *; diff --git a/src/GraphCtrl/GraphElement/_GEngine/GDynamicEngine/GDynamicEngine.cpp b/src/GraphCtrl/GraphElement/_GEngine/GDynamicEngine/GDynamicEngine.cpp index 3154070f..d94c2a97 100644 --- a/src/GraphCtrl/GraphElement/_GEngine/GDynamicEngine/GDynamicEngine.cpp +++ b/src/GraphCtrl/GraphElement/_GEngine/GDynamicEngine/GDynamicEngine.cpp @@ -111,7 +111,8 @@ CVoid GDynamicEngine::mark(const GSortedGElementPtrSet& elements) { CVoid GDynamicEngine::analysisDagType(const GSortedGElementPtrSet& elements) { - if (total_element_arr_.empty() || front_element_arr_.size() == 1 && total_element_arr_.size() - 1 == linked_size_) { + if (total_element_arr_.empty() + || (front_element_arr_.size() == 1 && total_element_arr_.size() - 1 == linked_size_)) { /** * 如果所有的信息中,只有一个是非linkable。则说明只有开头的那个是的,且只有一个开头 * 故,这里将其认定为一条 lineal 的情况 @@ -213,15 +214,13 @@ CVoid GDynamicEngine::parallelRunAll() { * 非纯并行逻辑,不走此函数 */ std::vector> futures; - futures.reserve(total_end_size_ - 1); - for (int i = 1; i < total_end_size_; i++) { + futures.reserve(total_end_size_); + for (int i = 0; i < total_end_size_; i++) { futures.emplace_back(std::move(thread_pool_->commit([this, i] { return total_element_arr_[i]->fatProcessor(CFunctionType::RUN); }, calcIndex(total_element_arr_[i])))); } - // 将 1~n 的数据,放入线程池。第0个,本地直接执行即可,类似亲和性处理 - cur_status_ += (*front_element_arr_.begin())->fatProcessor(CFunctionType::RUN); for (auto& fut : futures) { cur_status_ += fut.get(); } diff --git a/src/GraphCtrl/GraphEvent/GEvent.cpp b/src/GraphCtrl/GraphEvent/GEvent.cpp index 489488e1..c9ae1209 100644 --- a/src/GraphCtrl/GraphEvent/GEvent.cpp +++ b/src/GraphCtrl/GraphEvent/GEvent.cpp @@ -80,22 +80,18 @@ CVoid GEvent::asyncWait(GEventAsyncStrategy strategy) { switch (strategy) { case GEventAsyncStrategy::PIPELINE_RUN_FINISH: { for (auto& cur : async_run_finish_futures_) { - if (cur.valid()) { - cur.wait(); - } + cur.valid() ? cur.wait() : void(); } async_run_finish_futures_.clear(); - } break; + } case GEventAsyncStrategy::PIPELINE_DESTROY: { for (auto& cur : async_destroy_futures_) { - if (cur.valid()) { - cur.wait(); - } + cur.valid() ? cur.wait() : void(); } async_destroy_futures_.clear(); - } break; + } default: CGRAPH_THROW_EXCEPTION("unknown event async strategy type") } diff --git a/src/UtilsCtrl/ThreadPool/Task/UTask.h b/src/UtilsCtrl/ThreadPool/Task/UTask.h index d1fc6632..d6d95975 100644 --- a/src/UtilsCtrl/ThreadPool/Task/UTask.h +++ b/src/UtilsCtrl/ThreadPool/Task/UTask.h @@ -17,7 +17,7 @@ CGRAPH_NAMESPACE_BEGIN -class UTask : public UThreadObject { +class UTask : public CStruct { struct TaskBased { explicit TaskBased() = default; virtual CVoid call() = 0;