Skip to content

Commit 46c0f94

Browse files
committed
feat(thread): 重构并重命名并行索引处理函数以支持任务组模板参数
1 parent 517da46 commit 46c0f94

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

hikyuu_cpp/hikyuu/utilities/thread/algorithm.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,28 +128,28 @@ auto parallel_for_range(size_t start, size_t end, FunctionType f, size_t cpu_num
128128
return ret;
129129
}
130130

131-
template <typename FunctionType>
132-
void parallel_for_index_void_steal(size_t start, size_t end, FunctionType f, int cpu_num = 0) {
131+
template <typename FunctionType, class TaskGroup = ThreadPool>
132+
void parallel_for_index_void_single(size_t start, size_t end, FunctionType f, int cpu_num = 0) {
133133
if (start >= end) {
134134
return;
135135
}
136136

137-
StealThreadPool tg(cpu_num == 0 ? std::thread::hardware_concurrency() : cpu_num);
137+
TaskGroup tg(cpu_num == 0 ? std::thread::hardware_concurrency() : cpu_num);
138138
for (size_t i = start; i < end; i++) {
139139
tg.submit([func = f, i]() { func(i); });
140140
}
141141
tg.join();
142142
return;
143143
}
144144

145-
template <typename FunctionType>
146-
auto parallel_for_index_steal(size_t start, size_t end, FunctionType f, size_t cpu_num = 0) {
145+
template <typename FunctionType, class TaskGroup = ThreadPool>
146+
auto parallel_for_index_single(size_t start, size_t end, FunctionType f, size_t cpu_num = 0) {
147147
std::vector<typename std::invoke_result<FunctionType, size_t>::type> ret;
148148
if (start >= end) {
149149
return ret;
150150
}
151151

152-
StealThreadPool tg(cpu_num == 0 ? std::thread::hardware_concurrency() : cpu_num);
152+
TaskGroup tg(cpu_num == 0 ? std::thread::hardware_concurrency() : cpu_num);
153153
std::vector<std::future<typename std::invoke_result<FunctionType, size_t>::type>> tasks;
154154
for (size_t i = start; i < end; i++) {
155155
tasks.emplace_back(tg.submit([func = f, i]() { return func(i); }));

0 commit comments

Comments
 (0)