]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Fix thread join not working for subclasses of Thread because of C++ destructor ordering
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Mon, 10 Aug 2009 19:55:07 +0000 (19:55 +0000)
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Mon, 10 Aug 2009 19:55:07 +0000 (19:55 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11500 e03df62e-2008-0410-955e-edbf42e46eb7

include/threadengine.h
src/inspircd.cpp
src/modules/extra/m_mssql.cpp
src/modules/extra/m_mysql.cpp
src/threadengine.cpp

index c11f2d817734d58a7de096b2836a8cf20b843a63..10f3fed13b5fa6684397f105deace4386244e65e 100644 (file)
@@ -30,7 +30,7 @@ class ThreadData;
  * code. Be sure to keep your code thread-safe and not prone to deadlocks
  * and race conditions if you MUST use threading!
  */
-class CoreExport Thread : public Extensible
+class CoreExport Thread
 {
  private:
        /** Set to true when the thread is to exit
@@ -55,6 +55,7 @@ class CoreExport Thread : public Extensible
        {
        }
 
+       /* If the thread is running, you MUST join BEFORE deletion */
        virtual ~Thread();
 
        /** Override this method to put your actual
@@ -64,10 +65,11 @@ class CoreExport Thread : public Extensible
 
        /** Signal the thread to exit gracefully.
         */
-       virtual void SetExitFlag()
-       {
-               ExitFlag = true;
-       }
+       virtual void SetExitFlag();
+
+       /** Join the thread (calls SetExitFlag and waits for exit)
+        */
+       void join();
 };
 
 
index a1a5d2d032d1fee1b2a6ab3062c893ecc0916b73..5a792b884926c0b09cb9b178e2cbc2cc00e010e8 100644 (file)
@@ -788,6 +788,7 @@ int InspIRCd::Run()
                        FOREACH_MOD_I(this, I_OnRehash, OnRehash(user));
                        this->BuildISupport();
 
+                       ConfigThread->join();
                        delete ConfigThread;
                        ConfigThread = NULL;
                }
index 5fd62f55ee530a2fa3f5e2cac69a29a1fa17f617..9cc7a567c80afaf5153e563fbfcdb0c45f5b961b 100644 (file)
@@ -668,6 +668,7 @@ class ModuleMsSQL : public Module
 
        virtual ~ModuleMsSQL()
        {
+               queryDispatcher->join();
                delete queryDispatcher;
                ClearQueue();
                ClearAllConnections();
index 465992d304578da9a7b916ad2e3cdb935970dfd3..224bf0f560acf66a696c51af41d6fbae63aa555b 100644 (file)
@@ -682,8 +682,7 @@ ModuleSQL::ModuleSQL(InspIRCd* Me) : Module(Me), rehashing(false)
 
        if (!ServerInstance->Modules->PublishFeature("SQL", this))
        {
-               /* Tell worker thread to exit NOW,
-                * Automatically joins */
+               Dispatcher->join();
                delete Dispatcher;
                ServerInstance->Modules->DoneWithInterface("SQLutils");
                throw ModuleException("m_mysql: Unable to publish feature 'SQL'");
index c6128d13295efd0b7ea76ee2012ef2ca293821ed..c2976c0479c2340f00f475c819719185f9848d8b 100644 (file)
 #include "inspircd.h"
 #include "threadengine.h"
 
+void Thread::SetExitFlag()
+{
+       ExitFlag = true;
+}
+
+void Thread::join()
+{
+               state->FreeThread(this);
+               delete state;
+               state = 0;
+}
+
 /** If this thread has a Creator set, call it to
  * free the thread
  */
 Thread::~Thread()
 {
-       if (state)
-       {
-               state->FreeThread(this);
-               delete state;
-       }
 }