]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cull_list.cpp
Fix module unmapping with culled Module objects
[user/henk/code/inspircd.git] / src / cull_list.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include <typeinfo>
16
17 void CullList::Apply()
18 {
19         std::set<classbase*> gone;
20         std::vector<classbase*> queue;
21         queue.reserve(list.size() + 32);
22         for(unsigned int i=0; i < list.size(); i++)
23         {
24                 classbase* c = list[i];
25                 if (gone.insert(c).second)
26                 {
27                         ServerInstance->Logs->Log("CULLLIST", DEBUG, "Deleting %s @%p", typeid(*c).name(),
28                                 (void*)c);
29                         if (c->cull())
30                                 queue.push_back(c);
31                 }
32                 else
33                 {
34                         ServerInstance->Logs->Log("CULLLIST",DEBUG, "WARNING: Object @%p culled twice!",
35                                 (void*)c);
36                 }
37         }
38         list.clear();
39         for(unsigned int i=0; i < queue.size(); i++)
40         {
41                 classbase* c = queue[i];
42                 delete c;
43         }
44         if (list.size())
45         {
46                 ServerInstance->Logs->Log("CULLLIST",DEBUG, "WARNING: Objects added to cull list in a destructor");
47                 Apply();
48         }
49 }
50
51 void ActionList::Run()
52 {
53         for(unsigned int i=0; i < list.size(); i++)
54         {
55                 list[i]->Call();
56         }
57         list.clear();
58 }