]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Wheeeeee
[user/henk/code/inspircd.git] / src / inspircd.cpp
index 8999e7ccc8c2117e179299373fd666b5d02e0db7..765ee71fdaad6ba585c41e14d213e0890ebb9991 100644 (file)
@@ -308,6 +308,11 @@ InspIRCd::InspIRCd(int argc, char** argv)
        SE = SEF->Create(this);
        delete SEF;
 
+
+       ThreadEngineFactory* tef = new ThreadEngineFactory();
+       this->Threads = tef->Create(this);
+       delete tef;
+
        this->s_signal = 0;
        
        // Create base manager classes early, so nothing breaks
@@ -477,15 +482,15 @@ InspIRCd::InspIRCd(int argc, char** argv)
 
        SE->RecoverFromFork();
 
-       /* Read config, pass 0. At the end if this pass,
-        * the Config->IncludeFiles is populated, we call
-        * Config->StartDownloads to initialize the downlaods of all
-        * these files.
+       /* During startup we don't actually initialize this
+        * in the thread engine.
         */
-       Config->Read(true, NULL, 0);
-       Config->DoDownloads();
-       /* We have all the files we can get, initiate pass 1 */
-       Config->Read(true, NULL, 1);
+       this->ConfigThread = new ConfigReaderThread(this, true, NULL);
+       ConfigThread->Run();
+       delete ConfigThread;
+       this->ConfigThread = NULL;
+
+       this->Res = new DNS(this);
 
        this->AddServerName(Config->ServerName);
 
@@ -494,10 +499,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
         * For an explanation as to exactly how this works, and why it works this way, see GetUID().
         *   -- w00t
         */
-       if (*Config->sid)
-       {
-       }
-       else
+       if (!*Config->sid)
        {
                // Generate one
                size_t sid = 0;
@@ -530,18 +532,18 @@ InspIRCd::InspIRCd(int argc, char** argv)
 
        printf("\n");
 
-       /*this->Modules->LoadAll();*/
+       this->Modules->LoadAll();
        
        /* Just in case no modules were loaded - fix for bug #101 */
        this->BuildISupport();
        InitializeDisabledCommands(Config->DisabledCommands, this);
 
-       if ((Config->ports.size() == 0) && (found_ports > 0))
+       /*if ((Config->ports.size() == 0) && (found_ports > 0))
        {
                printf("\nERROR: I couldn't bind any ports! Are you sure you didn't start InspIRCd twice?\n");
                Logs->Log("STARTUP", DEFAULT,"ERROR: I couldn't bind any ports! Something else is bound to those ports!");
                Exit(EXIT_STATUS_BIND);
-       }
+       }*/
 
        if (Config->ports.size() != (unsigned int)found_ports)
        {
@@ -631,6 +633,35 @@ int InspIRCd::Run()
                static char window_title[100];
 #endif
 
+               /* Check if there is a config thread which has finished executing but has not yet been freed */
+               if (this->ConfigThread && this->ConfigThread->GetExitFlag())
+               {
+                       /* Rehash has completed */
+                       this->Logs->Log("CONFIG",DEBUG,"Detected ConfigThread exiting, tidying up...");
+
+                       /* IMPORTANT: This delete may hang if you fuck up your thread syncronization.
+                        * It will hang waiting for the ConfigThread to 'join' to avoid race conditons,
+                        * until the other thread is completed.
+                        */
+                       delete ConfigThread;
+                       ConfigThread = NULL;
+
+                       /* These are currently not known to be threadsafe, so they are executed outside
+                        * of the thread. It would be pretty simple to move them to the thread Run method
+                        * once they are known threadsafe with all the correct mutexes in place.
+                        *
+                        * XXX: The order of these is IMPORTANT, do not reorder them without testing
+                        * thoroughly!!!
+                        */
+                       this->XLines->CheckELines();
+                       this->XLines->ApplyLines();
+                       this->Res->Rehash();
+                       this->ResetMaxBans();
+                       InitializeDisabledCommands(Config->DisabledCommands, this);
+                       FOREACH_MOD_I(this, I_OnRehash, OnRehash(Config->RehashUser, Config->RehashParameter));
+                       this->BuildISupport();
+               }
+
                /* time() seems to be a pretty expensive syscall, so avoid calling it too much.
                 * Once per loop iteration is pleanty.
                 */
@@ -646,7 +677,7 @@ int InspIRCd::Run()
                {
                        if (TIME < OLDTIME)
                        {
-                               SNO->WriteToSnoMask('A', "\002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %d secs.",abs(OLDTIME-TIME));
+                               SNO->WriteToSnoMask('A', "\002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %d secs.",OLDTIME-TIME);
                        }
 
                        if ((TIME % 3600) == 0)
@@ -735,11 +766,9 @@ bool InspIRCd::AllModulesReportReady(User* user)
 {
        for (EventHandlerIter i = Modules->EventHandlers[I_OnCheckReady].begin(); i != Modules->EventHandlers[I_OnCheckReady].end(); ++i)
        {
-               int res = (*i)->OnCheckReady(user);
-               if (!res)
+               if (!(*i)->OnCheckReady(user))
                        return false;
        }
-
        return true;
 }