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: 8 additions & 0 deletions src/CBasic/CStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ class CSTATUS {
return error_code_ < STATUS_OK; // 约定异常信息,均为负值
}

/**
* 没有异常。包含 > 0 的警告类型
* @return
*/
bool isNotErr() const {
return error_code_ >= STATUS_OK;
}

/**
* 判断当前状态是否是崩溃了
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,26 @@ CVoid GDynamicEngine::process(GElementPtr element, CBool affinity) {
return;
}

const auto& exec = [this, element] {
element->refresh();
const CStatus& curStatus = element->fatProcessor(CFunctionType::RUN);
if (unlikely(curStatus.isErr())) {
// 当且仅当整体状正常,且当前状态异常的时候,进入赋值逻辑。确保不重复赋值
CGRAPH_LOCK_GUARD lk(status_lock_);
cur_status_ += curStatus;
locker_.cv_.notify_one();
}
afterElementRun(element);
};

if (affinity && element->isDefaultBinding()) {
// 如果 affinity=true,表示用当前的线程,执行这个逻辑。以便增加亲和性
exec();
innerExec(element);
} else {
thread_pool_->execute([this, element] {
this->innerExec(element); }, element->binding_index_);
}
}


CVoid GDynamicEngine::innerExec(GElementPtr element) {
element->refresh();
const CStatus& curStatus = element->fatProcessor(CFunctionType::RUN);
if (likely(curStatus.isNotErr())) {
afterElementRun(element);
} else {
thread_pool_->execute(exec, element->binding_index_);
// 遇到异常情况,结束整体逻辑
CGRAPH_LOCK_GUARD lk(status_lock_);
cur_status_ += curStatus;
locker_.cv_.notify_one();
}
}

Expand Down Expand Up @@ -187,6 +190,8 @@ CVoid GDynamicEngine::afterElementRun(GElementPtr element) {
}
break;
default:
CGRAPH_LOCK_GUARD lk(status_lock_);
cur_status_.setErrorInfo("element shape type error");
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ class GDynamicEngine : public GEngine {
*/
CVoid process(GElementPtr element, CBool affinity);

/**
* element 前后执行逻辑
* @param element
* @return
*/
CVoid innerExec(GElementPtr element);

/**
* element 运行完成处理
* @param element
Expand Down
10 changes: 5 additions & 5 deletions test/Functional/test-functional-99.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/***************************
@Author: Chunel
@Contact: chunel@foxmail.com
@File: test-functional-05.cpp
@File: test-functional-99.cpp
@Time: 2024/1/6 16:45
@Desc:
***************************/
Expand All @@ -11,18 +11,18 @@

using namespace CGraph;

void test_functional_05() {
void test_functional_99() {
GPipelinePtr pipeline = GPipelineFactory::create();
CStatus status;
GElementPtr a, b, c, d = nullptr;
status += pipeline->registerGElement<TestReturnErrorGNode>(&a, {});
status += pipeline->registerGElement<TestReturnErrorGNode>(&b, {});
status += pipeline->registerGElement<TestReturnErrorGNode>(&c, {});
status += pipeline->registerGElement<TestReturnErrorGNode>(&d, {});
status += pipeline->registerGElement<TestReturnErrorGNode>(&d, {c});

pipeline->init();
{
UTimeCounter counter("test_functional_05");
UTimeCounter counter("test_functional_99");
for (int i = 0; i < 10; i++) {
status = pipeline->run();
if (!status.isOK()) {
Expand All @@ -37,6 +37,6 @@ void test_functional_05() {


int main() {
test_functional_05();
test_functional_99();
return 0;
}
Loading