diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2010-03-22 18:02:09 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2010-03-22 18:02:09 +0000 |
commit | a9754ce49bf616c1d18556e19dd213d9ed54fcfc (patch) | |
tree | a91e0724c971415c9733bee2c99bec250ae3c42b /src/modules.cpp | |
parent | f5c631ef8641db6455bed23c02e5a39f63f7d6d0 (diff) |
Allow static initialization of dynamic_reference objects
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12648 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules.cpp')
-rw-r--r-- | src/modules.cpp | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/modules.cpp b/src/modules.cpp index 9e5c84bff..bf5506d68 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -23,6 +23,15 @@ #include <dirent.h> #endif +static std::vector<dynamic_reference_base*>* dynrefs = NULL; + +void dynamic_reference_base::reset_all() +{ + if (!dynrefs) + return; + for(unsigned int i = 0; i < dynrefs->size(); i++) + (*dynrefs)[i]->ClearCache(); +} // Version is a simple class for holding a modules version number template<> @@ -368,8 +377,8 @@ void ModuleManager::DoSafeUnload(Module* mod) if (curr->second->creator == mod) DataProviders.erase(curr); } - for(unsigned int i = 0; i < ServerInstance->Modules->ActiveDynrefs.size(); i++) - ServerInstance->Modules->ActiveDynrefs[i]->ClearCache(); + + dynamic_reference_base::reset_all(); /* Tidy up any dangling resolvers */ ServerInstance->Res->CleanResolvers(mod); @@ -454,8 +463,7 @@ void ModuleManager::DelService(ServiceProvider& item) if (curr->second == &item) DataProviders.erase(curr); } - for(unsigned int i = 0; i < ServerInstance->Modules->ActiveDynrefs.size(); i++) - ServerInstance->Modules->ActiveDynrefs[i]->ClearCache(); + dynamic_reference_base::reset_all(); return; } default: @@ -484,19 +492,26 @@ ServiceProvider* ModuleManager::FindService(ServiceType type, const std::string& dynamic_reference_base::dynamic_reference_base(Module* Creator, const std::string& Name) : name(Name), value(NULL), creator(Creator) { - ServerInstance->Modules->ActiveDynrefs.push_back(this); + if (!dynrefs) + dynrefs = new std::vector<dynamic_reference_base*>; + dynrefs->push_back(this); } dynamic_reference_base::~dynamic_reference_base() { - for(unsigned int i = 0; i < ServerInstance->Modules->ActiveDynrefs.size(); i++) + for(unsigned int i = 0; i < dynrefs->size(); i++) { - if (ServerInstance->Modules->ActiveDynrefs[i] == this) + if (dynrefs->at(i) == this) { - unsigned int last = ServerInstance->Modules->ActiveDynrefs.size() - 1; + unsigned int last = dynrefs->size() - 1; if (i != last) - ServerInstance->Modules->ActiveDynrefs[i] = ServerInstance->Modules->ActiveDynrefs[last]; - ServerInstance->Modules->ActiveDynrefs.erase(ServerInstance->Modules->ActiveDynrefs.begin() + last); + dynrefs->at(i) = dynrefs->at(last); + dynrefs->erase(dynrefs->begin() + last); + if (dynrefs->empty()) + { + delete dynrefs; + dynrefs = NULL; + } return; } } |