]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
A few cpu usage tweaks
[user/henk/code/inspircd.git] / src / inspircd.cpp
index 8cf2d9dd08aa79a23d8bf4292f367cdaf8de2932..ff1a9e9da09b51a7c7ce8a0b0ba67a62c882a127 100644 (file)
@@ -218,6 +218,8 @@ std::stringstream config_f(stringstream::in | stringstream::out);
 
 std::vector<userrec*> all_opers;
 
+static char already_sent[65536];
+
 void AddOper(userrec* user)
 {
        log(DEBUG,"Oper added to optimization list");
@@ -858,7 +860,9 @@ void WriteCommon(userrec *u, char* text, ...)
        va_end(argsPtr);
 
        // FIX: Stops a message going to the same person more than once
-       std::vector<int> already_sent;
+       bzero(&already_sent,65536);
+
+       bool sent_to_at_least_one = false;
 
         for (int i = 0; i < MAXCHANS; i++)
         {
@@ -869,26 +873,18 @@ void WriteCommon(userrec *u, char* text, ...)
                         {
                                 char* o = (*ulist)[j];
                                 userrec* otheruser = (userrec*)o;
-                               bool do_send = true;
-                               for (int t = 0; t < already_sent.size(); t++)
+                               if (!already_sent[otheruser->fd])
                                {
-                                       if (already_sent[t] == otheruser->fd)
-                                       {
-                                               do_send = false;
-                                               break;
-                                       }
-                               }
-                               if (do_send)
-                               {
-                                       already_sent.push_back(otheruser->fd);
+                                       already_sent[otheruser->fd] = 1;
                                        WriteFrom(otheruser->fd,u,"%s",textbuffer);
+                                       sent_to_at_least_one = true;
                                }
                         }
                 }
         }
        // if the user was not in any channels, no users will receive the text. Make sure the user
        // receives their OWN message for WriteCommon
-       if (!already_sent.size())
+       if (!sent_to_at_least_one)
        {
                WriteFrom(u->fd,u,"%s",textbuffer);
        }
@@ -916,7 +912,7 @@ void WriteCommonExcept(userrec *u, char* text, ...)
        vsnprintf(textbuffer, MAXBUF, text, argsPtr);
        va_end(argsPtr);
 
-       std::vector<int> already_sent;
+        bzero(&already_sent,65536);
 
         for (int i = 0; i < MAXCHANS; i++)
         {
@@ -929,18 +925,9 @@ void WriteCommonExcept(userrec *u, char* text, ...)
                                 userrec* otheruser = (userrec*)o;
                                if (u != otheruser)
                                {
-                                       bool do_send = true;
-                                       for (int t = 0; t < already_sent.size(); t++)
-                                       {
-                                               if (already_sent[t] == otheruser->fd)
-                                               {
-                                                       do_send = false;
-                                                       break;
-                                               }
-                                       }
-                                       if (do_send)
+                                       if (!already_sent[otheruser->fd])
                                        {
-                                               already_sent.push_back(otheruser->fd);
+                                               already_sent[otheruser->fd] = 1;
                                                WriteFrom(otheruser->fd,u,"%s",textbuffer);
                                        }
                                }
@@ -4138,6 +4125,9 @@ int InspIRCd(void)
 
                if ((curr) && (curr->fd != 0))
                {
+#ifdef _POSIX_PRIORITY_SCHEDULING
+        sched_yield();
+#endif
                        // assemble up to 64 sockets into an fd_set
                        // to implement a pooling mechanism.
                        //
@@ -4227,7 +4217,6 @@ int InspIRCd(void)
                                        }
                                        else result = result2;
                                        log(DEBUG,"Read result: %d",result);
-       
                                        if (result)
                                        {
                                                statsRecv += result;
@@ -4420,6 +4409,7 @@ int InspIRCd(void)
        if (0) {};
 #ifdef _POSIX_PRIORITY_SCHEDULING
         sched_yield();
+       sched_yield();
 #endif
 }
 /* not reached */