mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-20 20:23:03 +02:00
Made gamestate lock static
This commit is contained in:
parent
cf60aa61b0
commit
86f9df5f68
@ -746,7 +746,7 @@ void VCAI::makeTurn()
|
||||
logGlobal->info("Player %d (%s) starting turn", playerID, playerID.getStr());
|
||||
|
||||
MAKING_TURN;
|
||||
boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
|
||||
boost::shared_lock<boost::shared_mutex> gsLock(CGameState::mutex);
|
||||
setThreadName("VCAI::makeTurn");
|
||||
|
||||
switch(cb->getDate(Date::DAY_OF_WEEK))
|
||||
@ -1688,7 +1688,7 @@ void VCAI::battleEnd(const BattleResult *br)
|
||||
|
||||
void VCAI::waitTillFree()
|
||||
{
|
||||
auto unlock = vstd::makeUnlockSharedGuard(cb->getGsMutex());
|
||||
auto unlock = vstd::makeUnlockSharedGuard(CGameState::mutex);
|
||||
status.waitTillFree();
|
||||
}
|
||||
|
||||
@ -2787,7 +2787,7 @@ void VCAI::requestActionASAP(std::function<void()> whatToDo)
|
||||
{
|
||||
setThreadName("VCAI::requestActionASAP::whatToDo");
|
||||
SET_GLOBAL_STATE(this);
|
||||
boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
|
||||
boost::shared_lock<boost::shared_mutex> gsLock(CGameState::mutex);
|
||||
whatToDo();
|
||||
});
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ int CBattleCallback::sendRequest(const CPack *request)
|
||||
if(waitTillRealize)
|
||||
{
|
||||
logGlobal->traceStream() << boost::format("We'll wait till request %d is answered.\n") % requestID;
|
||||
auto gsUnlocker = vstd::makeUnlockSharedGuardIf(getGsMutex(), unlockGsWhenWaiting);
|
||||
auto gsUnlocker = vstd::makeUnlockSharedGuardIf(CGameState::mutex, unlockGsWhenWaiting);
|
||||
cl->waitingRequest.waitWhileContains(requestID);
|
||||
}
|
||||
|
||||
|
@ -1634,7 +1634,7 @@ void CPlayerInterface::setSelection(const CArmedInstance * obj)
|
||||
void CPlayerInterface::update()
|
||||
{
|
||||
// Make sure that gamestate won't change when GUI objects may obtain its parts on event processing or drawing request
|
||||
boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
|
||||
boost::shared_lock<boost::shared_mutex> gsLock(CGameState::mutex);
|
||||
|
||||
// While mutexes were locked away we may be have stopped being the active interface
|
||||
if (LOCPLINT != this)
|
||||
|
@ -100,11 +100,6 @@ namespace SiegeStuffThatShouldBeMovedToHandlers // <=== TODO
|
||||
|
||||
using namespace SiegeStuffThatShouldBeMovedToHandlers;
|
||||
|
||||
boost::shared_mutex& CCallbackBase::getGsMutex()
|
||||
{
|
||||
return *gs->mx;
|
||||
}
|
||||
|
||||
bool CCallbackBase::duringBattle() const
|
||||
{
|
||||
return getBattle() != nullptr;
|
||||
|
@ -62,7 +62,6 @@ protected:
|
||||
bool duringBattle() const;
|
||||
|
||||
public:
|
||||
boost::shared_mutex &getGsMutex(); //just return a reference to mutex, does not lock nor anything
|
||||
boost::optional<PlayerColor> getPlayerID() const;
|
||||
|
||||
friend class CBattleInfoEssentials;
|
||||
|
@ -45,6 +45,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
boost::shared_mutex CGameState::mutex;
|
||||
|
||||
template <typename T> class CApplyOnGS;
|
||||
|
||||
class CBaseForGSApply
|
||||
@ -65,7 +67,7 @@ public:
|
||||
{
|
||||
T *ptr = static_cast<T*>(pack);
|
||||
|
||||
boost::unique_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
boost::unique_lock<boost::shared_mutex> lock(CGameState::mutex);
|
||||
ptr->applyGs(gs);
|
||||
}
|
||||
};
|
||||
@ -675,7 +677,6 @@ int CGameState::getDate(Date::EDateType mode) const
|
||||
CGameState::CGameState()
|
||||
{
|
||||
gs = this;
|
||||
mx = new boost::shared_mutex();
|
||||
applierGs = new CApplier<CBaseForGSApply>;
|
||||
registerTypesClientPacks1(*applierGs);
|
||||
registerTypesClientPacks2(*applierGs);
|
||||
@ -687,7 +688,6 @@ CGameState::CGameState()
|
||||
|
||||
CGameState::~CGameState()
|
||||
{
|
||||
//delete mx;//TODO: crash on Linux (mutex must be unlocked before destruction)
|
||||
map.dellNull();
|
||||
curB.dellNull();
|
||||
//delete scenarioOps; //TODO: fix for loading ind delete
|
||||
|
@ -213,7 +213,7 @@ public:
|
||||
CBonusSystemNode globalEffects;
|
||||
RumorState rumor;
|
||||
|
||||
boost::shared_mutex *mx;
|
||||
static boost::shared_mutex mutex;
|
||||
|
||||
void giveHeroArtifact(CGHeroInstance *h, ArtifactID aid);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user