#include <s_async.h>
Public Member Functions | |
AsyncEngine ()=default | |
~AsyncEngine () | |
void | registerStateInitializer (StateInitializer func) |
Register function to be called on new states. More... | |
void | initialize (unsigned int numEngines) |
Create async engine tasks and lock function registration. More... | |
unsigned int | queueAsyncJob (const std::string &func, const std::string ¶ms) |
Queue an async job. More... | |
void | step (lua_State *L) |
Engine step to process finished jobs the engine step is one way to pass events back, PushFinishedJobs another. More... | |
Protected Member Functions | |
LuaJobInfo | getJob () |
Get a Job from queue to be processed this function blocks until a job is ready. More... | |
void | putJobResult (const LuaJobInfo &result) |
Put a Job result back to result queue. More... | |
void | 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. More... | |
Private Types | |
typedef void(* | StateInitializer) (lua_State *L, int top) |
Private Attributes | |
bool | initDone = false |
std::vector< StateInitializer > | stateInitializers |
unsigned int | jobIdCounter = 0 |
std::mutex | jobQueueMutex |
std::deque< LuaJobInfo > | jobQueue |
std::mutex | resultQueueMutex |
std::deque< LuaJobInfo > | resultQueue |
std::vector< AsyncWorkerThread * > | workerThreads |
Semaphore | jobQueueCounter |
Friends | |
class | AsyncWorkerThread |
|
private |
|
default |
AsyncEngine::~AsyncEngine | ( | ) |
References jobQueue, jobQueueCounter, jobQueueMutex, Semaphore::post(), and workerThreads.
|
protected |
Get a Job from queue to be processed this function blocks until a job is ready.
References jobQueue, jobQueueCounter, jobQueueMutex, LuaJobInfo::valid, and Semaphore::wait().
Referenced by AsyncWorkerThread::run().
void AsyncEngine::initialize | ( | unsigned int | numEngines | ) |
Create async engine tasks and lock function registration.
numEngines | Number of async threads to be started |
References AsyncWorkerThread, initDone, itos(), Thread::start(), and workerThreads.
Referenced by MainMenuScripting::initializeModApi().
|
protected |
Initialize environment with current registred functions this function adds all functions registred by registerFunction to the passed lua stack.
L | Lua stack to initialize |
top | Stack position |
References stateInitializers.
Referenced by AsyncWorkerThread::AsyncWorkerThread().
|
protected |
Put a Job result back to result queue.
result | result of completed job |
References resultQueue, and resultQueueMutex.
Referenced by AsyncWorkerThread::run().
unsigned int AsyncEngine::queueAsyncJob | ( | const std::string & | func, |
const std::string & | params | ||
) |
Queue an async job.
func | Serialized lua function |
params | Serialized parameters |
References LuaJobInfo::id, jobIdCounter, jobQueue, jobQueueCounter, jobQueueMutex, params, Semaphore::post(), LuaJobInfo::serializedFunction, and LuaJobInfo::serializedParams.
Referenced by MainMenuScripting::queueAsync().
void AsyncEngine::registerStateInitializer | ( | StateInitializer | func | ) |
Register function to be called on new states.
func | C function to be called |
References stateInitializers.
Referenced by MainMenuScripting::initializeModApi().
void AsyncEngine::step | ( | lua_State * | L | ) |
Engine step to process finished jobs the engine step is one way to pass events back, PushFinishedJobs another.
L | The Lua stack |
References FATAL_ERROR, LuaJobInfo::id, PCALL_RESL, PUSH_ERROR_HANDLER, resultQueue, resultQueueMutex, and LuaJobInfo::serializedResult.
Referenced by MainMenuScripting::step().
|
friend |
Referenced by initialize().
|
private |
Referenced by initialize().
|
private |
Referenced by queueAsyncJob().
|
private |
Referenced by ~AsyncEngine(), getJob(), and queueAsyncJob().
|
private |
Referenced by ~AsyncEngine(), getJob(), and queueAsyncJob().
|
private |
Referenced by ~AsyncEngine(), getJob(), and queueAsyncJob().
|
private |
Referenced by putJobResult(), and step().
|
private |
Referenced by putJobResult(), and step().
|
private |
Referenced by prepareEnvironment(), and registerStateInitializer().
|
private |
Referenced by ~AsyncEngine(), and initialize().