2020-04-20 23:59:47 +08:00
|
|
|
|
/*
|
|
|
|
|
* GlobalTaskGroup.h
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2019 hikyuu.org
|
|
|
|
|
*
|
|
|
|
|
* Created on: 2020-4-20
|
|
|
|
|
* Author: fasiondog
|
|
|
|
|
*/
|
|
|
|
|
|
2020-05-17 17:38:05 +08:00
|
|
|
|
#pragma once
|
2020-04-20 23:59:47 +08:00
|
|
|
|
#ifndef HKU_GLOBAL_TASK_GROUP
|
|
|
|
|
#define HKU_GLOBAL_TASK_GROUP
|
|
|
|
|
|
2021-01-15 00:19:38 +08:00
|
|
|
|
#include "../utilities/thread/StealThreadPool.h"
|
2020-04-20 23:59:47 +08:00
|
|
|
|
|
|
|
|
|
namespace hku {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取全局线程池任务组
|
|
|
|
|
* @note 请使用 future 获取任务返回
|
|
|
|
|
*/
|
2021-01-15 00:19:38 +08:00
|
|
|
|
StealThreadPool* getGlobalTaskGroup();
|
2020-04-20 23:59:47 +08:00
|
|
|
|
|
2020-04-25 23:55:52 +08:00
|
|
|
|
template <typename ResultType>
|
|
|
|
|
using task_handle = std::future<ResultType>;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 向全局任务池中增加任务
|
|
|
|
|
*/
|
|
|
|
|
template <typename FunctionType>
|
|
|
|
|
task_handle<typename std::result_of<FunctionType()>::type> addTask(FunctionType f) {
|
|
|
|
|
return getGlobalTaskGroup()->submit(f);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-15 00:19:38 +08:00
|
|
|
|
/**
|
|
|
|
|
* 程序退出时释放全局任务组实例,仅内部调用
|
2020-04-20 23:59:47 +08:00
|
|
|
|
*/
|
2021-01-15 00:19:38 +08:00
|
|
|
|
void releaseGlobalTaskGroup();
|
2020-04-20 23:59:47 +08:00
|
|
|
|
|
|
|
|
|
} /* namespace hku */
|
|
|
|
|
|
|
|
|
|
#endif /* HKU_GLOBAL_TASK_GROUP */
|