mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-06 23:26:26 +02:00
Fix freeze if AI initiates large number of async requests during turn
This commit is contained in:
parent
e273263334
commit
dff37ce81f
@ -593,12 +593,11 @@ void AIGateway::yourTurn(QueryID queryID)
|
|||||||
|
|
||||||
nullkiller->makingTurnInterrupption.reset();
|
nullkiller->makingTurnInterrupption.reset();
|
||||||
|
|
||||||
asyncTasks->run([this]()
|
executeActionAsyncArena.enqueue(asyncTasks->defer([this]()
|
||||||
{
|
{
|
||||||
ScopedThreadName guard("NKAI::makingTurn");
|
ScopedThreadName guard("NKAI::makingTurn");
|
||||||
makeTurn();
|
makeTurn();
|
||||||
});
|
}));
|
||||||
executeActionAsyncArena.enqueue([this](){asyncTasks->wait();});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AIGateway::heroGotLevel(const CGHeroInstance * hero, PrimarySkill pskill, std::vector<SecondarySkill> & skills, QueryID queryID)
|
void AIGateway::heroGotLevel(const CGHeroInstance * hero, PrimarySkill pskill, std::vector<SecondarySkill> & skills, QueryID queryID)
|
||||||
@ -1609,14 +1608,13 @@ void AIGateway::executeActionAsync(const std::string & description, const std::f
|
|||||||
if (!asyncTasks)
|
if (!asyncTasks)
|
||||||
throw std::runtime_error("Attempt to execute task on shut down AI state!");
|
throw std::runtime_error("Attempt to execute task on shut down AI state!");
|
||||||
|
|
||||||
asyncTasks->run([this, description, whatToDo]()
|
executeActionAsyncArena.enqueue(asyncTasks->defer([this, description, whatToDo]()
|
||||||
{
|
{
|
||||||
ScopedThreadName guard("NKAI::" + description);
|
ScopedThreadName guard("NKAI::" + description);
|
||||||
SET_GLOBAL_STATE(this);
|
SET_GLOBAL_STATE(this);
|
||||||
std::shared_lock gsLock(CGameState::mutex);
|
std::shared_lock gsLock(CGameState::mutex);
|
||||||
whatToDo();
|
whatToDo();
|
||||||
});
|
}));
|
||||||
executeActionAsyncArena.enqueue([this](){asyncTasks->wait();});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AIGateway::lostHero(HeroPtr h)
|
void AIGateway::lostHero(HeroPtr h)
|
||||||
|
@ -653,12 +653,11 @@ void VCAI::yourTurn(QueryID queryID)
|
|||||||
status.startedTurn();
|
status.startedTurn();
|
||||||
|
|
||||||
makingTurnInterrupption.reset();
|
makingTurnInterrupption.reset();
|
||||||
asyncTasks->run([this]()
|
executeActionAsyncArena.enqueue(asyncTasks->defer([this]()
|
||||||
{
|
{
|
||||||
ScopedThreadName guard("VCAI::makingTurn");
|
ScopedThreadName guard("VCAI::makingTurn");
|
||||||
makeTurn();
|
makeTurn();
|
||||||
});
|
}));
|
||||||
executeActionAsyncArena.enqueue([this](){asyncTasks->wait();});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VCAI::heroGotLevel(const CGHeroInstance * hero, PrimarySkill pskill, std::vector<SecondarySkill> & skills, QueryID queryID)
|
void VCAI::heroGotLevel(const CGHeroInstance * hero, PrimarySkill pskill, std::vector<SecondarySkill> & skills, QueryID queryID)
|
||||||
@ -2508,19 +2507,16 @@ void VCAI::finish()
|
|||||||
|
|
||||||
void VCAI::executeActionAsync(const std::string & description, const std::function<void()> & whatToDo)
|
void VCAI::executeActionAsync(const std::string & description, const std::function<void()> & whatToDo)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if (!asyncTasks)
|
if (!asyncTasks)
|
||||||
throw std::runtime_error("Attempt to execute task on shut down AI state!");
|
throw std::runtime_error("Attempt to execute task on shut down AI state!");
|
||||||
|
|
||||||
asyncTasks->run([this, description, whatToDo]()
|
executeActionAsyncArena.enqueue(asyncTasks->defer([this, description, whatToDo]()
|
||||||
{
|
{
|
||||||
ScopedThreadName guard("VCAI::" + description);
|
ScopedThreadName guard("VCAI::" + description);
|
||||||
SET_GLOBAL_STATE(this);
|
SET_GLOBAL_STATE(this);
|
||||||
std::shared_lock gsLock(CGameState::mutex);
|
std::shared_lock gsLock(CGameState::mutex);
|
||||||
whatToDo();
|
whatToDo();
|
||||||
});
|
}));
|
||||||
executeActionAsyncArena.enqueue([this](){asyncTasks->wait();});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VCAI::lostHero(HeroPtr h)
|
void VCAI::lostHero(HeroPtr h)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user