载入中...
搜索中...
未找到
JobSystemThreadPool.h
浏览该文件的文档.
1#pragma once
2
3#include "thread/JobSystem.h"
4#include "thread/Task.h"
5
6#include <memory>
7#include <mutex>
8#include <vector>
9
10namespace eve {
11namespace thread {
12
13class ThreadPool;
14
24class JobSystemThreadPool final : public JobSystem {
25public:
27 struct State;
28
30 explicit JobSystemThreadPool(int workerCount);
32 ~JobSystemThreadPool() override;
33
36
38 int getWorkerCount() const override;
40 bool isRunning() const override;
42 int getPendingCount() const override;
44 int getOutstandingCount() const override;
45
47 Job *submit(JobFunc body) override;
49 Job *createJob(JobFunc body) override;
51 void schedule(Job *job) override;
53 Job *parallelFor(int first, int last, ParallelForBody body, int chunk = 1) override;
55 TaskGroup *createTaskGroup() override;
56
58 Job *submitFrame(JobFunc body) override;
60 Job *createFrameJob(JobFunc body) override;
62 Job *parallelForFrame(int first, int last, ParallelForBody body, int chunk = 1) override;
66 void beginFrame() override;
68 void endFrame() override;
69
71 void waitAll() override;
73 void stop() override;
74
75private:
76 Job *parallelForImpl(int first, int last, ParallelForBody body, int chunk, bool frameScope);
77
78 std::shared_ptr<State> state_;
79 std::unique_ptr<ThreadPool> pool_;
80 std::vector<Task *> poolTasks_;
81 std::mutex lifecycleMu_;
82};
83
84} // namespace thread
85} // namespace eve
std::int32_t first
std::vector< ecs::EntityHandle > schedule
The round's activation queue, resolved against the target battle.
std::string body
Default JobSystem backend: a dependency-aware scheduler over the existing ThreadPool worker pool.
Job * createJob(JobFunc body) override
Creates job.
void endFrame() override
Ends frame.
Job * submitFrame(JobFunc body) override
Submit frame.
Job * parallelFor(int first, int last, ParallelForBody body, int chunk=1) override
Parallel for.
JobSystemThreadPool & operator=(const JobSystemThreadPool &)=delete
Job * parallelForFrame(int first, int last, ParallelForBody body, int chunk=1) override
Parallel for frame.
JobSystemThreadPool(const JobSystemThreadPool &)=delete
TaskGroup * createTaskGroup() override
Creates task group.
int getPendingCount() const override
Returns the pending count.
int getOutstandingCount() const override
Returns the outstanding count.
int getWorkerCount() const override
Returns the worker count.
Job * submit(JobFunc body) override
Submit.
TaskGroup * createFrameTaskGroup() override
Creates frame task group.
bool isRunning() const override
True when running.
~JobSystemThreadPool() override
Releases JobSystemThreadPool resources.
Job * createFrameJob(JobFunc body) override
Creates frame job.
void beginFrame() override
Begins frame.
Abstract job scheduler: dependencies, parallel_for, task_group, arena.
Definition JobSystem.h:157
Handle to a single job inside a JobSystem.
Definition JobSystem.h:43
Fork/join group: fork() spawns scheduled children, wait() joins them.
Definition JobSystem.h:109
std::function< void(int first, int last)> ParallelForBody
Body of a parallel_for subrange.
Definition JobSystem.h:24
std::function< void()> JobFunc
A unit of work executed by a JobSystem worker.
Definition JobSystem.h:17
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16