mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
Fix pthread_mutex_lock abort() in requestActionASAP impl
This commit is contained in:
@ -2660,19 +2660,13 @@ void VCAI::finish()
|
||||
|
||||
void VCAI::requestActionASAP(std::function<void()> whatToDo)
|
||||
{
|
||||
// static boost::mutex m;
|
||||
// boost::unique_lock<boost::mutex> mylock(m);
|
||||
|
||||
boost::barrier b(2);
|
||||
boost::thread newThread([&b,this,whatToDo]()
|
||||
boost::thread newThread([this, whatToDo]()
|
||||
{
|
||||
setThreadName("VCAI::requestActionASAP::helper");
|
||||
setThreadName("VCAI::requestActionASAP::whatToDo");
|
||||
SET_GLOBAL_STATE(this);
|
||||
boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
|
||||
b.wait();
|
||||
whatToDo();
|
||||
});
|
||||
b.wait();
|
||||
}
|
||||
|
||||
void VCAI::lostHero(HeroPtr h)
|
||||
@ -3405,4 +3399,3 @@ unsigned char & SectorMap::retreiveTile(crint3 pos)
|
||||
{
|
||||
return retreiveTileN(sector, pos);
|
||||
}
|
||||
|
||||
|
@ -5688,7 +5688,7 @@ bool CGameHandler::isValidObject(const CGObjectInstance *obj) const
|
||||
|
||||
bool CGameHandler::isBlockedByQueries(const CPack *pack, PlayerColor player)
|
||||
{
|
||||
if(dynamic_cast<const PlayerMessage*>(pack))
|
||||
if(!strcmp(typeid(*pack).name(), typeid(PlayerMessage).name()))
|
||||
return false;
|
||||
|
||||
auto query = queries.topQuery(player);
|
||||
@ -5826,7 +5826,7 @@ CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance *army, BattleI
|
||||
auto warMachine = VLC->arth->creatureToMachineID(st->type->idNumber);
|
||||
if (warMachine != ArtifactID::NONE)
|
||||
{
|
||||
auto hero = dynamic_cast<const CGHeroInstance*> (army);
|
||||
auto hero = dynamic_ptr_cast<CGHeroInstance> (army);
|
||||
if (hero)
|
||||
removedWarMachines.push_back (ArtifactLocation(hero, hero->getArtPos(warMachine, true)));
|
||||
}
|
||||
|
@ -86,8 +86,8 @@ void CPregameServer::handleConnection(CConnection *cpc)
|
||||
logNetwork->infoStream() << "Got package to announce " << typeid(*cpfs).name() << " from " << *cpc;
|
||||
|
||||
boost::unique_lock<boost::recursive_mutex> queueLock(mx);
|
||||
bool quitting = dynamic_cast<QuitMenuWithoutStarting*>(cpfs),
|
||||
startingGame = dynamic_cast<StartWithCurrentSettings*>(cpfs);
|
||||
bool quitting = dynamic_ptr_cast<QuitMenuWithoutStarting>(cpfs),
|
||||
startingGame = dynamic_ptr_cast<StartWithCurrentSettings>(cpfs);
|
||||
if(quitting || startingGame) //host leaves main menu or wants to start game -> we end
|
||||
{
|
||||
cpc->receivedStop = true;
|
||||
@ -258,11 +258,11 @@ void CPregameServer::sendPack(CConnection * pc, const CPackForSelectionScreen &
|
||||
*pc << &pack;
|
||||
}
|
||||
|
||||
if(dynamic_cast<const QuitMenuWithoutStarting*>(&pack))
|
||||
if(dynamic_ptr_cast<QuitMenuWithoutStarting>(&pack))
|
||||
{
|
||||
pc->sendStop = true;
|
||||
}
|
||||
else if(dynamic_cast<const StartWithCurrentSettings*>(&pack))
|
||||
else if(dynamic_ptr_cast<StartWithCurrentSettings>(&pack))
|
||||
{
|
||||
pc->sendStop = true;
|
||||
}
|
||||
@ -270,25 +270,25 @@ void CPregameServer::sendPack(CConnection * pc, const CPackForSelectionScreen &
|
||||
|
||||
void CPregameServer::processPack(CPackForSelectionScreen * pack)
|
||||
{
|
||||
if(dynamic_cast<CPregamePackToHost*>(pack))
|
||||
if(dynamic_ptr_cast<CPregamePackToHost>(pack))
|
||||
{
|
||||
sendPack(host, *pack);
|
||||
}
|
||||
else if(SelectMap *sm = dynamic_cast<SelectMap*>(pack))
|
||||
else if(SelectMap *sm = dynamic_ptr_cast<SelectMap>(pack))
|
||||
{
|
||||
vstd::clear_pointer(curmap);
|
||||
curmap = sm->mapInfo;
|
||||
sm->free = false;
|
||||
announcePack(*pack);
|
||||
}
|
||||
else if(UpdateStartOptions *uso = dynamic_cast<UpdateStartOptions*>(pack))
|
||||
else if(UpdateStartOptions *uso = dynamic_ptr_cast<UpdateStartOptions>(pack))
|
||||
{
|
||||
vstd::clear_pointer(curStartInfo);
|
||||
curStartInfo = uso->options;
|
||||
uso->free = false;
|
||||
announcePack(*pack);
|
||||
}
|
||||
else if(dynamic_cast<const StartWithCurrentSettings*>(pack))
|
||||
else if(dynamic_ptr_cast<StartWithCurrentSettings>(pack))
|
||||
{
|
||||
state = ENDING_AND_STARTING_GAME;
|
||||
announcePack(*pack);
|
||||
|
@ -209,7 +209,7 @@ bool SetFormation::applyGh( CGameHandler *gh )
|
||||
bool HireHero::applyGh( CGameHandler *gh )
|
||||
{
|
||||
const CGObjectInstance *obj = gh->getObj(tid);
|
||||
const CGTownInstance *town = dynamic_cast<const CGTownInstance *>(obj);
|
||||
const CGTownInstance *town = dynamic_ptr_cast<CGTownInstance>(obj);
|
||||
if(town && PlayerRelations::ENEMIES == gh->getPlayerRelations(obj->tempOwner, gh->getPlayerAt(c)))
|
||||
COMPLAIN_AND_RETURN("Can't buy hero in enemy town!");
|
||||
|
||||
|
@ -22,3 +22,17 @@ inline const T * dynamic_ptr_cast(const F * ptr)
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class T, class F>
|
||||
inline T * dynamic_ptr_cast(F * ptr)
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
return dynamic_cast<T*>(ptr);
|
||||
#else
|
||||
if (!strcmp(typeid(*ptr).name(), typeid(T).name()))
|
||||
{
|
||||
return static_cast<T*>(ptr);
|
||||
}
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user