Skip to content

Commit def0503

Browse files
authored
Merge pull request #460 from fasiondog/feature/coro
feat(thread): 添加协程执行器支持和完整的协程功能, 切换至c++20编译
2 parents 0b13c63 + 041b2f3 commit def0503

File tree

11 files changed

+1153
-7
lines changed

11 files changed

+1153
-7
lines changed

hikyuu_cpp/hikyuu/utilities/thread/GlobalMQStealThreadPool.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,19 @@ class HKU_UTILS_API GlobalMQStealThreadPool {
232232
m_done = true;
233233
}
234234

235+
struct ExecutorWrapper {
236+
GlobalMQStealThreadPool* pool;
237+
template <typename Function>
238+
void execute(Function f) {
239+
pool->submit(std::move(f));
240+
}
241+
};
242+
243+
/** 协程执行器 */
244+
ExecutorWrapper executor() {
245+
return ExecutorWrapper{this};
246+
}
247+
235248
private:
236249
typedef FuncWrapper task_type;
237250
std::atomic_bool m_done; // 线程池全局需终止指示

hikyuu_cpp/hikyuu/utilities/thread/GlobalMQThreadPool.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,19 @@ class HKU_UTILS_API GlobalMQThreadPool {
223223
m_done = true;
224224
}
225225

226+
struct ExecutorWrapper {
227+
GlobalMQThreadPool* pool;
228+
template <typename Function>
229+
void execute(Function f) {
230+
pool->submit(std::move(f));
231+
}
232+
};
233+
234+
/** 协程执行器 */
235+
ExecutorWrapper executor() {
236+
return ExecutorWrapper{this};
237+
}
238+
226239
private:
227240
typedef FuncWrapper task_type;
228241
std::atomic_bool m_done; // 线程池全局需终止指示

hikyuu_cpp/hikyuu/utilities/thread/GlobalStealThreadPool.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "ThreadSafeQueue.h"
1616
#include "WorkStealQueue.h"
1717
#include "InterruptFlag.h"
18+
#include "../Log.h"
1819
#include "../cppdef.h"
1920

2021
#ifdef __GNUC__
@@ -281,6 +282,19 @@ class HKU_UTILS_API GlobalStealThreadPool {
281282
m_threads.clear();
282283
}
283284

285+
struct ExecutorWrapper {
286+
GlobalStealThreadPool* pool;
287+
template <typename Function>
288+
void execute(Function f) {
289+
pool->submit(std::move(f));
290+
}
291+
};
292+
293+
/** 协程执行器 */
294+
ExecutorWrapper executor() {
295+
return ExecutorWrapper{this};
296+
}
297+
284298
public:
285299
bool run_available_task_once() {
286300
HKU_IF_RETURN(m_done.load(std::memory_order_acquire) || m_thread_need_stop.isSet(), false);

hikyuu_cpp/hikyuu/utilities/thread/GlobalThreadPool.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,19 @@ class HKU_UTILS_API GlobalThreadPool {
176176
m_master_work_queue.clear();
177177
}
178178

179+
struct ExecutorWrapper {
180+
GlobalThreadPool* pool;
181+
template <typename Function>
182+
void execute(Function f) {
183+
pool->submit(std::move(f));
184+
}
185+
};
186+
187+
/** 协程执行器 */
188+
ExecutorWrapper executor() {
189+
return ExecutorWrapper{this};
190+
}
191+
179192
private:
180193
typedef FuncWrapper task_type;
181194
std::atomic_bool m_done; // 线程池全局需终止指示

hikyuu_cpp/hikyuu/utilities/thread/MQStealThreadPool.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,19 @@ class HKU_UTILS_API MQStealThreadPool {
225225
}
226226
}
227227

228+
struct ExecutorWrapper {
229+
MQStealThreadPool* pool;
230+
template <typename Function>
231+
void execute(Function f) {
232+
pool->submit(std::move(f));
233+
}
234+
};
235+
236+
/** 协程执行器 */
237+
ExecutorWrapper executor() {
238+
return ExecutorWrapper{this};
239+
}
240+
228241
private:
229242
typedef FuncWrapper task_type;
230243
std::atomic_bool m_done; // 线程池全局需终止指示

hikyuu_cpp/hikyuu/utilities/thread/MQThreadPool.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,19 @@ class HKU_UTILS_API MQThreadPool {
206206
m_done = true;
207207
}
208208

209+
struct ExecutorWrapper {
210+
MQThreadPool *pool;
211+
template <typename Function>
212+
void execute(Function f) {
213+
pool->submit(std::move(f));
214+
}
215+
};
216+
217+
/** 协程执行器 */
218+
ExecutorWrapper executor() {
219+
return ExecutorWrapper{this};
220+
}
221+
209222
private:
210223
typedef FuncWrapper task_type;
211224
std::atomic_bool m_done; // 线程池全局需终止指示

hikyuu_cpp/hikyuu/utilities/thread/StealThreadPool.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,19 @@ class HKU_UTILS_API StealThreadPool {
228228
}
229229
}
230230

231+
struct ExecutorWrapper {
232+
StealThreadPool* pool;
233+
template <typename Function>
234+
void execute(Function f) {
235+
pool->submit(std::move(f));
236+
}
237+
};
238+
239+
/** 协程执行器 */
240+
ExecutorWrapper executor() {
241+
return ExecutorWrapper{this};
242+
}
243+
231244
private:
232245
typedef FuncWrapper task_type;
233246
std::atomic_bool m_done; // 线程池全局需终止指示

hikyuu_cpp/hikyuu/utilities/thread/ThreadPool.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ class ThreadPool {
170170
m_master_work_queue.clear();
171171
}
172172

173+
struct ExecutorWrapper {
174+
ThreadPool* pool;
175+
template <typename Function>
176+
void execute(Function f) {
177+
pool->submit(std::move(f));
178+
}
179+
};
180+
181+
/** 协程执行器 */
182+
ExecutorWrapper executor() {
183+
return ExecutorWrapper{this};
184+
}
185+
173186
private:
174187
typedef FuncWrapper task_type;
175188
std::atomic_bool m_done; // 线程池全局需终止指示

0 commit comments

Comments
 (0)