* 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
{
}
+ /* If the thread is running, you MUST join BEFORE deletion */
virtual ~Thread();
/** Override this method to put your actual
/** 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();
};
FOREACH_MOD_I(this, I_OnRehash, OnRehash(user));
this->BuildISupport();
+ ConfigThread->join();
delete ConfigThread;
ConfigThread = NULL;
}
virtual ~ModuleMsSQL()
{
+ queryDispatcher->join();
delete queryDispatcher;
ClearQueue();
ClearAllConnections();
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'");
#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;
- }
}