Skip to content

Commit 09d1d88

Browse files
committed
[feat] support lite mode
1 parent 4950664 commit 09d1d88

4 files changed

Lines changed: 42 additions & 5 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ option(CGRAPH_BUILD_PERFORMANCE_TESTS "Enable build performance tests" OFF)
3131
# 副作用是GParam中的锁无法递归上锁,一般情况下可忽略影响
3232
# add_definitions(-D_CGRAPH_GPARAM_RWLOCK_ENABLE_)
3333

34+
# 如果开启此宏定义,则执行过程中,仅正常执行 element 的 init/run/destroy 方法
35+
# 无 循环loop、切面aspect、退出cancel、暂停Suspend 等功能
36+
# 主要用于 简单场景 和 性能测试,一般情况不建议开启
37+
# add_definitions(-D_CGRAPH_LITE_MODE_ENABLE_)
38+
3439
# add CGraph environment info
3540
include(cmake/CGraph-env-include.cmake)
3641

‎src/GraphCtrl/GraphElement/GElement.cpp‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,37 @@ CStatus GElement::doAspect(const internal::GAspectType& aspectType, const CStatu
218218
}
219219

220220

221+
#ifdef _CGRAPH_LITE_MODE_ENABLE_
222+
CStatus GElement::fatProcessor(const CFunctionType& type) {
223+
CGRAPH_FUNCTION_BEGIN
224+
try {
225+
switch (type) {
226+
case CFunctionType::RUN: {
227+
status = run();
228+
CGRAPH_FUNCTION_CHECK_STATUS
229+
break;
230+
}
231+
case CFunctionType::INIT: {
232+
concerned_params_.clear(); // 仅需要记录这一轮使用到的 GParam 信息
233+
status = init();
234+
CGRAPH_FUNCTION_CHECK_STATUS
235+
break;
236+
}
237+
case CFunctionType::DESTROY: {
238+
status = destroy();
239+
CGRAPH_FUNCTION_CHECK_STATUS
240+
break;
241+
}
242+
default:
243+
CGRAPH_RETURN_ERROR_STATUS("get function type error")
244+
}
245+
} catch (const CException& ex) {
246+
status = crashed(ex);
247+
}
248+
249+
CGRAPH_FUNCTION_END
250+
}
251+
#else
221252
CStatus GElement::fatProcessor(const CFunctionType& type) {
222253
CGRAPH_FUNCTION_BEGIN
223254

@@ -284,6 +315,7 @@ CStatus GElement::fatProcessor(const CFunctionType& type) {
284315

285316
CGRAPH_FUNCTION_END
286317
}
318+
#endif
287319

288320

289321
CStatus GElement::prepareRun() {

‎src/GraphCtrl/GraphElement/GElementManager.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ GElementManager::~GElementManager() {
2323
CStatus GElementManager::init() {
2424
CGRAPH_FUNCTION_BEGIN
2525

26-
for (auto element : manager_elements_) {
26+
for (auto* element : manager_elements_) {
2727
CGRAPH_ASSERT_NOT_NULL(element)
2828
}
2929

3030
status = initEngine();
3131
CGRAPH_FUNCTION_CHECK_STATUS
3232

33-
for (GElementPtr element : manager_elements_) {
33+
for (auto* element : manager_elements_) {
3434
status = element->fatProcessor(CFunctionType::INIT);
3535
CGRAPH_FUNCTION_CHECK_STATUS
3636
element->is_init_ = true;
@@ -43,7 +43,7 @@ CStatus GElementManager::init() {
4343
CStatus GElementManager::destroy() {
4444
CGRAPH_FUNCTION_BEGIN
4545

46-
for (GElementPtr element : manager_elements_) {
46+
for (auto* element : manager_elements_) {
4747
status = element->fatProcessor(CFunctionType::DESTROY);
4848
CGRAPH_FUNCTION_CHECK_STATUS
4949
element->is_init_ = false;
@@ -136,7 +136,7 @@ CSize GElementManager::calcMaxParaSize() const {
136136
}
137137

138138

139-
CBool GElementManager::checkSerializable() {
139+
CBool GElementManager::checkSerializable() const {
140140
if (engine_type_ != GEngineType::DYNAMIC) {
141141
return false; // 目前仅支持动态引擎的执行方式
142142
}

‎src/GraphCtrl/GraphElement/GElementManager.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class GElementManager : public GElementObject,
8282
* 查看是否可以串行执行
8383
* @return
8484
*/
85-
CBool checkSerializable();
85+
CBool checkSerializable() const;
8686

8787
/**
8888
* 剪裁多余的连边信息

0 commit comments

Comments
 (0)