载入中...
搜索中...
未找到
ThreadPool.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "thread/Task.h"
6
7#include <condition_variable>
8#include <cstddef>
9#include <functional>
10#include <memory>
11#include <mutex>
12#include <queue>
13#include <string>
14#include <thread>
15#include <vector>
16
17namespace eve {
18namespace thread {
19
20class Channel;
21
27public:
29 explicit ThreadPool(int workerCount);
32
33 ThreadPool(const ThreadPool &) = delete;
34 ThreadPool &operator=(const ThreadPool &) = delete;
35
37 int getWorkerCount() const;
39 int getPendingCount() const;
41 bool isRunning() const;
42
44 Task *submit(std::function<void()> fn);
45
47 Task *submitSleep(int ms);
48
50 Task *submitPush(Channel *channel, std::string message, int delayMs = 0);
51
56 Task *submitPost(std::string name, std::string data = "", int delayMs = 0);
57
59 void waitAll();
60
62 void stop();
63
64private:
65 struct State;
66
67 static void workerMain(std::shared_ptr<State> state);
68 void stopImpl(bool allowWorkerCaller);
69
70 int workerCount_ = 0;
71 std::vector<std::thread> workers_;
72 std::shared_ptr<State> state_;
73 std::mutex lifecycleMu_;
74};
75
76} // namespace thread
77} // namespace eve
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
std::string message
std::string name
Thread-safe message queue (love2d-style Channel). Values are strings so the API stays overload-free f...
Definition Channel.h:19
A job executed by a ThreadPool worker. Status strings (no enums): "pending" | "running" | "done" | "f...
Definition Task.h:18
Fixed-size worker pool. Owns worker std::threads; tasks run FIFO. Squirrel VM is not thread-safe — do...
Definition ThreadPool.h:26
ThreadPool(const ThreadPool &)=delete
ThreadPool & operator=(const ThreadPool &)=delete
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
SettlementPipeline::Stage fn