summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-08-10 19:55:07 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-08-10 19:55:07 +0000
commit8235290c734c17f5b52533876136e9a61d231c9d (patch)
tree82acae114b8e64b7b53b17b257f292f8e6b0686d
parent5c4212ee9be88b05f39fc5a0fb0a8fa6366e048b (diff)
Fix thread join not working for subclasses of Thread because of C++ destructor ordering
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11500 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/threadengine.h12
-rw-r--r--src/inspircd.cpp1
-rw-r--r--src/modules/extra/m_mssql.cpp1
-rw-r--r--src/modules/extra/m_mysql.cpp3
-rw-r--r--src/threadengine.cpp17
5 files changed, 22 insertions, 12 deletions
diff --git a/include/threadengine.h b/include/threadengine.h
index c11f2d817..10f3fed13 100644
--- a/include/threadengine.h
+++ b/include/threadengine.h
@@ -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();
};
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index a1a5d2d03..5a792b884 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -788,6 +788,7 @@ int InspIRCd::Run()
FOREACH_MOD_I(this, I_OnRehash, OnRehash(user));
this->BuildISupport();
+ ConfigThread->join();
delete ConfigThread;
ConfigThread = NULL;
}
diff --git a/src/modules/extra/m_mssql.cpp b/src/modules/extra/m_mssql.cpp
index 5fd62f55e..9cc7a567c 100644
--- a/src/modules/extra/m_mssql.cpp
+++ b/src/modules/extra/m_mssql.cpp
@@ -668,6 +668,7 @@ class ModuleMsSQL : public Module
virtual ~ModuleMsSQL()
{
+ queryDispatcher->join();
delete queryDispatcher;
ClearQueue();
ClearAllConnections();
diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp
index 465992d30..224bf0f56 100644
--- a/src/modules/extra/m_mysql.cpp
+++ b/src/modules/extra/m_mysql.cpp
@@ -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'");
diff --git a/src/threadengine.cpp b/src/threadengine.cpp
index c6128d132..c2976c047 100644
--- a/src/threadengine.cpp
+++ b/src/threadengine.cpp
@@ -20,14 +20,21 @@
#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;
- }
}