diff options
author | Elias Fleckenstein <54945686+EliasFleckenstein03@users.noreply.github.com> | 2020-11-04 16:44:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-04 16:44:42 +0100 |
commit | 5d9ae5a91c544fc7fbd475decf47cef7e09ef8fc (patch) | |
tree | c980d614fec4a5495798be3e79e033229062c3cd /src/script/cpp_api/s_async.cpp | |
parent | 28f6a79706b088c37268a59d90878220dc4ef9c7 (diff) | |
parent | 3af10766fd2b58b068e970266724d7eb10e9316b (diff) | |
download | dragonfireclient-5d9ae5a91c544fc7fbd475decf47cef7e09ef8fc.tar.xz |
Merge branch 'master' into master
Diffstat (limited to 'src/script/cpp_api/s_async.cpp')
-rw-r--r-- | src/script/cpp_api/s_async.cpp | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/src/script/cpp_api/s_async.cpp b/src/script/cpp_api/s_async.cpp index 5f1f9297e..d0e520ae9 100644 --- a/src/script/cpp_api/s_async.cpp +++ b/src/script/cpp_api/s_async.cpp @@ -42,7 +42,6 @@ AsyncEngine::~AsyncEngine() workerThread->stop(); } - // Wake up all threads for (std::vector<AsyncWorkerThread *>::iterator it = workerThreads.begin(); it != workerThreads.end(); ++it) { @@ -77,16 +76,16 @@ void AsyncEngine::initialize(unsigned int numEngines) initDone = true; for (unsigned int i = 0; i < numEngines; i++) { - AsyncWorkerThread *toAdd = new AsyncWorkerThread(this, - std::string("AsyncWorker-") + itos(i)); + AsyncWorkerThread *toAdd = new AsyncWorkerThread( + this, std::string("AsyncWorker-") + itos(i)); workerThreads.push_back(toAdd); toAdd->start(); } } /******************************************************************************/ -unsigned int AsyncEngine::queueAsyncJob(const std::string &func, - const std::string ¶ms) +unsigned int AsyncEngine::queueAsyncJob( + const std::string &func, const std::string ¶ms) { jobQueueMutex.lock(); LuaJobInfo toAdd; @@ -158,7 +157,8 @@ void AsyncEngine::step(lua_State *L) } /******************************************************************************/ -void AsyncEngine::pushFinishedJobs(lua_State* L) { +void AsyncEngine::pushFinishedJobs(lua_State *L) +{ // Result Table MutexAutoLock l(resultQueueMutex); @@ -170,7 +170,7 @@ void AsyncEngine::pushFinishedJobs(lua_State* L) { LuaJobInfo jobDone = resultQueue.front(); resultQueue.pop_front(); - lua_createtable(L, 0, 2); // Pre-allocate space for two map fields + lua_createtable(L, 0, 2); // Pre-allocate space for two map fields int top_lvl2 = lua_gettop(L); lua_pushstring(L, "jobid"); @@ -179,7 +179,7 @@ void AsyncEngine::pushFinishedJobs(lua_State* L) { lua_pushstring(L, "retval"); lua_pushlstring(L, jobDone.serializedResult.data(), - jobDone.serializedResult.size()); + jobDone.serializedResult.size()); lua_settable(L, top_lvl2); lua_rawseti(L, top, index++); @@ -187,7 +187,7 @@ void AsyncEngine::pushFinishedJobs(lua_State* L) { } /******************************************************************************/ -void AsyncEngine::prepareEnvironment(lua_State* L, int top) +void AsyncEngine::prepareEnvironment(lua_State *L, int top) { for (StateInitializer &stateInitializer : stateInitializers) { stateInitializer(L, top); @@ -195,11 +195,10 @@ void AsyncEngine::prepareEnvironment(lua_State* L, int top) } /******************************************************************************/ -AsyncWorkerThread::AsyncWorkerThread(AsyncEngine* jobDispatcher, - const std::string &name) : - Thread(name), - ScriptApiBase(ScriptingType::Async), - jobDispatcher(jobDispatcher) +AsyncWorkerThread::AsyncWorkerThread( + AsyncEngine *jobDispatcher, const std::string &name) : + Thread(name), + ScriptApiBase(ScriptingType::Async), jobDispatcher(jobDispatcher) { lua_State *L = getStack(); @@ -221,7 +220,7 @@ AsyncWorkerThread::~AsyncWorkerThread() } /******************************************************************************/ -void* AsyncWorkerThread::run() +void *AsyncWorkerThread::run() { lua_State *L = getStack(); @@ -229,8 +228,8 @@ void* AsyncWorkerThread::run() try { loadScript(script); } catch (const ModError &e) { - errorstream << "Execution of async base environment failed: " - << e.what() << std::endl; + errorstream << "Execution of async base environment failed: " << e.what() + << std::endl; FATAL_ERROR("Execution of async base environment failed"); } @@ -258,11 +257,9 @@ void* AsyncWorkerThread::run() luaL_checktype(L, -1, LUA_TFUNCTION); // Call it - lua_pushlstring(L, - toProcess.serializedFunction.data(), + lua_pushlstring(L, toProcess.serializedFunction.data(), toProcess.serializedFunction.size()); - lua_pushlstring(L, - toProcess.serializedParams.data(), + lua_pushlstring(L, toProcess.serializedParams.data(), toProcess.serializedParams.size()); int result = lua_pcall(L, 2, 1, error_handler); @@ -276,14 +273,13 @@ void* AsyncWorkerThread::run() toProcess.serializedResult = std::string(retval, length); } - lua_pop(L, 1); // Pop retval + lua_pop(L, 1); // Pop retval // Put job result jobDispatcher->putJobResult(toProcess); } - lua_pop(L, 2); // Pop core and error handler + lua_pop(L, 2); // Pop core and error handler return 0; } - |