]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Convert LocalUserList to an intrusively linked list
authorAttila Molnar <attilamolnar@hush.com>
Fri, 24 Jan 2014 12:08:13 +0000 (13:08 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Fri, 24 Jan 2014 12:08:13 +0000 (13:08 +0100)
include/typedefs.h
include/usermanager.h
include/users.h
src/inspircd.cpp
src/usermanager.cpp
src/users.cpp
src/xline.cpp

index 050707e73e38b73337f5534c51f345808bb7f8f2..067768db4e2d703f3aea955ee4de1e11a11e8de1 100644 (file)
@@ -57,7 +57,7 @@ typedef TR1NS::unordered_map<std::string, Channel*, irc::insensitive, irc::StrHa
 
 /** A list holding local users, this is the type of UserManager::local_users
  */
-typedef std::list<LocalUser*> LocalUserList;
+typedef intrusive_list<LocalUser> LocalUserList;
 
 /** A list of failed port bindings, used for informational purposes on startup */
 typedef std::vector<std::pair<std::string, std::string> > FailedPortList;
index a807cd447b57de70db5f0d5118042f526eb064bc..e287d74d0be434f3799969292dac53612751a5a2 100644 (file)
@@ -63,10 +63,6 @@ class CoreExport UserManager
         */
        unsigned int unregistered_count;
 
-       /** Number of elements in local_users
-        */
-       unsigned int local_count;
-
        /** Map of global ip addresses for clone counting
         * XXX - this should be private, but m_clones depends on it currently.
         */
@@ -159,7 +155,7 @@ class CoreExport UserManager
        /** Return a count of local registered users
         * @return The number of registered local users
         */
-       unsigned int LocalUserCount() const { return (this->local_count - this->UnregisteredUserCount()); }
+       unsigned int LocalUserCount() const { return (this->local_users.size() - this->UnregisteredUserCount()); }
 
        /** Send a server notice to all local users
         * @param text The text format string to send
index f8bfb5a6e523eeb78cf7579d4becb2b9709b42c3..db2d538785c9378a6367642f5adf22a680ea5c27 100644 (file)
@@ -655,7 +655,7 @@ class CoreExport UserIOHandler : public StreamSocket
 
 typedef unsigned int already_sent_t;
 
-class CoreExport LocalUser : public User, public InviteBase
+class CoreExport LocalUser : public User, public InviteBase, public intrusive_list_node<LocalUser>
 {
  public:
        LocalUser(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
@@ -663,10 +663,6 @@ class CoreExport LocalUser : public User, public InviteBase
 
        UserIOHandler eh;
 
-       /** Position in UserManager::local_users
-        */
-       LocalUserList::iterator localuseriter;
-
        /** Stats counter for bytes inbound
         */
        unsigned int bytes_in;
index fb33f1937cb7f6ff6de11bace05aa239b79fa99e..12962d92d6391dcd8b3033477adbe22f58ce2547 100644 (file)
@@ -107,12 +107,9 @@ void InspIRCd::Cleanup()
        ports.clear();
 
        /* Close all client sockets, or the new process inherits them */
-       LocalUserList::reverse_iterator i = Users->local_users.rbegin();
-       while (i != this->Users->local_users.rend())
-       {
-               User* u = *i++;
-               Users->QuitUser(u, "Server shutdown");
-       }
+       LocalUserList& list = Users->local_users;
+       for (LocalUserList::iterator i = list.begin(); i != list.end(); ++i)
+               Users->QuitUser(*i, "Server shutdown");
 
        GlobalCulls.Apply();
        Modules->UnloadAll();
index 29d1f737003c88bf1c8576015a90ae69ae4e3eda..13646f225c2abf1e75d6b1e4b6f7b16a7ef8ed97 100644 (file)
@@ -28,7 +28,7 @@
 UserManager::UserManager()
        : clientlist(new user_hash)
        , uuidlist(new user_hash)
-       , unregistered_count(0), local_count(0)
+       , unregistered_count(0)
 {
 }
 
@@ -81,8 +81,7 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs
        ServerInstance->Users->AddLocalClone(New);
        ServerInstance->Users->AddGlobalClone(New);
 
-       New->localuseriter = this->local_users.insert(local_users.end(), New);
-       local_count++;
+       this->local_users.push_front(New);
 
        if ((this->local_users.size() > ServerInstance->Config->SoftLimit) || (this->local_users.size() >= (unsigned int)ServerInstance->SE->GetMaxFds()))
        {
index df42d2a9c2910f3e4ad60ddaaa06857dc0b8ac4a..6ec46883ff7e8054b21c77bbe23c51a3f4f86296 100644 (file)
@@ -86,7 +86,6 @@ User::User(const std::string& uid, Server* srv, int type)
 
 LocalUser::LocalUser(int myfd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* servaddr)
        : User(ServerInstance->UIDGen.GetUID(), ServerInstance->FakeClient->server, USERTYPE_LOCAL), eh(this),
-       localuseriter(ServerInstance->Users->local_users.end()),
        bytes_in(0), bytes_out(0), cmds_in(0), cmds_out(0), nping(0), CommandFloodPenalty(0),
        already_sent(0)
 {
@@ -337,17 +336,7 @@ CullResult User::cull()
 
 CullResult LocalUser::cull()
 {
-       // The iterator is initialized to local_users.end() in the constructor. It is
-       // overwritten in UserManager::AddUser() with the real iterator so this check
-       // is only a precaution currently.
-       if (localuseriter != ServerInstance->Users->local_users.end())
-       {
-               ServerInstance->Users->local_count--;
-               ServerInstance->Users->local_users.erase(localuseriter);
-       }
-       else
-               ServerInstance->Logs->Log("USERS", LOG_DEFAULT, "ERROR: LocalUserIter does not point to a valid entry for " + this->nick);
-
+       ServerInstance->Users->local_users.erase(this);
        ClearInvites();
        eh.cull();
        return User::cull();
index 63a64d6b9d74d2b9ab73a4e38c8702f37b3c990b..d2fd9a5be238eed47ae948aa36190dc2d99405e1 100644 (file)
@@ -430,10 +430,10 @@ void XLineManager::ExpireLine(ContainerIter container, LookupIter item)
 // applies lines, removing clients and changing nicks etc as applicable
 void XLineManager::ApplyLines()
 {
-       LocalUserList::reverse_iterator u2 = ServerInstance->Users->local_users.rbegin();
-       while (u2 != ServerInstance->Users->local_users.rend())
+       LocalUserList& list = ServerInstance->Users->local_users;
+       for (LocalUserList::iterator j = list.begin(); j != list.end(); ++j)
        {
-               LocalUser* u = *u2++;
+               LocalUser* u = *j;
 
                // Don't ban people who are exempt.
                if (u->exempt)