diff options
Diffstat (limited to 'src')
-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; } } |