Skip to content

Commit

Permalink
[delete] remove static engine code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed May 4, 2024
1 parent b54204e commit c3c94ec
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 315 deletions.
11 changes: 6 additions & 5 deletions src/GraphCtrl/GraphElement/GAdapter/GSingleton/GSingleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ class GSingleton : public GAdapter {
private:
explicit GSingleton();

CStatus init() override;
CStatus run() override;
CStatus destroy() override;
CStatus init() final;
CStatus run() final;
CStatus destroy() final;

CStatus addElementInfo(const std::set<GElementPtr> &dependElements,
const std::string &name,
CSize loop) final;
const std::string &name, CSize loop) final;

CStatus addManagers(GParamManagerPtr paramManager,
GEventManagerPtr eventManager) final;
Expand All @@ -35,6 +34,8 @@ class GSingleton : public GAdapter {

CBool isRegistered() const final;

const std::string& getName() const final;

private:
static USingleton<T> s_singleton_; // 单例
static std::atomic<CBool> s_is_init_; // 标志是否被初始化过
Expand Down
24 changes: 15 additions & 9 deletions src/GraphCtrl/GraphElement/GAdapter/GSingleton/GSingleton.inl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CStatus GSingleton<T>::init() {
}

/* 因为采取的是饥汉模式,不需要判断ptr是否为空了 */
auto element = dynamic_cast<GElementPtr>(s_singleton_.get());
auto element = dynamic_cast<T *>(s_singleton_.get());
status = element->init();
if (status.isOK()) {
s_is_init_ = true;
Expand All @@ -63,7 +63,7 @@ CStatus GSingleton<T>::destroy() {
CGRAPH_FUNCTION_END
}

auto element = dynamic_cast<GElementPtr>(s_singleton_.get());
auto element = dynamic_cast<T *>(s_singleton_.get());
status = element->destroy();
if (status.isOK()) {
s_is_init_ = false;
Expand All @@ -75,8 +75,7 @@ CStatus GSingleton<T>::destroy() {

template <typename T>
CStatus GSingleton<T>::addElementInfo(const std::set<GElementPtr> &dependElements,
const std::string &name,
CSize loop) {
const std::string &name, CSize loop) {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_INIT(false)

Expand All @@ -86,7 +85,7 @@ CStatus GSingleton<T>::addElementInfo(const std::set<GElementPtr> &dependElement
// 这里,内部和外部均需要设定name信息
this->setName(name)->setLoop(loop);
// 获取单例信息,然后将信息node中信息
auto element = dynamic_cast<GElementPtr>(s_singleton_.get());
auto element = dynamic_cast<T *>(s_singleton_.get());
element->name_ = name;
CGRAPH_FUNCTION_END
}
Expand All @@ -99,7 +98,7 @@ CStatus GSingleton<T>::addManagers(GParamManagerPtr paramManager,

CGRAPH_ASSERT_INIT(false)
CGRAPH_ASSERT_NOT_NULL(paramManager, eventManager)
auto element = dynamic_cast<GElementPtr>(s_singleton_.get());
auto element = dynamic_cast<T *>(s_singleton_.get());
status = element->addManagers(paramManager, eventManager);

CGRAPH_FUNCTION_END
Expand All @@ -108,24 +107,31 @@ CStatus GSingleton<T>::addManagers(GParamManagerPtr paramManager,

template <typename T>
CBool GSingleton<T>::isHold(){
auto element = dynamic_cast<GElementPtr>(s_singleton_.get());
auto element = dynamic_cast<T *>(s_singleton_.get());
return element->isHold();
}


template <typename T>
CBool GSingleton<T>::isMatch() {
auto element = dynamic_cast<GElementPtr>(s_singleton_.get());
auto element = dynamic_cast<T *>(s_singleton_.get());
return element->isMatch();
}


template <typename T>
CBool GSingleton<T>::isRegistered() const {
auto element = dynamic_cast<GElementPtr>(s_singleton_.get());
auto element = dynamic_cast<T *>(s_singleton_.get());
return element->isRegistered();
}


template <typename T>
const std::string& GSingleton<T>::getName() const {
auto element = dynamic_cast<T *>(s_singleton_.get());
return element->getName();
}

CGRAPH_NAMESPACE_END

#endif //CGRAPH_GSINGLETON_INL
5 changes: 0 additions & 5 deletions src/GraphCtrl/GraphElement/GElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ GElement& GElement::operator*(CSize loop) noexcept {
}


CBool GElement::isRunnable() const {
return 0 >= this->left_depend_.load(std::memory_order_acquire) && !this->done_;
}


CBool GElement::isLinkable() const {
return this->linkable_;
}
Expand Down
8 changes: 0 additions & 8 deletions src/GraphCtrl/GraphElement/GElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,6 @@ class GElement : public GElementObject,
*/
virtual CVoid afterRun();

/**
* 判定element是否可以运行
* 可执行的条件为:自身未被执行且依赖节点全部被执行
* @return
*/
CBool isRunnable() const;

/**
* 判定node是否可以和前面节点一起执行
* @return
Expand Down Expand Up @@ -447,7 +440,6 @@ class GElement : public GElementObject,
template<CInt> friend class GCoordinator;
template<typename T> friend class GSingleton;
friend class GEngine;
friend class GStaticEngine;
friend class GDynamicEngine;
friend class GTopoEngine;
friend class GAspectObject;
Expand Down
1 change: 0 additions & 1 deletion src/GraphCtrl/GraphElement/GElementManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ CStatus GElementManager::initEngine() {
CGRAPH_DELETE_PTR(engine_)

switch (engine_type_) {
case GEngineType::STATIC : engine_ = CGRAPH_SAFE_MALLOC_COBJECT(GStaticEngine) break;
case GEngineType::DYNAMIC : engine_ = CGRAPH_SAFE_MALLOC_COBJECT(GDynamicEngine) break;
case GEngineType::TOPO: engine_ = CGRAPH_SAFE_MALLOC_COBJECT(GTopoEngine) break;
default: CGRAPH_RETURN_ERROR_STATUS("unknown engine type")
Expand Down
53 changes: 0 additions & 53 deletions src/GraphCtrl/GraphElement/GGroup/GCluster/GCluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,44 +42,6 @@ CStatus GCluster::run() {
}


CStatus GCluster::process(CBool isMock) {
CGRAPH_FUNCTION_BEGIN

this->beforeRun();
if (likely(!isMock)) {
// 如果是mock执行,则不进入这里
for (GElementPtr element : this->group_elements_arr_) {
status = element->fatProcessor(CFunctionType::RUN);
CGRAPH_FUNCTION_CHECK_STATUS
}
}

this->afterRun();
CGRAPH_FUNCTION_END
}


CVoid GCluster::beforeRun() {
this->done_ = false;
this->left_depend_ = dependence_.size();
for (GElementPtr element : this->group_elements_arr_) {
element->beforeRun();
}
}


CVoid GCluster::afterRun() {
for (GElementPtr element : this->group_elements_arr_) {
element->afterRun();
}

for (auto& element : this->run_before_) {
element->left_depend_--;
}
this->done_ = true;
}


CStatus GCluster::addElement(GElementPtr element) {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_NOT_NULL(element)
Expand All @@ -90,21 +52,6 @@ CStatus GCluster::addElement(GElementPtr element) {
}


CSize GCluster::getElementNum() {
auto num = group_elements_arr_.size();
return num;
}


CBool GCluster::isDone() {
/* 所有的element均被执行过,则提示true */
return std::all_of(group_elements_arr_.begin(), group_elements_arr_.end(),
[](GElementPtr element) {
return element->done_;
});
}


CVoid GCluster::dump(std::ostream& oss) {
dumpElement(oss);
dumpGroupLabelBegin(oss);
Expand Down
35 changes: 1 addition & 34 deletions src/GraphCtrl/GraphElement/GGroup/GCluster/GCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,26 @@
CGRAPH_NAMESPACE_BEGIN

class GCluster : public GGroup {
public:
protected:
/** 涉及到与线程池的联动,cluster类无法将构造函数申明成protected类型 */
GCluster(const GCluster& cluster);
GCluster& operator=(const GCluster& cluster);

protected:
explicit GCluster();

/**
* 获取element个数信息
* @return
*/
CSize getElementNum();

private:
/**
* 线程池中的运行函数,依次执行beforeRun,run和afterRun方法,
* 其中有任何返回值问题,则直接返回
* @param isMock 是否真实执行run方法。默认执行的
* @return
*/
CStatus process(CBool isMock);

CStatus run() final;

CStatus addElement(GElementPtr element) final;

CVoid beforeRun() final;

CVoid afterRun() final;

CVoid dump(std::ostream& oss) final;

CBool isSeparate(GElementCPtr a, GElementCPtr b) const final;

/**
* 判断是否所有element均执行结束了
* @return
*/
CBool isDone();

friend class GPipeline;
friend class GStaticEngine;
friend class GDynamicEngine;
friend class UAllocator;
};

using GClusterPtr = GCluster *;
using GClusterRef = GCluster &;
using GClusterArr = std::vector<GCluster>;
using GClusterArrRef = GClusterArr &;
using ParaWorkedClusterArrs = std::vector<GClusterArr>;

CGRAPH_NAMESPACE_END

#endif //CGRAPH_GCLUSTER_H
1 change: 0 additions & 1 deletion src/GraphCtrl/GraphElement/GGroup/GGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class GGroup : public GElement {
private:
GElementPtrArr group_elements_arr_; // 存放 element的数组

friend class GStaticEngine;
friend class GPipeline;
friend class GCluster;
friend class GRegion;
Expand Down
1 change: 0 additions & 1 deletion src/GraphCtrl/GraphElement/GGroup/GSome/GSome.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class GSome : public GGroup {
std::condition_variable cv_;

friend class GPipeline;
friend class GStaticEngine;
friend class GDynamicEngine;
friend class UAllocator;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,7 @@ CVoid GDynamicEngine::analysisDagType(const GSortedGElementPtrSet& elements) {


CVoid GDynamicEngine::process(GElementPtr element, CBool affinity) {
if (unlikely(cur_status_.isErr() || element->done_)) {
/**
* 如果已经有异常逻辑,
* 或者传入的element,是已经执行过的了(理论上不会出现这种情况,由于提升性能的原因,取消了atomic计数的逻辑,故添加这一处判定,防止意外情况)
* 则直接停止当前流程
*/
if (unlikely(cur_status_.isErr())) {
return;
}

Expand Down
5 changes: 2 additions & 3 deletions src/GraphCtrl/GraphElement/_GEngine/GEngineDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
CGRAPH_NAMESPACE_BEGIN

enum class GEngineType {
STATIC = 0, /** 静态图运行 */
DYNAMIC = 1, /** 动态图运行 */
TOPO = 2, /** 拓扑运行 */
DYNAMIC = 0, /** 动态图运行 */
TOPO = 1, /** 拓扑运行 */
};

CGRAPH_INTERNAL_NAMESPACE_BEGIN
Expand Down
1 change: 0 additions & 1 deletion src/GraphCtrl/GraphElement/_GEngine/GEngineInclude.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "GEngine.h"
#include "GEngineDefine.h"
#include "GStaticEngine/GStaticEngine.h"
#include "GDynamicEngine/GDynamicEngine.h"
#include "GTopoEngine/GTopoEngine.h"

Expand Down
Loading

0 comments on commit c3c94ec

Please sign in to comment.