Refactored singletons to enable proper deconstruction during shutdown

This commit is contained in:
leak
2014-07-20 00:39:43 +02:00
parent d2c120f2c2
commit dce92611f3
39 changed files with 83 additions and 84 deletions

View File

@@ -99,9 +99,9 @@ int main(int argc, char** argv)
return 1;
// Get the list of realms for the server
sRealmList.Initialize(_ioService, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 20));
sRealmList->Initialize(_ioService, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 20));
if (sRealmList.size() == 0)
if (sRealmList->size() == 0)
{
TC_LOG_ERROR("server.authserver", "No valid realms specified.");
return 1;

View File

@@ -62,10 +62,10 @@ class RealmList
public:
typedef std::map<std::string, Realm> RealmMap;
static RealmList& instance()
static RealmList* instance()
{
static RealmList *instance = new RealmList();
return *instance;
static RealmList instance;
return &instance;
}
~RealmList();

View File

@@ -797,13 +797,13 @@ bool AuthSession::_HandleRealmList()
uint32 id = fields[0].GetUInt32();
// Update realm list if need
sRealmList.UpdateIfNeed();
sRealmList->UpdateIfNeed();
// Circle through realms in the RealmList and construct the return packet (including # of user characters in each realm)
ByteBuffer pkt;
size_t RealmListSize = 0;
for (RealmList::RealmMap::const_iterator i = sRealmList.begin(); i != sRealmList.end(); ++i)
for (RealmList::RealmMap::const_iterator i = sRealmList->begin(); i != sRealmList->end(); ++i)
{
const Realm &realm = i->second;
// don't work with realms which not compatible with the client

View File

@@ -1403,8 +1403,8 @@ class SmartWaypointMgr
public:
static SmartWaypointMgr* instance()
{
static SmartWaypointMgr* instance = new SmartWaypointMgr();
return instance;
static SmartWaypointMgr instance;
return &instance;
}
void LoadFromDB();
@@ -1439,8 +1439,8 @@ class SmartAIMgr
public:
static SmartAIMgr* instance()
{
static SmartAIMgr* instance = new SmartAIMgr();
return instance;
static SmartAIMgr instance;
return &instance;
}
void LoadSmartAIFromDB();

View File

@@ -57,8 +57,8 @@ class AccountMgr
public:
static AccountMgr* instance()
{
static AccountMgr* instance = new AccountMgr();
return instance;
static AccountMgr instance;
return &instance;
}
AccountOpResult CreateAccount(std::string username, std::string password, std::string email);

View File

@@ -310,8 +310,8 @@ class AchievementGlobalMgr
public:
static AchievementGlobalMgr* instance()
{
static AchievementGlobalMgr* instance = new AchievementGlobalMgr();
return instance;
static AchievementGlobalMgr instance;
return &instance;
}
AchievementCriteriaEntryList const& GetAchievementCriteriaByType(AchievementCriteriaTypes type) const

View File

@@ -142,8 +142,8 @@ class AuctionHouseMgr
public:
static AuctionHouseMgr* instance()
{
static AuctionHouseMgr* instance = new AuctionHouseMgr();
return instance;
static AuctionHouseMgr instance;
return &instance;
}
typedef std::unordered_map<uint32, Item*> ItemMap;

View File

@@ -29,8 +29,8 @@ class BattlefieldMgr
public:
static BattlefieldMgr* instance()
{
static BattlefieldMgr* instance = new BattlefieldMgr();
return instance;
static BattlefieldMgr instance;
return &instance;
}
// create battlefield events

View File

@@ -29,8 +29,8 @@ private:
public:
static ArenaTeamMgr* instance()
{
static ArenaTeamMgr* instance = new ArenaTeamMgr();
return instance;
static ArenaTeamMgr instance;
return &instance;
}
typedef std::unordered_map<uint32, ArenaTeam*> ArenaTeamContainer;

View File

@@ -64,8 +64,8 @@ class BattlegroundMgr
public:
static BattlegroundMgr* instance()
{
static BattlegroundMgr* instance = new BattlegroundMgr();
return instance;
static BattlegroundMgr instance;
return &instance;
}
void Update(uint32 diff);

View File

@@ -282,8 +282,8 @@ class CalendarMgr
public:
static CalendarMgr* instance()
{
static CalendarMgr* instance = new CalendarMgr();
return instance;
static CalendarMgr instance;
return &instance;
}
void LoadFromDB();

View File

@@ -37,8 +37,8 @@ class ChannelMgr
public:
static ChannelMgr* instance()
{
static ChannelMgr* instance = new ChannelMgr();
return instance;
static ChannelMgr instance;
return &instance;
}
static ChannelMgr * forTeam(uint32 team);

View File

@@ -230,8 +230,8 @@ class ConditionMgr
static ConditionMgr* instance()
{
static ConditionMgr* instance = new ConditionMgr();
return instance;
static ConditionMgr instance;
return &instance;
}
void LoadConditions(bool isReload = false);

View File

@@ -298,8 +298,8 @@ class LFGMgr
public:
static LFGMgr* instance()
{
static LFGMgr* instance = new LFGMgr();
return instance;
static LFGMgr instance;
return &instance;
}
// Functions used outside lfg namespace

View File

@@ -47,8 +47,8 @@ class FormationMgr
public:
static FormationMgr* instance()
{
static FormationMgr* instance = new FormationMgr();
return instance;
static FormationMgr instance;
return &instance;
}
void AddCreatureToGroup(uint32 group_id, Creature* creature);

View File

@@ -129,8 +129,8 @@ class SocialMgr
public:
static SocialMgr* instance()
{
static SocialMgr* instance = new SocialMgr();
return instance;
static SocialMgr instance;
return &instance;
}
// Misc

View File

@@ -101,8 +101,8 @@ class GameEventMgr
public:
static GameEventMgr* instance()
{
static GameEventMgr* instance = new GameEventMgr();
return instance;
static GameEventMgr instance;
return &instance;
}
typedef std::set<uint16> ActiveEvents;

View File

@@ -94,8 +94,8 @@ class ObjectAccessor
static ObjectAccessor* instance()
{
static ObjectAccessor *instance = new ObjectAccessor();
return instance;
static ObjectAccessor instance;
return &instance;
}
template<class T> static T* GetObjectInOrOutOfWorld(uint64 guid, T* /*typeSpecifier*/)

View File

@@ -694,8 +694,8 @@ class ObjectMgr
public:
static ObjectMgr* instance()
{
static ObjectMgr* instance = new ObjectMgr();
return instance;
static ObjectMgr instance;
return &instance;
}
typedef std::unordered_map<uint32, Item*> ItemMap;

View File

@@ -29,8 +29,8 @@ private:
public:
static GroupMgr* instance()
{
static GroupMgr* instance = new GroupMgr();
return instance;
static GroupMgr instance;
return &instance;
}
typedef std::map<uint32, Group*> GroupContainer;

View File

@@ -29,8 +29,8 @@ private:
public:
static GuildMgr* instance()
{
static GuildMgr* instance = new GuildMgr();
return instance;
static GuildMgr instance;
return &instance;
}
Guild* GetGuildByLeader(uint64 guid) const;

View File

@@ -28,8 +28,8 @@ class AddonHandler
public:
static AddonHandler* instance()
{
static AddonHandler* instance = new AddonHandler();
return instance;
static AddonHandler instance;
return &instance;
}
bool BuildAddonPacket(WorldPacket* Source, WorldPacket* Target);

View File

@@ -160,8 +160,8 @@ class InstanceSaveManager
static InstanceSaveManager* instance()
{
static InstanceSaveManager *instance = new InstanceSaveManager();
return instance;
static InstanceSaveManager instance;
return &instance;
}
/* resetTime is a global propery of each (raid/heroic) map

View File

@@ -32,8 +32,8 @@ class MapManager
public:
static MapManager* instance()
{
static MapManager* instance = new MapManager();
return instance;
static MapManager instance;
return &instance;
}
Map* CreateBaseMap(uint32 mapId);

View File

@@ -100,8 +100,8 @@ class TransportMgr
public:
static TransportMgr* instance()
{
static TransportMgr* instance = new TransportMgr();
return instance;
static TransportMgr instance;
return &instance;
}
void Unload();

View File

@@ -39,8 +39,8 @@ class WaypointMgr
public:
static WaypointMgr* instance()
{
static WaypointMgr* instance = new WaypointMgr();
return instance;
static WaypointMgr instance;
return &instance;
}
// Attempts to reload a single path from database

View File

@@ -44,8 +44,8 @@ class OutdoorPvPMgr
public:
static OutdoorPvPMgr* instance()
{
static OutdoorPvPMgr* instance = new OutdoorPvPMgr();
return instance;
static OutdoorPvPMgr instance;
return &instance;
}
// create outdoor pvp events

View File

@@ -110,8 +110,8 @@ class PoolMgr
public:
static PoolMgr* instance()
{
static PoolMgr* instance = new PoolMgr();
return instance;
static PoolMgr instance;
return &instance;
}
void LoadFromDB();

View File

@@ -881,8 +881,8 @@ class ScriptMgr
public: /* Initialization */
static ScriptMgr* instance()
{
static ScriptMgr* instance = new ScriptMgr();
return instance;
static ScriptMgr instance;
return &instance;
}
void Initialize();

View File

@@ -54,8 +54,8 @@ class SystemMgr
public:
static SystemMgr* instance()
{
static SystemMgr* instance = new SystemMgr();
return instance;
static SystemMgr instance;
return &instance;
}
typedef std::unordered_map<uint32, ScriptPointVector> PointMoveMap;

View File

@@ -37,8 +37,8 @@ class PacketLog
public:
static PacketLog* instance()
{
static PacketLog* instance = new PacketLog();
return instance;
static PacketLog instance;
return &instance;
}
void Initialize();

View File

@@ -610,9 +610,8 @@ class SpellMgr
public:
static SpellMgr* instance()
{
static SpellMgr* instance = new SpellMgr();
return instance;
static SpellMgr instance;
return &instance;
}
// Spell correctness for client using

View File

@@ -89,8 +89,8 @@ class CreatureTextMgr
public:
static CreatureTextMgr* instance()
{
static CreatureTextMgr* instance = new CreatureTextMgr();
return instance;
static CreatureTextMgr instance;
return &instance;
}
void LoadCreatureTexts();

View File

@@ -180,8 +180,8 @@ private:
public:
static TicketMgr* instance()
{
static TicketMgr* instance = new TicketMgr();
return instance;
static TicketMgr instance;
return &instance;
}
void LoadTickets();

View File

@@ -57,8 +57,8 @@ class WardenCheckMgr
public:
static WardenCheckMgr* instance()
{
static WardenCheckMgr* instance = new WardenCheckMgr();
return instance;
static WardenCheckMgr instance;
return &instance;
}
// We have a linear key without any gaps, so we use vector for fast access

View File

@@ -520,8 +520,8 @@ class World
public:
static World* instance()
{
static World* instance = new World();
return instance;
static World instance;
return &instance;
}
static std::atomic<uint32> m_worldLoopCounter;

View File

@@ -35,8 +35,8 @@ public:
static ConfigMgr* instance()
{
static ConfigMgr *instance = new ConfigMgr();
return instance;
static ConfigMgr instance;
return &instance;
}
bool Reload();

View File

@@ -35,8 +35,8 @@ class ObjectRegistry
static ObjectRegistry<T, Key>* instance()
{
static ObjectRegistry<T, Key>* instance = new ObjectRegistry<T, Key>();
return instance;
static ObjectRegistry<T, Key> instance;
return &instance;
}
/// Returns a registry item

View File

@@ -43,15 +43,15 @@ class Log
static Log* instance(boost::asio::io_service* ioService = nullptr)
{
static Log* instance = new Log();
static Log instance;
if (ioService != nullptr)
{
instance->_ioService = ioService;
instance->_strand = new boost::asio::strand(*ioService);
instance._ioService = ioService;
instance._strand = new boost::asio::strand(*ioService);
}
return instance;
return &instance;
}
void LoadFromConfig();