aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2013-11-30 01:51:54 +0100
committersapier <Sapier at GMX dot net>2013-11-30 02:15:31 +0100
commitd19a69cd0d22dfbe802286baf8b33ebb8c6f4fa2 (patch)
tree813d0cf5a003d6b9e7966c20878a2b131299564d /src/script
parentd02ce1cf4d5d283cc6045771612e5b351740e07e (diff)
downloadminetest-d19a69cd0d22dfbe802286baf8b33ebb8c6f4fa2.tar.gz
minetest-d19a69cd0d22dfbe802286baf8b33ebb8c6f4fa2.tar.bz2
minetest-d19a69cd0d22dfbe802286baf8b33ebb8c6f4fa2.zip
Fix broken thread stop handling
Diffstat (limited to 'src/script')
-rw-r--r--src/script/lua_api/l_async_events.cpp11
-rw-r--r--src/script/lua_api/l_async_events.h2
2 files changed, 9 insertions, 4 deletions
diff --git a/src/script/lua_api/l_async_events.cpp b/src/script/lua_api/l_async_events.cpp
index cc4644cdf..63ca87aed 100644
--- a/src/script/lua_api/l_async_events.cpp
+++ b/src/script/lua_api/l_async_events.cpp
@@ -149,9 +149,11 @@ LuaJobInfo AsyncEngine::getJob() {
m_JobQueueMutex.Lock();
LuaJobInfo retval;
+ retval.valid = false;
if (m_JobQueue.size() != 0) {
retval = m_JobQueue.front();
+ retval.valid = true;
m_JobQueue.erase((m_JobQueue.begin()));
}
m_JobQueueMutex.Unlock();
@@ -322,11 +324,12 @@ void* AsyncWorkerThread::worker_thread_main() {
assert("no future with broken builtin async environment scripts" == 0);
}
/** main loop **/
- while(IsRunning()) {
+ while(!StopRequested()) {
//wait for job
LuaJobInfo toprocess = m_JobDispatcher->getJob();
- if (!IsRunning()) { continue; }
+ if (toprocess.valid == false) { continue; }
+ if (StopRequested()) { continue; }
//first push error handler
lua_pushcfunction(m_LuaStack, script_error_handler);
@@ -350,7 +353,7 @@ void* AsyncWorkerThread::worker_thread_main() {
toprocess.serializedParams.c_str(),
toprocess.serializedParams.length());
- if (!IsRunning()) { continue; }
+ if (StopRequested()) { continue; }
if(lua_pcall(m_LuaStack, 2, 2, errorhandler)) {
scriptError("Async WORKER thread: %s\n", lua_tostring(m_LuaStack, -1));
toprocess.serializedResult="ERROR";
@@ -362,7 +365,7 @@ void* AsyncWorkerThread::worker_thread_main() {
toprocess.serializedResult = std::string(retval,lenght);
}
- if (!IsRunning()) { continue; }
+ if (StopRequested()) { continue; }
//put job result
m_JobDispatcher->putJobResult(toprocess);
}
diff --git a/src/script/lua_api/l_async_events.h b/src/script/lua_api/l_async_events.h
index 347d9c0fc..079a08009 100644
--- a/src/script/lua_api/l_async_events.h
+++ b/src/script/lua_api/l_async_events.h
@@ -57,6 +57,8 @@ struct LuaJobInfo {
std::string serializedResult;
/** jobid used to identify a job and match it to callback **/
unsigned int JobId;
+ /** valid marker **/
+ bool valid;
};
/** class encapsulating a asynchronous working environment **/