Skip to content

Commit

Permalink
[feat] add async launch policy
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Dec 10, 2024
1 parent 82cb73a commit b12e703
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/GraphCtrl/GraphPipeline/GPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,23 @@ CStatus GPipeline::registerGGroup(GElementPPtr groupRef, const GElementPtrSet &d
}


std::future<CStatus> GPipeline::asyncRun() {
std::future<CStatus> GPipeline::asyncRun(std::launch policy) {
/**
* 1. 确认当前pipeline已经初始化完毕
* 2. 异步的执行 run() 方法,并且返回执行结果的 future 信息
*/
CGRAPH_ASSERT_INIT_THROW_ERROR(true)

return std::async(std::launch::async, [this] {
return std::async(policy, [this] {
return run();
});
}


std::future<CStatus> GPipeline::asyncProcess(CSize runTimes) {
std::future<CStatus> GPipeline::asyncProcess(CSize runTimes, std::launch policy) {
CGRAPH_ASSERT_INIT_THROW_ERROR(false)

return std::async(std::launch::async, [runTimes, this] {
return std::async(policy, [runTimes, this] {
return process(runTimes);
});
}
Expand Down
8 changes: 6 additions & 2 deletions src/GraphCtrl/GraphPipeline/GPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <memory>
#include <list>
#include <thread>
#include <future>
#include <sstream>

#include "GPipelineObject.h"
Expand Down Expand Up @@ -41,16 +42,19 @@ class GPipeline : public GPipelineObject,

/**
* 异步执行pipeline的run流程
* @param policy
* @return
*/
std::future<CStatus> asyncRun();
std::future<CStatus> asyncRun(std::launch policy = std::launch::any);

/**
* 异步执行pipeline的全部流程
* @param runTimes
* @param policy
* @return
*/
std::future<CStatus> asyncProcess(CSize runTimes = CGRAPH_DEFAULT_LOOP_TIMES);
std::future<CStatus> asyncProcess(CSize runTimes = CGRAPH_DEFAULT_LOOP_TIMES,
std::launch policy = std::launch::any);

/**
* 停止执行流程,多用于异步执行流程中
Expand Down

0 comments on commit b12e703

Please sign in to comment.