Axmol 3.0.0-89d6d9a
Loading...
Searching...
No Matches
JobSystem Class Reference

Thread-pool based background job system used by Axmol. More...

#include <JobSystem.h>

Public Member Functions

JobHandle enqueue (std::function< void()> jobFunc)
 Enqueue a regular background job.
JobHandle enqueue (std::function< void(JobThreadData *)> jobFunc)
 Enqueue a job that receives the worker thread's JobThreadData.
int getWorkerCount () const
 Get the number of worker threads owned by this JobSystem.

Detailed Description

Thread-pool based background job system used by Axmol.

JobSystem owns a small worker pool and executes submitted jobs off the Axmol thread when worker threads are available. If the platform or configuration creates the JobSystem with no workers, jobs run synchronously on the caller thread with a main-thread JobThreadData fallback.

The preferred entry point is enqueue(std::function<void()>). Use enqueue(std::function<void(JobThreadData*)>) only when a job needs per-worker context initialized by JobThreadData.

Note
JobSystem is intentionally a low-level background execution API. For the common "run work in the background, then continue on the Axmol thread" pattern, prefer Director::runAsync().
Warning
Jobs must not call rendering, scene graph, or other Axmol-thread-only APIs directly unless the specific API is documented as thread-safe.
Waiting for another JobSystem job from inside a worker can deadlock when all workers are occupied.

Member Function Documentation

◆ enqueue() [1/2]

JobHandle enqueue ( std::function< void()> jobFunc)

Enqueue a regular background job.

This is the default overload for fire-and-forget work. Keep the returned handle only when native code needs to observe completion, wait for the job, or request cooperative cancellation.

Parameters
jobFuncFunction executed by the JobSystem.
Returns
A handle that can be ignored, polled, waited, or used for cooperative cancellation.

◆ enqueue() [2/2]

JobHandle enqueue ( std::function< void(JobThreadData *)> jobFunc)

Enqueue a job that receives the worker thread's JobThreadData.

Use this overload for jobs that need per-worker context initialized by JobThreadData::init(), such as renderer, decoder, or platform resources that should be reused by a worker thread.

Parameters
jobFuncFunction executed by the JobSystem. In the synchronous fallback path, it receives the main-thread JobThreadData instance.
Returns
A handle that can be ignored, polled, waited, or used for cooperative cancellation.

◆ getWorkerCount()

int getWorkerCount ( ) const
inline

Get the number of worker threads owned by this JobSystem.

Returns
The number of background worker threads actually created. Returns 0 when the JobSystem is using the synchronous fallback path.

The documentation for this class was generated from the following file:
  • JobSystem.h