mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-31 22:05:10 +02:00
Remove undefined behavior in requestActionASAP
This commit is contained in:
parent
0fab319c73
commit
0661aa0e6e
@ -2705,24 +2705,13 @@ void VCAI::finish()
|
|||||||
|
|
||||||
void VCAI::requestActionASAP(std::function<void()> whatToDo)
|
void VCAI::requestActionASAP(std::function<void()> whatToDo)
|
||||||
{
|
{
|
||||||
boost::mutex mutex;
|
boost::thread newThread([this,whatToDo]()
|
||||||
mutex.lock();
|
|
||||||
|
|
||||||
boost::thread newThread([&mutex,this,whatToDo]()
|
|
||||||
{
|
{
|
||||||
setThreadName("VCAI::requestActionASAP::whatToDo");
|
setThreadName("VCAI::requestActionASAP::whatToDo");
|
||||||
SET_GLOBAL_STATE(this);
|
SET_GLOBAL_STATE(this);
|
||||||
boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
|
boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
|
||||||
// unlock mutex and allow parent function to exit
|
|
||||||
mutex.unlock();
|
|
||||||
whatToDo();
|
whatToDo();
|
||||||
});
|
});
|
||||||
|
|
||||||
// wait for mutex to unlock and for thread to initialize properly
|
|
||||||
mutex.lock();
|
|
||||||
|
|
||||||
// unlock mutex - boost dislikes destruction of locked mutexes
|
|
||||||
mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VCAI::lostHero(HeroPtr h)
|
void VCAI::lostHero(HeroPtr h)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user