Abstract job scheduler: dependencies, parallel_for, task_group, arena. 更多...
#include <JobSystem.h>
Public 成员函数 | |
| virtual | ~JobSystem ()=default |
| virtual int | getWorkerCount () const =0 |
| Number of scheduler worker threads. | |
| virtual bool | isRunning () const =0 |
| Whether the system is still accepting new jobs. | |
| virtual int | getPendingCount () const =0 |
| Number of ready jobs waiting for a worker (approximate). | |
| virtual int | getOutstandingCount () const =0 |
| Number of scheduled jobs that have not finished (approximate). | |
| virtual Job * | submit (JobFunc body)=0 |
| Create a job and schedule it immediately. | |
| virtual Job * | createJob (JobFunc body)=0 |
| Create a paused job (dependencies can be wired, then schedule()). | |
| virtual void | schedule (Job *job)=0 |
| Kick a paused job so it can run. | |
| virtual Job * | parallelFor (int first, int last, ParallelForBody body, int chunk=1)=0 |
| Run body over [first, last) in parallel. | |
| virtual TaskGroup * | createTaskGroup ()=0 |
| Create a fork/join task group. | |
| virtual Job * | submitFrame (JobFunc body)=0 |
| Create a frame-scoped job and schedule it immediately. | |
| virtual Job * | createFrameJob (JobFunc body)=0 |
| Create a paused frame-scoped job. | |
| virtual Job * | parallelForFrame (int first, int last, ParallelForBody body, int chunk=1)=0 |
| Frame-scoped parallel_for; see parallelFor(). | |
| virtual TaskGroup * | createFrameTaskGroup ()=0 |
| Create a fork/join task group whose children are frame-scoped. | |
| virtual void | beginFrame ()=0 |
| Start a new frame: join leftover frame jobs and recycle the arena. | |
| virtual void | endFrame ()=0 |
| End the frame: join outstanding frame jobs and recycle the arena. | |
| virtual void | waitAll ()=0 |
| Block until every scheduled job has finished. | |
| virtual void | stop ()=0 |
| Stop accepting work and join workers. Idempotent. | |
详细描述
Abstract job scheduler: dependencies, parallel_for, task_group, arena.
This is the stable engine-wide API for CPU job scheduling. The default backend (JobSystemThreadPool) schedules on top of the existing ThreadPool worker pool; a TBB backend only needs to implement this interface, and the factory in JobSystem.cpp is the single file that chooses the backend.
Two allocation scopes exist:
- Heap jobs (submit/createJob/parallelFor/createTaskGroup): caller-owned handles, deleted with
deleteonce finished. Long-lived work (async scene loading) belongs here. - Frame jobs (submitFrame/createFrameJob/parallelForFrame/ createFrameTaskGroup): allocated from a per-frame arena that is recycled by beginFrame()/endFrame(), so per-frame job submission does no new/delete. Handles are valid until the next beginFrame()/endFrame() and must not be deleted.
在文件 JobSystem.h 第 153 行定义.
构造及析构函数说明
◆ ~JobSystem()
|
virtualdefault |
成员函数说明
◆ beginFrame()
|
pure virtual |
Start a new frame: join leftover frame jobs and recycle the arena.
All frame-scoped handles from the previous frame become invalid. Call once per frame before submitting frame jobs.
在 eve::thread::JobSystemThreadPool 内被实现.
◆ createFrameJob()
Create a paused frame-scoped job.
- 参数
-
body Work to run on a worker.
- 返回
- Arena-allocated Job; do not delete, valid until next beginFrame().
在 eve::thread::JobSystemThreadPool 内被实现.
◆ createFrameTaskGroup()
|
pure virtual |
Create a fork/join task group whose children are frame-scoped.
- 返回
- Arena-allocated TaskGroup; do not delete, valid until next beginFrame().
在 eve::thread::JobSystemThreadPool 内被实现.
◆ createJob()
Create a paused job (dependencies can be wired, then schedule()).
- 参数
-
body Work to run on a worker; may be empty to create a pure join/dependency node that just gates downstream jobs.
- 返回
- Heap-allocated Job; delete once finished.
在 eve::thread::JobSystemThreadPool 内被实现.
◆ createTaskGroup()
|
pure virtual |
Create a fork/join task group.
- 返回
- Heap-allocated TaskGroup; delete once joined.
在 eve::thread::JobSystemThreadPool 内被实现.
◆ endFrame()
|
pure virtual |
End the frame: join outstanding frame jobs and recycle the arena.
Blocks until every frame-scoped job finished, so results are safe to consume (e.g. before swapping GPU buffers). Idempotent with beginFrame().
在 eve::thread::JobSystemThreadPool 内被实现.
◆ getOutstandingCount()
|
pure virtual |
Number of scheduled jobs that have not finished (approximate).
在 eve::thread::JobSystemThreadPool 内被实现.
◆ getPendingCount()
|
pure virtual |
Number of ready jobs waiting for a worker (approximate).
在 eve::thread::JobSystemThreadPool 内被实现.
◆ getWorkerCount()
|
pure virtual |
Number of scheduler worker threads.
在 eve::thread::JobSystemThreadPool 内被实现.
◆ isRunning()
|
pure virtual |
Whether the system is still accepting new jobs.
在 eve::thread::JobSystemThreadPool 内被实现.
◆ parallelFor()
|
pure virtual |
Run body over [first, last) in parallel.
The range is statically split into ceil((last-first)/chunk) child jobs; the returned job represents the whole loop and finishes when every child is done. chunk <= 0 picks an automatic chunk targeting ~4 tasks per worker.
- 参数
-
first First index (inclusive). last One past the last index (exclusive). body Called on a worker for each subrange [first, last). chunk Subrange size per child task (default 1).
- 返回
- Heap-allocated loop Job; wait() on it joins the loop.
在 eve::thread::JobSystemThreadPool 内被实现.
◆ parallelForFrame()
|
pure virtual |
Frame-scoped parallel_for; see parallelFor().
- 返回
- Arena-allocated loop Job; do not delete.
在 eve::thread::JobSystemThreadPool 内被实现.
◆ schedule()
|
pure virtual |
Kick a paused job so it can run.
A job with no pending dependencies becomes ready immediately; a job with dependencies runs when its last predecessor finishes. Throws when the system is stopped or the job was already scheduled.
- 参数
-
job Job previously returned by createJob()/createFrameJob().
在 eve::thread::JobSystemThreadPool 内被实现.
◆ stop()
|
pure virtual |
Stop accepting work and join workers. Idempotent.
- 异常
-
eve::Exception when called from one of this system's workers.
在 eve::thread::JobSystemThreadPool 内被实现.
◆ submit()
Create a job and schedule it immediately.
- 参数
-
body Work to run on a worker; may be empty to create a pure join/dependency node that just gates downstream jobs.
- 返回
- Heap-allocated Job; delete once finished.
在 eve::thread::JobSystemThreadPool 内被实现.
◆ submitFrame()
Create a frame-scoped job and schedule it immediately.
- 参数
-
body Work to run on a worker.
- 返回
- Arena-allocated Job; do not delete, valid until next beginFrame().
在 eve::thread::JobSystemThreadPool 内被实现.
◆ waitAll()
|
pure virtual |
Block until every scheduled job has finished.
- 异常
-
eve::Exception when called from one of this system's workers.
在 eve::thread::JobSystemThreadPool 内被实现.
该类的文档由以下文件生成:
- src/modules/thread/JobSystem.h