mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
Quick shutdown of ConsoleHandler thread
This commit is contained in:
@@ -251,8 +251,9 @@ int CConsoleHandler::run()
|
|||||||
if ( cb )
|
if ( cb )
|
||||||
cb(buffer, false);
|
cb(buffer, false);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::unique_lock guard(shutdownMutex);
|
||||||
|
shutdownVariable.wait_for(guard, std::chrono::seconds(1));
|
||||||
|
|
||||||
if (shutdownPending)
|
if (shutdownPending)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -308,6 +309,7 @@ void CConsoleHandler::end()
|
|||||||
{
|
{
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
shutdownPending = true;
|
shutdownPending = true;
|
||||||
|
shutdownVariable.notify_all();
|
||||||
#else
|
#else
|
||||||
TerminateThread(thread.native_handle(),0);
|
TerminateThread(thread.native_handle(),0);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -94,6 +94,8 @@ private:
|
|||||||
//function to be called when message is received - string: message, bool: whether call was made from in-game console
|
//function to be called when message is received - string: message, bool: whether call was made from in-game console
|
||||||
std::function<void(const std::string &, bool)> cb;
|
std::function<void(const std::string &, bool)> cb;
|
||||||
|
|
||||||
|
std::condition_variable shutdownVariable;
|
||||||
|
std::mutex shutdownMutex;
|
||||||
std::atomic<bool> shutdownPending = false;
|
std::atomic<bool> shutdownPending = false;
|
||||||
|
|
||||||
std::mutex smx;
|
std::mutex smx;
|
||||||
|
|||||||
Reference in New Issue
Block a user