mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-10 22:31:40 +02:00
shared_mutex replace boost
This commit is contained in:
@@ -93,7 +93,7 @@ private:
|
||||
const HeroActor * actor;
|
||||
std::map<const ChainActor *, HeroActor *> exchangeMap;
|
||||
const Nullkiller * ai;
|
||||
boost::shared_mutex sync;
|
||||
std::shared_mutex sync;
|
||||
|
||||
public:
|
||||
HeroExchangeMap(const HeroActor * actor, const Nullkiller * ai);
|
||||
|
@@ -36,7 +36,7 @@ public:
|
||||
|
||||
std::unique_ptr<EventSubscription> subscribeBefore(BusTag tag, PreHandler && handler)
|
||||
{
|
||||
std::unique_lock<boost::shared_mutex> lock(mutex);
|
||||
std::unique_lock<std::shared_mutex> lock(mutex);
|
||||
|
||||
auto storage = std::make_shared<PreHandlerStorage>(std::move(handler));
|
||||
preHandlers[tag].push_back(storage);
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
|
||||
std::unique_ptr<EventSubscription> subscribeAfter(BusTag tag, PostHandler && handler)
|
||||
{
|
||||
std::unique_lock<boost::shared_mutex> lock(mutex);
|
||||
std::unique_lock<std::shared_mutex> lock(mutex);
|
||||
|
||||
auto storage = std::make_shared<PostHandlerStorage>(std::move(handler));
|
||||
postHandlers[tag].push_back(storage);
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
|
||||
void executeEvent(const EventBus * bus, E & event, const ExecHandler & execHandler)
|
||||
{
|
||||
std::shared_lock<boost::shared_mutex> lock(mutex);
|
||||
std::shared_lock<std::shared_mutex> lock(mutex);
|
||||
{
|
||||
auto it = preHandlers.find(bus);
|
||||
|
||||
@@ -141,7 +141,7 @@ private:
|
||||
std::shared_ptr<PostHandlerStorage> handler;
|
||||
};
|
||||
|
||||
boost::shared_mutex mutex;
|
||||
std::shared_mutex mutex;
|
||||
|
||||
std::map<BusTag, std::vector<std::shared_ptr<PreHandlerStorage>>> preHandlers;
|
||||
std::map<BusTag, std::vector<std::shared_ptr<PostHandlerStorage>>> postHandlers;
|
||||
@@ -149,7 +149,7 @@ private:
|
||||
template <typename T>
|
||||
void unsubscribe(BusTag tag, T what, std::map<BusTag, std::vector<T>> & from)
|
||||
{
|
||||
std::unique_lock<boost::shared_mutex> lock(mutex);
|
||||
std::unique_lock<std::shared_mutex> lock(mutex);
|
||||
|
||||
auto it = from.find(tag);
|
||||
|
||||
|
@@ -185,7 +185,7 @@ const IMarket * CGameInfoCallback::getMarket(ObjectInstanceID objid) const
|
||||
|
||||
void CGameInfoCallback::fillUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo & out) const
|
||||
{
|
||||
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
||||
ERROR_RET_IF(!canGetFullInfo(obj), "Cannot get info about not owned object!");
|
||||
ERROR_RET_IF(!obj->hasStackAtSlot(stackPos), "There is no such stack!");
|
||||
gs->fillUpgradeInfo(obj, stackPos, out);
|
||||
@@ -194,7 +194,7 @@ void CGameInfoCallback::fillUpgradeInfo(const CArmedInstance *obj, SlotID stackP
|
||||
|
||||
const StartInfo * CGameInfoCallback::getStartInfo(bool beforeRandomization) const
|
||||
{
|
||||
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
||||
if(beforeRandomization)
|
||||
return gs->initialOpts;
|
||||
else
|
||||
@@ -203,7 +203,7 @@ const StartInfo * CGameInfoCallback::getStartInfo(bool beforeRandomization) cons
|
||||
|
||||
int32_t CGameInfoCallback::getSpellCost(const spells::Spell * sp, const CGHeroInstance * caster) const
|
||||
{
|
||||
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
||||
ERROR_RET_VAL_IF(!canGetFullInfo(caster), "Cannot get info about caster!", -1);
|
||||
//if there is a battle
|
||||
auto casterBattle = gs->getBattle(caster->getOwner());
|
||||
@@ -217,7 +217,7 @@ int32_t CGameInfoCallback::getSpellCost(const spells::Spell * sp, const CGHeroIn
|
||||
|
||||
int64_t CGameInfoCallback::estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const
|
||||
{
|
||||
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
||||
|
||||
ERROR_RET_VAL_IF(hero && !canGetFullInfo(hero), "Cannot get info about caster!", -1);
|
||||
|
||||
@@ -229,7 +229,7 @@ int64_t CGameInfoCallback::estimateSpellDamage(const CSpell * sp, const CGHeroIn
|
||||
|
||||
void CGameInfoCallback::getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj)
|
||||
{
|
||||
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
||||
ERROR_RET_IF(!obj, "No guild object!");
|
||||
ERROR_RET_IF(obj->ID == Obj::TOWN && !canGetFullInfo(obj), "Cannot get info about town guild object!");
|
||||
//TODO: advmap object -> check if they're visited by our hero
|
||||
@@ -419,13 +419,13 @@ bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero
|
||||
|
||||
int CGameInfoCallback::getDate(Date mode) const
|
||||
{
|
||||
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
||||
return gs->getDate(mode);
|
||||
}
|
||||
|
||||
bool CGameInfoCallback::isVisible(int3 pos, const std::optional<PlayerColor> & Player) const
|
||||
{
|
||||
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
||||
return gs->isVisible(pos, Player);
|
||||
}
|
||||
|
||||
@@ -445,7 +445,7 @@ bool CGameInfoCallback::isVisible(const CGObjectInstance *obj) const
|
||||
}
|
||||
// const CCreatureSet* CInfoCallback::getGarrison(const CGObjectInstance *obj) const
|
||||
// {
|
||||
// //std::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
// //std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
||||
// if()
|
||||
// const CArmedInstance *armi = dynamic_cast<const CArmedInstance*>(obj);
|
||||
// if(!armi)
|
||||
@@ -754,14 +754,14 @@ CGameInfoCallback::CGameInfoCallback(CGameState * GS):
|
||||
|
||||
int CPlayerSpecificInfoCallback::howManyTowns() const
|
||||
{
|
||||
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
||||
ERROR_RET_VAL_IF(!getPlayerID(), "Applicable only for player callbacks", -1);
|
||||
return CGameInfoCallback::howManyTowns(*getPlayerID());
|
||||
}
|
||||
|
||||
std::vector < const CGTownInstance *> CPlayerSpecificInfoCallback::getTownsInfo(bool onlyOur) const
|
||||
{
|
||||
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
||||
auto ret = std::vector < const CGTownInstance *>();
|
||||
for(const auto & i : gs->players)
|
||||
{
|
||||
@@ -777,7 +777,7 @@ std::vector < const CGTownInstance *> CPlayerSpecificInfoCallback::getTownsInfo(
|
||||
}
|
||||
std::vector < const CGHeroInstance *> CPlayerSpecificInfoCallback::getHeroesInfo(bool onlyOur) const
|
||||
{
|
||||
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
||||
std::vector < const CGHeroInstance *> ret;
|
||||
for(auto hero : gs->map->heroesOnMap)
|
||||
{
|
||||
@@ -840,7 +840,7 @@ std::vector <QuestInfo> CPlayerSpecificInfoCallback::getMyQuests() const
|
||||
|
||||
int CPlayerSpecificInfoCallback::howManyHeroes(bool includeGarrisoned) const
|
||||
{
|
||||
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
||||
ERROR_RET_VAL_IF(!getPlayerID(), "Applicable only for player callbacks", -1);
|
||||
return getHeroCount(*getPlayerID(), includeGarrisoned);
|
||||
}
|
||||
@@ -872,14 +872,14 @@ const CGTownInstance* CPlayerSpecificInfoCallback::getTownBySerial(int serialId)
|
||||
|
||||
int CPlayerSpecificInfoCallback::getResourceAmount(GameResID type) const
|
||||
{
|
||||
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
||||
ERROR_RET_VAL_IF(!getPlayerID(), "Applicable only for player callbacks", -1);
|
||||
return getResource(*getPlayerID(), type);
|
||||
}
|
||||
|
||||
TResources CPlayerSpecificInfoCallback::getResourceAmount() const
|
||||
{
|
||||
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
||||
ERROR_RET_VAL_IF(!getPlayerID(), "Applicable only for player callbacks", TResources());
|
||||
return gs->players[*getPlayerID()].resources;
|
||||
}
|
||||
|
@@ -114,7 +114,7 @@ namespace vstd
|
||||
: unlock_guard<Mutex, detail::unlock_shared_policy<Mutex> >();
|
||||
}
|
||||
|
||||
using unlock_shared_guard = unlock_guard<boost::shared_mutex, detail::unlock_shared_policy<boost::shared_mutex>>;
|
||||
using unlock_shared_guard = unlock_guard<std::shared_mutex, detail::unlock_shared_policy<std::shared_mutex>>;
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@@ -58,7 +58,7 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
boost::shared_mutex CGameState::mutex;
|
||||
std::shared_mutex CGameState::mutex;
|
||||
|
||||
HeroTypeID CGameState::pickNextHeroType(const PlayerColor & owner)
|
||||
{
|
||||
|
@@ -82,7 +82,7 @@ public:
|
||||
|
||||
StatisticDataSet statistic;
|
||||
|
||||
static boost::shared_mutex mutex;
|
||||
static std::shared_mutex mutex;
|
||||
|
||||
void updateEntity(Metatype metatype, int32_t index, const JsonNode & data) override;
|
||||
|
||||
|
@@ -64,7 +64,7 @@ protected:
|
||||
|
||||
mutable std::recursive_mutex externalAccessMutex; //Used to communicate between Modificators
|
||||
using RecursiveLock = std::unique_lock<std::recursive_mutex>;
|
||||
using Lock = std::unique_lock<boost::shared_mutex>;
|
||||
using Lock = std::unique_lock<std::shared_mutex>;
|
||||
|
||||
private:
|
||||
virtual void process() = 0;
|
||||
@@ -73,7 +73,7 @@ private:
|
||||
|
||||
std::list<Modificator*> preceeders; //must be ordered container
|
||||
|
||||
mutable boost::shared_mutex mx; //Used only for task scheduling
|
||||
mutable std::shared_mutex mx; //Used only for task scheduling
|
||||
|
||||
void dump();
|
||||
};
|
||||
|
@@ -19,8 +19,8 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
template <typename T>
|
||||
class DLL_LINKAGE BlockingQueue : protected std::queue<T>
|
||||
{
|
||||
using WriteLock = std::unique_lock<boost::shared_mutex>;
|
||||
using Readlock = std::shared_lock<boost::shared_mutex>;
|
||||
using WriteLock = std::unique_lock<std::shared_mutex>;
|
||||
using Readlock = std::shared_lock<std::shared_mutex>;
|
||||
|
||||
public:
|
||||
BlockingQueue() = default;
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
mutable boost::shared_mutex mx;
|
||||
mutable std::shared_mutex mx;
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
@@ -33,8 +33,8 @@ public:
|
||||
void drawRoads(vstd::RNG & generator, std::vector<int3> & tiles, RoadId roadType);
|
||||
|
||||
private:
|
||||
mutable boost::shared_mutex mx;
|
||||
using Lock = std::unique_lock<boost::shared_mutex>;
|
||||
mutable std::shared_mutex mx;
|
||||
using Lock = std::unique_lock<std::shared_mutex>;
|
||||
|
||||
RmgMap & map;
|
||||
};
|
||||
|
@@ -24,8 +24,8 @@ typedef std::optional<TRMGfunction> TRMGJob;
|
||||
class DLL_LINKAGE ThreadPool
|
||||
{
|
||||
private:
|
||||
using Lock = std::unique_lock<boost::shared_mutex>;
|
||||
mutable boost::shared_mutex mx;
|
||||
using Lock = std::unique_lock<std::shared_mutex>;
|
||||
mutable std::shared_mutex mx;
|
||||
mutable std::condition_variable_any cv;
|
||||
mutable boost::once_flag once;
|
||||
|
||||
|
Reference in New Issue
Block a user