summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2017-02-07 17:20:07 -0500
committerAdam <Adam@anope.org>2017-02-07 17:20:07 -0500
commit09dca29c8898916772c2a2a6b86b625c812007ed (patch)
tree1b28f4751feec3ea2b46fa0afb061da7926f3a47 /src
parent8b694bc392c36551e428b84454efb81cdbc8bcd3 (diff)
Normalize databases by not allowing generic Object references
Remove redis database support
Diffstat (limited to 'src')
-rw-r--r--src/serialize.cpp63
1 files changed, 31 insertions, 32 deletions
diff --git a/src/serialize.cpp b/src/serialize.cpp
index d27950f36..5315a8469 100644
--- a/src/serialize.cpp
+++ b/src/serialize.cpp
@@ -25,7 +25,7 @@
using namespace Serialize;
-std::unordered_map<ID, Object *> Serialize::objects;
+static std::map<Serialize::TypeBase *, std::unordered_map<ID, Object *>> objects;
std::vector<FieldBase *> Serialize::serializableFields;
@@ -34,33 +34,34 @@ std::multimap<Anope::string, Anope::string> Serialize::child_types;
static ID curid;
-Object *Serialize::GetID(ID id)
+Object *Serialize::GetID(Serialize::TypeBase *type, ID id)
{
- auto it = objects.find(id);
- if (it != objects.end())
+ auto it = objects[type].find(id);
+ if (it != objects[type].end())
return it->second;
return nullptr;
}
void Serialize::GC()
{
- for (auto it = objects.begin(); it != objects.end();)
- {
- Object *o = it->second;
-
- if (!o->CanGC())
+ for (auto it = objects.begin(); it != objects.end(); ++it)
+ for (auto it2 = it->second.begin(); it2 != it->second.end();)
{
- // Wipe internal storage to force refetch
- o->Wipe();
- ++it;
- continue;
- }
+ Object *o = it2->second;
- Anope::Logger.Debug2("garbage collected object {0}", o->id);
+ if (!o->CanGC())
+ {
+ // Wipe internal storage to force refetch
+ o->Wipe();
+ ++it2;
+ continue;
+ }
- it = objects.erase(it);
- delete o;
- }
+ Anope::Logger.Debug2("garbage collected object {0}", o->id);
+
+ it2 = it->second.erase(it2);
+ delete o;
+ }
}
void Serialize::Unregister(Module *m)
@@ -109,15 +110,15 @@ std::vector<Edge> Object::GetEdges(TypeBase *type)
Object::Object(TypeBase *type)
{
ID i;
- EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializableGetId, i);
+ EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializableGetId, type, i);
if (result != EVENT_ALLOW)
{
- while (GetID(++curid));
+ while (GetID(type, ++curid));
i = curid;
}
id = i;
- objects[id] = this;
+ objects[type][id] = this;
this->s_type = type;
@@ -131,7 +132,7 @@ Object::Object(TypeBase *type)
Object::Object(TypeBase *type, ID i)
{
this->id = i;
- objects[i] = this;
+ objects[type][id] = this;
this->s_type = type;
@@ -142,7 +143,7 @@ Object::Object(TypeBase *type, ID i)
Object::~Object()
{
- Anope::Logger.Debug2("Destructing object id #{0} address {2} type {3}", id, static_cast<void *>(this), s_type->GetName());
+ Anope::Logger.Debug2("Destructing object id #{0} address {1} type {2}", id, static_cast<void *>(this), s_type->GetName());
/* Remove in memory edges */
std::map<TypeBase *, std::vector<Edge>> copy = edges;
@@ -161,7 +162,7 @@ Object::~Object()
}
}
- objects.erase(id);
+ objects[s_type].erase(id);
s_type->objects.erase(this);
}
@@ -230,18 +231,16 @@ TypeBase::TypeBase(Module *o, const Anope::string &n) : Service(o, TypeBase::NAM
{
}
-TypeBase::~TypeBase()
-{
- if (!Serialize::GetObjects<Object *>(this->GetName()).empty())
- throw CoreException("Type destructing with objects still alive");
-}
-
void TypeBase::Unregister()
{
Anope::Logger.Debug2("Unregistering type {0}", this->GetName());
- for (Object *obj : GetObjects<Object *>(this->GetName()))
- obj->Delete();
+ // Delete in memory objects
+ std::unordered_map<ID, Object *> objs = ::objects[this];
+ for (auto &pair : objs)
+ delete pair.second;
+
+ ::objects.erase(this);
for (FieldBase *field : serializableFields)
{