GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [chg] change yield to suspend · feiyunwill/CGraph@8e35360

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • python
    • PyCGraph.cpp
    • tutorial
      • MyGNode
        • MyStageNode.py
      • T12-Function.py
      • T13-Daemon.py
      • T20-Suspend.py
      • T26-Mutable.py
  • src/GraphCtrl
    • GraphElement
      • GElement.cpp
      • GElement.h
      • GElementDefine.h
      • GElementRepository.cpp
    • GraphPipeline
      • GPipeline.cpp
      • GPipeline.h
  • tutorial
    • BUILD
    • CMakeLists.txt
    • T20-Suspend.cpp
  • xmake.lua
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎python/PyCGraph.cpp‎

Copy file name to clipboardExpand all lines: python/PyCGraph.cpp
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ PYBIND11_MODULE(PyCGraph, m) {
9191
.value("DESTROY", CFunctionType::DESTROY)
9292
.export_values();
9393

94+
py::enum_<GElementState>(m, "GElementState")
95+
.value("NORMAL", GElementState::NORMAL)
96+
.value("CANCEL", GElementState::CANCEL)
97+
.value("SUSPEND", GElementState::SUSPEND)
98+
.value("TIMEOUT", GElementState::TIMEOUT)
99+
.export_values();
100+
m.attr("GPipelineState") = m.attr("GElementState");
101+
94102
py::enum_<std::launch>(m, "StdLaunchPolicy")
95103
.value("ASYNC", std::launch::async)
96104
.value("DEFERRED", std::launch::deferred)
@@ -190,7 +198,7 @@ PYBIND11_MODULE(PyCGraph, m) {
190198
py::call_guard<py::gil_scoped_release>())
191199
.def("cancel", &PywGPipeline::cancel,
192200
py::call_guard<py::gil_scoped_release>())
193-
.def("yields", &PywGPipeline::yield, // yield is python's keyword, use yields to replace
201+
.def("suspend", &PywGPipeline::suspend,
194202
py::call_guard<py::gil_scoped_release>())
195203
.def("resume", &PywGPipeline::resume,
196204
py::call_guard<py::gil_scoped_release>())
Collapse file

‎python/tutorial/MyGNode/MyStageNode.py‎

Copy file name to clipboardExpand all lines: python/tutorial/MyGNode/MyStageNode.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def run(self):
2121
time.sleep(self._before)
2222
print('[{0}] ----> {1} wait {2}s before enter stage'.format(datetime.now(), self.getName(), self._before))
2323

24-
sts: CStatus = self.enterStage('stage1')
24+
status: CStatus = self.enterStage('stage1')
2525
print('[{0}] <---- {1} wait {2}s after enter stage'.format(datetime.now(), self.getName(), self._after))
2626
time.sleep(self._after)
27-
return CStatus()
27+
return status
Collapse file

‎python/tutorial/T12-Function.py‎

Copy file name to clipboardExpand all lines: python/tutorial/T12-Function.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def d_function_init(d: GFunction):
2525
return CStatus()
2626

2727
def d_function_run(d: GFunction, num: int):
28-
# get GParam info in CFunction
28+
# get GParam info in GFunction
2929
param: MyParam = d.getGParamWithNoEmpty('param1')
3030
param.count += num
3131
print('[{0}] do run function, count is {1}, value is {2}'.format(
Collapse file

‎python/tutorial/T13-Deamon.py‎ ‎python/tutorial/T13-Daemon.py‎python/tutorial/T13-Deamon.py renamed to python/tutorial/T13-Daemon.py

Copy file name to clipboardExpand all lines: python/tutorial/T13-Daemon.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
@Author: Chunel
33
@Contact: [email protected]
4-
@File: T13-Deamon
4+
@File: T13-Daemon
55
@Time: 2025/3/30 00:46
66
@Desc:
77
"""
@@ -13,7 +13,7 @@
1313
from MyGDaemon.MyMonitorDaemon import MyMonitorGDaemon
1414

1515

16-
def tutorial_simple():
16+
def tutorial_daemon():
1717
pipeline = GPipeline()
1818
a, b = MyNode1(), MyWriteParamNode()
1919

@@ -26,5 +26,5 @@ def tutorial_simple():
2626

2727

2828
if __name__ == '__main__':
29-
tutorial_simple()
29+
tutorial_daemon()
3030

Collapse file

‎python/tutorial/T20-YieldResume.py‎ ‎python/tutorial/T20-Suspend.py‎python/tutorial/T20-YieldResume.py renamed to python/tutorial/T20-Suspend.py

Copy file name to clipboardExpand all lines: python/tutorial/T20-Suspend.py
+5-6Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
"""
22
@Author: Chunel
33
@Contact: [email protected]
4-
@File: T20-YieldResume
4+
@File: T20-Suspend
55
@Time: 2025/3/29 00:23
66
@Desc:
77
"""
88

9-
109
import time
1110

1211
from PyCGraph import GPipeline, StdFutureCStatus
@@ -15,7 +14,7 @@
1514
from MyGNode.MyNode2 import MyNode2
1615

1716

18-
def tutorial_cancel():
17+
def tutorial_suspend():
1918
pipeline = GPipeline()
2019
a, b, c, d = MyNode1(), MyNode2(), MyNode1(), MyNode2()
2120

@@ -29,8 +28,8 @@ def tutorial_cancel():
2928
result: StdFutureCStatus = pipeline.asyncRun()
3029
print("pipeline async run first time, BEGIN.")
3130
time.sleep(2.6)
32-
print("pipeline async run first time, YIELDS.")
33-
pipeline.yields()
31+
print("pipeline async run first time, SUSPEND.")
32+
pipeline.suspend()
3433

3534
time.sleep(7.2)
3635
print("pipeline async run, RESUME after 7200ms.")
@@ -41,4 +40,4 @@ def tutorial_cancel():
4140

4241

4342
if __name__ == '__main__':
44-
tutorial_cancel()
43+
tutorial_suspend()
Collapse file

‎python/tutorial/T26-GMutable.py‎ ‎python/tutorial/T26-Mutable.py‎python/tutorial/T26-GMutable.py renamed to python/tutorial/T26-Mutable.py

Copy file name to clipboard
File renamed without changes.
Collapse file

‎src/GraphCtrl/GraphElement/GElement.cpp‎

Copy file name to clipboardExpand all lines: src/GraphCtrl/GraphElement/GElement.cpp
+10-6Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,12 @@ CStatus GElement::fatProcessor(const CFunctionType& type) {
246246
do {
247247
status += isAsync() ? asyncRun() : run();
248248
/**
249-
* 在实际run结束之后,首先需要判断一下是否进入yield状态了。
249+
* 在实际run结束之后,首先需要判断一下是否进入suspend状态了。
250250
* 接下来,如果状态是ok的,并且被条件hold住,则循环执行
251251
* 默认所有element的isHold条件均为false,即不hold,即执行一次
252252
* 可以根据需求,对任意element类型,添加特定的isHold条件
253253
* */
254-
} while (checkYield(), this->isHold() && status.isOK());
254+
} while (checkSuspend(), this->isHold() && status.isOK());
255255
doAspect(internal::GAspectType::FINISH_RUN, status);
256256
}
257257

@@ -431,10 +431,14 @@ CVoid GElement::dumpPerfInfo(std::ostream& oss) {
431431
}
432432

433433

434-
CVoid GElement::checkYield() {
435-
std::unique_lock<std::mutex> lk(yield_mutex_);
436-
this->yield_cv_.wait(lk, [this] {
437-
return GElementState::YIELD != cur_state_.load(std::memory_order_acquire);
434+
CVoid GElement::checkSuspend() {
435+
if (GElementState::SUSPEND != cur_state_.load(std::memory_order_acquire)) {
436+
return;
437+
}
438+
439+
std::unique_lock<std::mutex> lk(suspend_locker_.mtx_);
440+
this->suspend_locker_.cv_.wait(lk, [this] {
441+
return GElementState::SUSPEND != cur_state_.load(std::memory_order_acquire);
438442
});
439443
}
440444

Collapse file

‎src/GraphCtrl/GraphElement/GElement.h‎

Copy file name to clipboardExpand all lines: src/GraphCtrl/GraphElement/GElement.h
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,10 @@ class GElement : public GElementObject,
376376
CVoid dumpPerfInfo(std::ostream& oss);
377377

378378
/**
379-
* 判断是否进入 yield状态。如果是的话,则等待恢复。未进入yield状态,则继续运行
379+
* 判断是否进入 suspend 状态。如果是的话,则等待恢复。未进入 suspend 状态,则继续运行
380380
* @return
381381
*/
382-
CVoid checkYield();
382+
CVoid checkSuspend();
383383

384384
/**
385385
* 判断当前元素,是否可以线性执行。默认返回true
@@ -469,8 +469,7 @@ class GElement : public GElementObject,
469469

470470
/** 异步执行相关信息 */
471471
std::future<CStatus> async_result_; // 用于记录当前节点的异步执行情况
472-
std::mutex yield_mutex_; // 控制停止执行的锁
473-
std::condition_variable yield_cv_; // 控制停止执行的条件变量
472+
UCvMutex suspend_locker_; // 控制停止执行锁信息
474473

475474
friend class GNode;
476475
friend class GGroup;
Collapse file

‎src/GraphCtrl/GraphElement/GElementDefine.h‎

Copy file name to clipboardExpand all lines: src/GraphCtrl/GraphElement/GElementDefine.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ enum class GElementType {
3939
enum class GElementState {
4040
NORMAL = 0x0000, // 正常状态
4141
CANCEL = 0x1001, // 取消状态
42-
YIELD = 0x1002, // 暂停状态
42+
SUSPEND = 0x1002, // 暂停状态(同 v3.0.0版本之前的 YIELD 含义相同)
4343
TIMEOUT = 0x1010, // 超时状态
4444
};
4545
using GPipelineState = GElementState; // pipeline 同element共享状态
Collapse file

‎src/GraphCtrl/GraphElement/GElementRepository.cpp‎

Copy file name to clipboardExpand all lines: src/GraphCtrl/GraphElement/GElementRepository.cpp
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ CStatus GElementRepository::pushAllState(const GElementState& state) {
6767

6868
for (auto& cur : elements_) {
6969
cur->cur_state_.store(state, std::memory_order_release);
70-
if (GElementState::YIELD != state) {
71-
// 目前仅非yield状态,需要切换的。如果一直处于 yield状态,是不需要被通知的
72-
cur->yield_cv_.notify_one();
70+
if (GElementState::SUSPEND != state) {
71+
// 目前仅非 suspend 状态,需要切换的。如果一直处于 suspend 状态,是不需要被通知的
72+
cur->suspend_locker_.cv_.notify_one();
7373
}
7474
}
7575
cur_state_ = state; // 记录当前的状态信息

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.