#include <s_async.h>
|
| bool | getJob (LuaJobInfo *job) |
| | Get a Job from queue to be processed this function blocks until a job is ready.
|
| u32 | queueAsyncJob (LuaJobInfo &&job) |
| | Queue an async job.
|
| void | putJobResult (LuaJobInfo &&result) |
| | Put a Job result back to result queue.
|
| void | addWorkerThread () |
| | Start an additional worker thread.
|
| void | stepJobResults (lua_State *L) |
| | Process finished jobs callbacks.
|
| void | stepAutoscale () |
| | Handle automatic scaling of worker threads.
|
| void | stepStuckWarning () |
| | Print warning message if too many jobs are stuck.
|
| bool | prepareEnvironment (lua_State *L, int top) |
| | Initialize environment with current registred functions this function adds all functions registred by registerFunction to the passed lua stack.
|
◆ StateInitializer
| typedef void(* AsyncEngine::StateInitializer) (lua_State *L, int top) |
|
private |
◆ AsyncEngine() [1/2]
| AsyncEngine::AsyncEngine |
( |
| ) |
|
|
default |
◆ AsyncEngine() [2/2]
| AsyncEngine::AsyncEngine |
( |
Server * | server | ) |
|
|
inline |
◆ ~AsyncEngine()
| AsyncEngine::~AsyncEngine |
( |
| ) |
|
◆ addWorkerThread()
| void AsyncEngine::addWorkerThread |
( |
| ) |
|
|
protected |
◆ cancelAsyncJob()
| bool AsyncEngine::cancelAsyncJob |
( |
u32 | id | ) |
|
Try to cancel an async job.
- Parameters
-
- Returns
- Whether the job was cancelled
References jobQueue, and jobQueueMutex.
◆ compareJobs()
template<typename T>
| size_t AsyncEngine::compareJobs |
( |
const T & | from | ) |
|
|
inlineprivate |
◆ getJob()
Get a Job from queue to be processed this function blocks until a job is ready.
- Parameters
-
- Returns
- whether a job was available
References jobQueue, jobQueueCounter, and jobQueueMutex.
◆ getThreadingCapacity()
| unsigned int AsyncEngine::getThreadingCapacity |
( |
| ) |
const |
|
inline |
◆ initialize()
| void AsyncEngine::initialize |
( |
unsigned int | numEngines | ) |
|
◆ prepareEnvironment()
| bool AsyncEngine::prepareEnvironment |
( |
lua_State * | L, |
|
|
int | top ) |
|
protected |
◆ putJobResult()
| void AsyncEngine::putJobResult |
( |
LuaJobInfo && | result | ) |
|
|
protected |
◆ queueAsyncJob() [1/3]
| u32 AsyncEngine::queueAsyncJob |
( |
LuaJobInfo && | job | ) |
|
|
protected |
◆ queueAsyncJob() [2/3]
| u32 AsyncEngine::queueAsyncJob |
( |
std::string && | func, |
|
|
PackedValue * | params, |
|
|
const std::string & | mod_origin = "" ) |
Queue an async job.
- Parameters
-
| func | Serialized lua function |
| params | Serialized parameters (takes ownership!) |
- Returns
- ID of queued job
References queueAsyncJob().
◆ queueAsyncJob() [3/3]
| u32 AsyncEngine::queueAsyncJob |
( |
std::string && | func, |
|
|
std::string && | params, |
|
|
const std::string & | mod_origin = "" ) |
◆ registerStateInitializer()
◆ snapshotJobs()
template<typename T>
| void AsyncEngine::snapshotJobs |
( |
T & | to | ) |
|
|
inlineprivate |
◆ step()
| void AsyncEngine::step |
( |
lua_State * | L | ) |
|
◆ stepAutoscale()
| void AsyncEngine::stepAutoscale |
( |
| ) |
|
|
protected |
Handle automatic scaling of worker threads.
References addWorkerThread(), AUTOSCALE_DELAY_MS, autoscaleMaxWorkers, autoscaleSeenJobs, autoscaleTimer, compareJobs(), porting::getTimeMs(), infostream, jobQueue, jobQueueMutex, snapshotJobs(), and workerThreads.
Referenced by step().
◆ stepJobResults()
| void AsyncEngine::stepJobResults |
( |
lua_State * | L | ) |
|
|
protected |
Process finished jobs callbacks.
References FATAL_ERROR, ModApiBase::getScriptApiBase(), LuaJobInfo::id, LuaJobInfo::mod_origin, PUSH_ERROR_HANDLER, LuaJobInfo::result, LuaJobInfo::result_ext, resultQueue, resultQueueMutex, script_error(), script_unpack(), and ScriptApiBase::setOriginDirect().
Referenced by step().
◆ stepStuckWarning()
| void AsyncEngine::stepStuckWarning |
( |
| ) |
|
|
protected |
◆ AsyncWorkerThread
◆ autoscaleMaxWorkers
| unsigned int AsyncEngine::autoscaleMaxWorkers = 0 |
|
private |
◆ autoscaleSeenJobs
| std::unordered_set<u32> AsyncEngine::autoscaleSeenJobs |
|
private |
◆ autoscaleTimer
| u64 AsyncEngine::autoscaleTimer = 0 |
|
private |
◆ initDone
| bool AsyncEngine::initDone = false |
|
private |
◆ jobIdCounter
| u32 AsyncEngine::jobIdCounter = 0 |
|
private |
◆ jobQueue
◆ jobQueueCounter
◆ jobQueueMutex
| std::mutex AsyncEngine::jobQueueMutex |
|
private |
◆ resultQueue
◆ resultQueueMutex
| std::mutex AsyncEngine::resultQueueMutex |
|
private |
◆ server
| Server* AsyncEngine::server = nullptr |
|
private |
◆ stateInitializers
◆ stuckSeenJobs
| std::unordered_set<u32> AsyncEngine::stuckSeenJobs |
|
private |
◆ stuckTimer
| u64 AsyncEngine::stuckTimer = 0 |
|
private |
◆ workerThreads
The documentation for this class was generated from the following files: