载入中...
搜索中...
未找到
Task.h
浏览该文件的文档.
1#pragma once
2
3#include <condition_variable>
4#include <functional>
5#include <memory>
6#include <mutex>
7#include <string>
8
9namespace eve {
10namespace thread {
11
16class Task {
17public:
18 explicit Task(std::function<void()> fn);
20
21 std::string getStatus() const;
22 bool isDone() const;
23 bool hasFailed() const;
24 std::string getError() const;
25
27 void wait();
28
29 // Internal — called by ThreadPool workers.
30 void run();
31
32private:
33 struct State {
34 explicit State(std::function<void()> taskFn) : fn(std::move(taskFn)) {}
35
36 std::function<void()> fn;
37 mutable std::mutex mu;
38 std::condition_variable cv;
39 std::string status = "pending";
40 std::string error;
41 };
42
43 explicit Task(std::shared_ptr<State> state);
44 static void run(const std::shared_ptr<State> &state);
45
46 std::shared_ptr<State> state_;
47
48 friend class ThreadPool;
49};
50
51} // namespace thread
52} // namespace eve
JobStatus status
std::string error
JobSystemThreadPool::State * state
SettlementPipeline::Stage fn
A job executed by a ThreadPool worker. Status strings (no enums): "pending" | "running" | "done" | "f...
Definition Task.h:16
bool hasFailed() const
Definition Task.cpp:28
void wait()
Block until the task finishes (done or failed).
Definition Task.cpp:38
std::string getError() const
Definition Task.cpp:33
bool isDone() const
Definition Task.cpp:23
std::string getStatus() const
Definition Task.cpp:18
Fixed-size worker pool. Owns worker std::threads; tasks run FIFO. Squirrel VM is not thread-safe — do...
Definition ThreadPool.h:24
Definition Build.cpp:11