Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/GraphCtrl/GraphElement/GElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ GElementRelation GElement::getRelation() const {
GElementRelation relation;
relation.predecessors_ = this->dependence_.asVector(); // 前驱
relation.successors_ = this->run_before_.asVector(); // 后继
relation.children_ = this->getChildren();
relation.children_ = this->children_;
relation.belong_ = this->belong_; // 从属信息

return relation;
Expand Down Expand Up @@ -595,12 +595,6 @@ GElementPtrArr GElement::getDeepPath(CBool reverse) const {
}


GElementPtrArr GElement::getChildren() const {
(void)(this);
return GElementPtrArr{};
}


CBool GElement::isDefaultBinding() const {
return CGRAPH_DEFAULT_BINDING_INDEX == binding_index_;
}
Expand Down
7 changes: 1 addition & 6 deletions src/GraphCtrl/GraphElement/GElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,6 @@ class GElement : public GElementObject,
*/
GElement* updateAspectInfo();

/**
* 获取其中包含的内容
* @return
* @notice 仅在为 group 的情况下有意义
*/
virtual std::vector<GElement *> getChildren() const;

private:
/** 状态相关信息 */
Expand Down Expand Up @@ -472,6 +466,7 @@ class GElement : public GElementObject,
USmallVector<GElement *> run_before_ {}; // 被依赖的节点(后继)
USmallVector<GElement *> dependence_ {}; // 依赖的节点信息(前驱)
GElement* belong_ { nullptr }; // 从属的element 信息,如为nullptr,则表示从属于 pipeline
std::vector<GElement *> children_ {}; // 子节点,适用于group类型

/** 异步执行相关信息 */
std::future<CStatus> async_result_; // 用于记录当前节点的异步执行情况
Expand Down
2 changes: 1 addition & 1 deletion src/GraphCtrl/GraphElement/GElement.inl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ GElementPtr GElement::addEParam(const std::string& key, T* param) {
template<typename T,
c_enable_if_t<std::is_base_of<GElementParam, T>::value, int>>
T* GElement::getEParam(const std::string& key) {
auto iter = local_params_.find(key);
const auto iter = local_params_.find(key);
if (iter == local_params_.end()) {
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion src/GraphCtrl/GraphElement/GElementRepository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ CVoid GElementRepository::fetch(GElementPtr element) {
if (element->isGGroup()) {
auto group = dynamic_cast<GGroupPtr>(element);
CGRAPH_ASSERT_NOT_NULL_THROW_ERROR(group)
for (auto* cur : group->group_elements_arr_) {
for (auto* cur : group->children_) {
fetch(cur);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/GraphCtrl/GraphElement/GGroup/GCluster/GCluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GCluster::GCluster() {

CStatus GCluster::run() {
CGRAPH_FUNCTION_BEGIN
for (GElementPtr element : this->group_elements_arr_) {
for (GElementPtr element : this->children_) {
status = element->fatProcessor(CFunctionType::RUN);
CGRAPH_FUNCTION_CHECK_STATUS
}
Expand All @@ -34,8 +34,8 @@ CVoid GCluster::dump(std::ostream& oss) {
oss << "color=blue;\n";

GElementPtr pre = nullptr;
for (CSize i = 0; i < group_elements_arr_.size(); i++) {
const auto& element = group_elements_arr_[i];
for (CSize i = 0; i < children_.size(); i++) {
const auto& element = children_[i];
element->dump(oss);

if (0 != i) {
Expand Down
12 changes: 6 additions & 6 deletions src/GraphCtrl/GraphElement/GGroup/GCondition/GCondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ CStatus GCondition::run() {

CIndex index = this->choose();
if (internal::CGRAPH_CONDITION_LAST_INDEX == index
&& !this->group_elements_arr_.empty()) {
&& !this->children_.empty()) {
// 如果返回-1,则直接执行最后一个条件(模仿default功能)
auto element = group_elements_arr_.back();
auto element = children_.back();
status = element->fatProcessor(CFunctionType::RUN);
} else if (0 <= index && index < (CIndex)group_elements_arr_.size()) {
} else if (0 <= index && index < (CIndex)children_.size()) {
// 如果返回的内容,在元素范围之内,则直接执行元素的内容。不在的话,则不执行任何操作,直接返回正确状态
auto element = group_elements_arr_[index];
auto element = children_[index];
status = element->fatProcessor(CFunctionType::RUN);
}

Expand All @@ -41,8 +41,8 @@ CVoid GCondition::dump(std::ostream& oss) {
oss << 'p' << this << "[shape=diamond];\n";
oss << "color=blue;\n";

for (CSize i = 0; i < group_elements_arr_.size(); ++i) {
const auto& cur = group_elements_arr_[i];
for (CSize i = 0; i < children_.size(); ++i) {
const auto& cur = children_[i];
cur->dump(oss);

const std::string& label = "[label=\"" + std::to_string(i) + "\"]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ template<GMultiConditionType type>
CStatus GMultiCondition<type>::serialRun() {
CGRAPH_FUNCTION_BEGIN

for (auto cur: this->group_elements_arr_) {
for (auto* cur: this->children_) {
if (cur->isMatch()) {
// 仅依次执行 match 的逻辑
status = cur->fatProcessor(CFunctionType::RUN);
Expand All @@ -59,7 +59,7 @@ template<GMultiConditionType type>
CStatus GMultiCondition<type>::parallelRun() {
CGRAPH_FUNCTION_BEGIN
std::vector<std::future<CStatus> > futures;
for (GElementPtr cur : this->group_elements_arr_) {
for (auto* cur : this->children_) {
if (!cur->isMatch()) {
continue; // 不满足条件,则不执行
}
Expand Down Expand Up @@ -91,7 +91,7 @@ CIndex GMultiCondition<type>::choose() {

template<GMultiConditionType type>
CBool GMultiCondition<type>::isSerializable() const {
if (GMultiConditionType::PARALLEL == type && group_elements_arr_.size() > 1) {
if (GMultiConditionType::PARALLEL == type && children_.size() > 1) {
/**
* 如果是PARALLEL模式的话,并且其中的元素个数大于1,则一定不可以串行执行
* PARALLEL模式中,仅有一个元素的情况,和 SERIAL模式的判断方式一样,
Expand Down
17 changes: 6 additions & 11 deletions src/GraphCtrl/GraphElement/GGroup/GGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ GGroup::GGroup() {
CStatus GGroup::init() {
CGRAPH_FUNCTION_BEGIN

for (GElementPtr element : group_elements_arr_) {
for (GElementPtr element : children_) {
CGRAPH_ASSERT_NOT_NULL(element)
status += element->fatProcessor(CFunctionType::INIT);
}
Expand All @@ -31,7 +31,7 @@ CStatus GGroup::init() {
CStatus GGroup::destroy() {
CGRAPH_FUNCTION_BEGIN

for (GElementPtr element : group_elements_arr_) {
for (GElementPtr element : children_) {
CGRAPH_ASSERT_NOT_NULL(element)
status += element->fatProcessor(CFunctionType::DESTROY);
}
Expand All @@ -46,7 +46,7 @@ CStatus GGroup::addElement(GElementPtr element) {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_NOT_NULL(element)

this->group_elements_arr_.emplace_back(element);
this->children_.emplace_back(element);
element->belong_ = this;
// 在这里不要进行判断返回值,因为可能是region刚刚创建的时候,还没被写入 pipeline中
element->addManagers(param_manager_, event_manager_, stage_manager_);
Expand All @@ -61,11 +61,6 @@ CStatus GGroup::addElementEx(GElementPtr element) {
}


GElementPtrArr GGroup::getChildren() const {
return group_elements_arr_;
}


CVoid GGroup::dumpGroupLabelBegin(std::ostream& oss) {
oss << "subgraph ";
oss << "cluster_p" << this; // cluster_ 是 graphviz的关键字,和CGraph中GCluster逻辑无关
Expand Down Expand Up @@ -97,7 +92,7 @@ CBool GGroup::isSerializable() const {
* 针对group的情况,应该是所有在其中的element 都是可以串行的,才认定为可串行
* 但是在 region和 multiCondition中,有针对性的判断
*/
return std::all_of(group_elements_arr_.begin(), group_elements_arr_.end(),
return std::all_of(children_.begin(), children_.end(),
[](GElementPtr element) {
return element->isSerializable();
});
Expand All @@ -114,7 +109,7 @@ CStatus GGroup::addManagers(GParamManagerPtr paramManager,
status = GElement::addManagers(paramManager, eventManager, stageManager);
CGRAPH_FUNCTION_CHECK_STATUS

for (GElementPtr element : group_elements_arr_) {
for (auto* element : children_) {
CGRAPH_ASSERT_NOT_NULL(element)
status += element->addManagers(paramManager, eventManager, stageManager);
}
Expand All @@ -131,7 +126,7 @@ CBool GGroup::isSeparate(GElementCPtr a, GElementCPtr b) const {
CStatus GGroup::__addGElements_4py(const GElementPtrArr& elements) {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_INIT(false)
for (GElementPtr element : elements) {
for (auto* element : elements) {
status += addElement(element);
}
CGRAPH_FUNCTION_END
Expand Down
5 changes: 0 additions & 5 deletions src/GraphCtrl/GraphElement/GGroup/GGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class GGroup : public GElement {

CStatus destroy() override;

GElementPtrArr getChildren() const override;

/**
* 生成graphviz中 group对应的label 的开头信息
* @param oss
Expand All @@ -71,9 +69,6 @@ class GGroup : public GElement {
*/
virtual CBool isSeparate(GElementCPtr a, GElementCPtr b) const;

private:
GElementPtrArr group_elements_arr_; // 存放 element的数组

friend class GPipeline;
friend class GCluster;
friend class GRegion;
Expand Down
8 changes: 4 additions & 4 deletions src/GraphCtrl/GraphElement/GGroup/GMutable/GMutable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ CStatus GMutable::run() {
* 3. 通过 manager 执行
*/
setup();
status = reshape(group_elements_arr_);
status = reshape(children_);
CGRAPH_FUNCTION_CHECK_STATUS

status = manager_->process({group_elements_arr_.begin(), group_elements_arr_.end()});
status = manager_->process({children_.begin(), children_.end()});
CGRAPH_FUNCTION_END
}


CStatus GMutable::destroy() {
CGRAPH_FUNCTION_BEGIN
for (auto* element : group_elements_arr_) {
for (auto* element : children_) {
// 链路中,可能会将部分内容设置为 visible 的信息。这里统一恢复一下
element->setVisible(true);
}
Expand All @@ -76,7 +76,7 @@ GElementPtr GMutable::setThreadPoolEx(UThreadPoolPtr ptr) {


CVoid GMutable::setup() {
for (auto* element : group_elements_arr_) {
for (auto* element : children_) {
element->run_before_.clear();
element->dependence_.clear();
element->setLoop(1);
Expand Down
10 changes: 5 additions & 5 deletions src/GraphCtrl/GraphElement/GGroup/GSome/GSome.inl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ CStatus GSome<TriggerNum>::run() {
* 3. 将所有未执行完的element 设置为timeout
* 4. 赋返回值
*/
for (auto* element : group_elements_arr_) {
for (auto* element : children_) {
thread_pool_->commit([this, element] {
{
const auto& curStatus = element->fatProcessor(CFunctionType::RUN);
Expand All @@ -68,7 +68,7 @@ CStatus GSome<TriggerNum>::run() {
return left_num_ <= 0 || cur_status_.isErr();
});

for (auto* element : group_elements_arr_) {
for (auto* element : children_) {
if (!element->done_) {
element->cur_state_.store(GElementState::TIMEOUT, std::memory_order_release);
}
Expand All @@ -91,7 +91,7 @@ CVoid GSome<TriggerNum>::dump(std::ostream& oss) {
oss << 'p' << this << "[shape=point height=0];\n";
oss << "color=blue;style=dashed;\n"; // 蓝色虚线

for (const auto& element : group_elements_arr_) {
for (const auto& element : children_) {
element->dump(oss);
}

Expand All @@ -118,9 +118,9 @@ CStatus GSome<TriggerNum>::checkSuitable() {

CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION((CGRAPH_DEFAULT_LOOP_TIMES != loop_), "GSome cannot set loop > 1.")
CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION((0 >= TriggerNum), "trigger num must bigger than 0.")
CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION((group_elements_arr_.size() < TriggerNum), \
CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION((children_.size() < TriggerNum), \
"this GSome need at least [" + std::to_string(TriggerNum) + "] element.")
CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION(std::any_of(group_elements_arr_.begin(), group_elements_arr_.end(), [](GElementPtr ptr) {
CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION(std::any_of(children_.begin(), children_.end(), [](GElementPtr ptr) {
return !ptr->isAsync();
}), "GSome contains async node only.")

Expand Down
2 changes: 1 addition & 1 deletion src/GraphCtrl/GraphPipeline/_GStroage/GStorageDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct _GElementStorage : public _GStorageBasic {
for (const auto* dep : element->dependence_) {
dependence_sessions_.emplace_back(dep->getSession());
}
for (const auto* child : element->getChildren()) {
for (const auto* child : element->children_) {
children_.emplace_back(child);
}
if (element->aspect_manager_) {
Expand Down
Loading