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