summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-03-22 18:02:09 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-03-22 18:02:09 +0000
commita9754ce49bf616c1d18556e19dd213d9ed54fcfc (patch)
treea91e0724c971415c9733bee2c99bec250ae3c42b
parentf5c631ef8641db6455bed23c02e5a39f63f7d6d0 (diff)
Allow static initialization of dynamic_reference objects
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12648 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/modules.h4
-rw-r--r--src/modules.cpp35
2 files changed, 26 insertions, 13 deletions
diff --git a/include/modules.h b/include/modules.h
index 5a9cb90e2..d889d734d 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -287,6 +287,7 @@ class CoreExport dynamic_reference_base : public interfacebase
void SetProvider(const std::string& newname);
void lookup();
operator bool();
+ static void reset_all();
};
template<typename T>
@@ -1492,9 +1493,6 @@ class CoreExport ModuleManager
/** List of data services keyed by name */
std::multimap<std::string, ServiceProvider*> DataProviders;
- /** List of all dynamic references that are currently active */
- std::vector<dynamic_reference_base*> ActiveDynrefs;
-
/** Simple, bog-standard, boring constructor.
*/
ModuleManager();
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;
}
}