Skip to content

Commit 4e73f7d

Browse files
committed
shared_mutex replace boost
1 parent 41a4ea1 commit 4e73f7d

File tree

10 files changed

+32
-32
lines changed

10 files changed

+32
-32
lines changed

AI/Nullkiller/Pathfinding/Actors.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class HeroExchangeMap
9393
const HeroActor * actor;
9494
std::map<const ChainActor *, HeroActor *> exchangeMap;
9595
const Nullkiller * ai;
96-
boost::shared_mutex sync;
96+
std::shared_mutex sync;
9797

9898
public:
9999
HeroExchangeMap(const HeroActor * actor, const Nullkiller * ai);

include/vcmi/events/SubscriptionRegistry.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SubscriptionRegistry : public boost::noncopyable
3636

3737
std::unique_ptr<EventSubscription> subscribeBefore(BusTag tag, PreHandler && handler)
3838
{
39-
std::unique_lock<boost::shared_mutex> lock(mutex);
39+
std::unique_lock<std::shared_mutex> lock(mutex);
4040

4141
auto storage = std::make_shared<PreHandlerStorage>(std::move(handler));
4242
preHandlers[tag].push_back(storage);
@@ -45,7 +45,7 @@ class SubscriptionRegistry : public boost::noncopyable
4545

4646
std::unique_ptr<EventSubscription> subscribeAfter(BusTag tag, PostHandler && handler)
4747
{
48-
std::unique_lock<boost::shared_mutex> lock(mutex);
48+
std::unique_lock<std::shared_mutex> lock(mutex);
4949

5050
auto storage = std::make_shared<PostHandlerStorage>(std::move(handler));
5151
postHandlers[tag].push_back(storage);
@@ -54,7 +54,7 @@ class SubscriptionRegistry : public boost::noncopyable
5454

5555
void executeEvent(const EventBus * bus, E & event, const ExecHandler & execHandler)
5656
{
57-
std::shared_lock<boost::shared_mutex> lock(mutex);
57+
std::shared_lock<std::shared_mutex> lock(mutex);
5858
{
5959
auto it = preHandlers.find(bus);
6060

@@ -141,15 +141,15 @@ class SubscriptionRegistry : public boost::noncopyable
141141
std::shared_ptr<PostHandlerStorage> handler;
142142
};
143143

144-
boost::shared_mutex mutex;
144+
std::shared_mutex mutex;
145145

146146
std::map<BusTag, std::vector<std::shared_ptr<PreHandlerStorage>>> preHandlers;
147147
std::map<BusTag, std::vector<std::shared_ptr<PostHandlerStorage>>> postHandlers;
148148

149149
template <typename T>
150150
void unsubscribe(BusTag tag, T what, std::map<BusTag, std::vector<T>> & from)
151151
{
152-
std::unique_lock<boost::shared_mutex> lock(mutex);
152+
std::unique_lock<std::shared_mutex> lock(mutex);
153153

154154
auto it = from.find(tag);
155155

lib/CGameInfoCallback.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ const IMarket * CGameInfoCallback::getMarket(ObjectInstanceID objid) const
185185

186186
void CGameInfoCallback::fillUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo & out) const
187187
{
188-
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
188+
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
189189
ERROR_RET_IF(!canGetFullInfo(obj), "Cannot get info about not owned object!");
190190
ERROR_RET_IF(!obj->hasStackAtSlot(stackPos), "There is no such stack!");
191191
gs->fillUpgradeInfo(obj, stackPos, out);
@@ -194,7 +194,7 @@ void CGameInfoCallback::fillUpgradeInfo(const CArmedInstance *obj, SlotID stackP
194194

195195
const StartInfo * CGameInfoCallback::getStartInfo(bool beforeRandomization) const
196196
{
197-
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
197+
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
198198
if(beforeRandomization)
199199
return gs->initialOpts;
200200
else
@@ -203,7 +203,7 @@ const StartInfo * CGameInfoCallback::getStartInfo(bool beforeRandomization) cons
203203

204204
int32_t CGameInfoCallback::getSpellCost(const spells::Spell * sp, const CGHeroInstance * caster) const
205205
{
206-
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
206+
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
207207
ERROR_RET_VAL_IF(!canGetFullInfo(caster), "Cannot get info about caster!", -1);
208208
//if there is a battle
209209
auto casterBattle = gs->getBattle(caster->getOwner());
@@ -217,7 +217,7 @@ int32_t CGameInfoCallback::getSpellCost(const spells::Spell * sp, const CGHeroIn
217217

218218
int64_t CGameInfoCallback::estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const
219219
{
220-
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
220+
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
221221

222222
ERROR_RET_VAL_IF(hero && !canGetFullInfo(hero), "Cannot get info about caster!", -1);
223223

@@ -229,7 +229,7 @@ int64_t CGameInfoCallback::estimateSpellDamage(const CSpell * sp, const CGHeroIn
229229

230230
void CGameInfoCallback::getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj)
231231
{
232-
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
232+
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
233233
ERROR_RET_IF(!obj, "No guild object!");
234234
ERROR_RET_IF(obj->ID == Obj::TOWN && !canGetFullInfo(obj), "Cannot get info about town guild object!");
235235
//TODO: advmap object -> check if they're visited by our hero
@@ -419,13 +419,13 @@ bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero
419419

420420
int CGameInfoCallback::getDate(Date mode) const
421421
{
422-
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
422+
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
423423
return gs->getDate(mode);
424424
}
425425

426426
bool CGameInfoCallback::isVisible(int3 pos, const std::optional<PlayerColor> & Player) const
427427
{
428-
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
428+
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
429429
return gs->isVisible(pos, Player);
430430
}
431431

@@ -445,7 +445,7 @@ bool CGameInfoCallback::isVisible(const CGObjectInstance *obj) const
445445
}
446446
// const CCreatureSet* CInfoCallback::getGarrison(const CGObjectInstance *obj) const
447447
// {
448-
// //std::shared_lock<boost::shared_mutex> lock(*gs->mx);
448+
// //std::shared_lock<std::shared_mutex> lock(*gs->mx);
449449
// if()
450450
// const CArmedInstance *armi = dynamic_cast<const CArmedInstance*>(obj);
451451
// if(!armi)
@@ -754,14 +754,14 @@ CGameInfoCallback::CGameInfoCallback(CGameState * GS):
754754

755755
int CPlayerSpecificInfoCallback::howManyTowns() const
756756
{
757-
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
757+
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
758758
ERROR_RET_VAL_IF(!getPlayerID(), "Applicable only for player callbacks", -1);
759759
return CGameInfoCallback::howManyTowns(*getPlayerID());
760760
}
761761

762762
std::vector < const CGTownInstance *> CPlayerSpecificInfoCallback::getTownsInfo(bool onlyOur) const
763763
{
764-
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
764+
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
765765
auto ret = std::vector < const CGTownInstance *>();
766766
for(const auto & i : gs->players)
767767
{
@@ -777,7 +777,7 @@ std::vector < const CGTownInstance *> CPlayerSpecificInfoCallback::getTownsInfo(
777777
}
778778
std::vector < const CGHeroInstance *> CPlayerSpecificInfoCallback::getHeroesInfo(bool onlyOur) const
779779
{
780-
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
780+
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
781781
std::vector < const CGHeroInstance *> ret;
782782
for(auto hero : gs->map->heroesOnMap)
783783
{
@@ -840,7 +840,7 @@ std::vector <QuestInfo> CPlayerSpecificInfoCallback::getMyQuests() const
840840

841841
int CPlayerSpecificInfoCallback::howManyHeroes(bool includeGarrisoned) const
842842
{
843-
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
843+
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
844844
ERROR_RET_VAL_IF(!getPlayerID(), "Applicable only for player callbacks", -1);
845845
return getHeroCount(*getPlayerID(), includeGarrisoned);
846846
}
@@ -872,14 +872,14 @@ const CGTownInstance* CPlayerSpecificInfoCallback::getTownBySerial(int serialId)
872872

873873
int CPlayerSpecificInfoCallback::getResourceAmount(GameResID type) const
874874
{
875-
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
875+
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
876876
ERROR_RET_VAL_IF(!getPlayerID(), "Applicable only for player callbacks", -1);
877877
return getResource(*getPlayerID(), type);
878878
}
879879

880880
TResources CPlayerSpecificInfoCallback::getResourceAmount() const
881881
{
882-
//std::shared_lock<boost::shared_mutex> lock(*gs->mx);
882+
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
883883
ERROR_RET_VAL_IF(!getPlayerID(), "Applicable only for player callbacks", TResources());
884884
return gs->players[*getPlayerID()].resources;
885885
}

lib/UnlockGuard.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace vstd
114114
: unlock_guard<Mutex, detail::unlock_shared_policy<Mutex> >();
115115
}
116116

117-
using unlock_shared_guard = unlock_guard<boost::shared_mutex, detail::unlock_shared_policy<boost::shared_mutex>>;
117+
using unlock_shared_guard = unlock_guard<std::shared_mutex, detail::unlock_shared_policy<std::shared_mutex>>;
118118
}
119119

120120
VCMI_LIB_NAMESPACE_END

lib/gameState/CGameState.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
VCMI_LIB_NAMESPACE_BEGIN
6060

61-
boost::shared_mutex CGameState::mutex;
61+
std::shared_mutex CGameState::mutex;
6262

6363
HeroTypeID CGameState::pickNextHeroType(const PlayerColor & owner)
6464
{

lib/gameState/CGameState.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class DLL_LINKAGE CGameState : public CNonConstInfoCallback, public Serializeabl
8282

8383
StatisticDataSet statistic;
8484

85-
static boost::shared_mutex mutex;
85+
static std::shared_mutex mutex;
8686

8787
void updateEntity(Metatype metatype, int32_t index, const JsonNode & data) override;
8888

lib/rmg/modificators/Modificator.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Modificator
6464

6565
mutable std::recursive_mutex externalAccessMutex; //Used to communicate between Modificators
6666
using RecursiveLock = std::unique_lock<std::recursive_mutex>;
67-
using Lock = std::unique_lock<boost::shared_mutex>;
67+
using Lock = std::unique_lock<std::shared_mutex>;
6868

6969
private:
7070
virtual void process() = 0;
@@ -73,7 +73,7 @@ class Modificator
7373

7474
std::list<Modificator*> preceeders; //must be ordered container
7575

76-
mutable boost::shared_mutex mx; //Used only for task scheduling
76+
mutable std::shared_mutex mx; //Used only for task scheduling
7777

7878
void dump();
7979
};

lib/rmg/threadpool/BlockingQueue.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ VCMI_LIB_NAMESPACE_BEGIN
1919
template <typename T>
2020
class DLL_LINKAGE BlockingQueue : protected std::queue<T>
2121
{
22-
using WriteLock = std::unique_lock<boost::shared_mutex>;
23-
using Readlock = std::shared_lock<boost::shared_mutex>;
22+
using WriteLock = std::unique_lock<std::shared_mutex>;
23+
using Readlock = std::shared_lock<std::shared_mutex>;
2424

2525
public:
2626
BlockingQueue() = default;
@@ -85,7 +85,7 @@ class DLL_LINKAGE BlockingQueue : protected std::queue<T>
8585
}
8686

8787
private:
88-
mutable boost::shared_mutex mx;
88+
mutable std::shared_mutex mx;
8989
};
9090

9191
VCMI_LIB_NAMESPACE_END

lib/rmg/threadpool/MapProxy.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class MapProxy
3333
void drawRoads(vstd::RNG & generator, std::vector<int3> & tiles, RoadId roadType);
3434

3535
private:
36-
mutable boost::shared_mutex mx;
37-
using Lock = std::unique_lock<boost::shared_mutex>;
36+
mutable std::shared_mutex mx;
37+
using Lock = std::unique_lock<std::shared_mutex>;
3838

3939
RmgMap & map;
4040
};

lib/rmg/threadpool/ThreadPool.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ typedef std::optional<TRMGfunction> TRMGJob;
2424
class DLL_LINKAGE ThreadPool
2525
{
2626
private:
27-
using Lock = std::unique_lock<boost::shared_mutex>;
28-
mutable boost::shared_mutex mx;
27+
using Lock = std::unique_lock<std::shared_mutex>;
28+
mutable std::shared_mutex mx;
2929
mutable std::condition_variable_any cv;
3030
mutable boost::once_flag once;
3131

0 commit comments

Comments
 (0)